fix(medcat): prevent silent document loss in TestTrainSplitter.split()#574
Open
silverfoxdoc wants to merge 7 commits into
Open
fix(medcat): prevent silent document loss in TestTrainSplitter.split()#574silverfoxdoc wants to merge 7 commits into
silverfoxdoc wants to merge 7 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When using
make_mc_train_test(ortest_size > 0intrain_supervised_raw),TestTrainSplitter.split()seems to silently drop the majority of documents rather than assigning them to the train set. This results in a training set far smaller than expected.Expected behaviour
When testing with real data set of 472 annotated documents and test_size=0.1, approximately 425 documents should be assigned to the train set and ~47 to the test set, given reasonably uniform numbers of annotations in each document; appreciate the method for splitting is more complex than simply raw document/annotation numbers.
Actual behaviour
Only ~20 documents appear in the train set. The remaining ~450 documents are neither assigned to train nor test set and are silently discarded.
Root cause
In medcat-v2/medcat/utils/data_utils.py, the split() method uses continue when the test quota is full, skipping documents entirely rather than routing them to the train set:
Proposed fix
Add the document to the train set before continue:
Tests
A new test class
TestTrainSplitterNoDocumentLossTestshas been added totests/utils/test_data_utils.pycovering:make_mc_train_testwrapper also loses no documentsTests were verified to fail on
main(4/5 failing) and pass on this branch (5/5 passing).Full transparency - the test was generated by claude AI with code reviewed manually to ensure performing as expected.