Skip to content

CU-8698gqumv: Fix regression test vocab vector sizes #526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/resources/regression/creation/vocab_data.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
severe 10000 1.0 0 0 1 0 0 0
minor 10000 -1.0 0 0 1 0 0 0
acute 6500 0 1.0 0 1 0 0 0
chronic 6500 0 -1.0 0 0 1 0 0 0
chronic 6500 0 -1.0 0 0 1 0 0
heavy 4000 0 0 1.0 1 0 0 0
light 4000 0 0 -1.0 1 0 0 0
considered 1000 0.1 -0.2 0 0 0.9 0 0
Expand All @@ -15,4 +15,4 @@ are 12000 0 0 0 0 1.1 0 0
has 11000 0 0 0 0 0.98 0 0
presence 1000 0 0 0 0 0 0 0.4
indication 500 0 0 0 0 0 0 0.3
time 450 0 0 0 0 0 0 0.1
time 450 0 0 0 0 0 0 0.1
4 changes: 4 additions & 0 deletions tests/resources/regression/run_regression.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ echo "$output"
model_path=$(echo "$output" | tail -n 1)
# NOTE: this file should be tagged with the python version we're using

# test the vocab to make sure it's all good
python tests/resources/regression/test_vocab.py
# TODO: test other things as well?

# run the regression_checker with the captured file path
# if any of the regression cases fail, this will return a non-zero exit status
python -m medcat.utils.regression.regression_checker \
Expand Down
31 changes: 31 additions & 0 deletions tests/resources/regression/test_vocab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os

from medcat.vocab import Vocab

import unittest


class RegressionModelVocabTests(unittest.TestCase):
VOCAB_DATA_PATH = os.path.join(os.path.dirname(__file__),
'creation', 'vocab_data.txt')

@classmethod
def setUpClass(cls):
cls.vocab = Vocab()
cls.vocab.add_words(cls.VOCAB_DATA_PATH)

def test_has_same_vector_lengths(self):
all_lengths = set()
for w in self.vocab.vec_index2word.values():
all_lengths.add(len(self.vocab.vec(w)))
self.assertEqual(len(all_lengths), 1, f"Expected equal lengths. Got: {all_lengths}")

def test_all_words_have_vectors(self):
for w in self.vocab.vocab:
with self.subTest(f"Word: {repr(w)}"):
# NOTE: if not there, will raise an exception
self.assertIsNotNone(self.vocab.vec(w))


if __name__ == '__main__':
unittest.main()