Repository navigation
Count uncapped words without building a document matrix - #898
Open
snygginghani wants to merge 1 commit into
Open
snygginghani wants to merge 1 commit into
snygginghani wants to merge 1 commit 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.
Summary
The default
word_countpath builds a sparse document-term matrix, then only reads its sum and number of columns. Use the same scikit-learn analyzer and count words and distinct tokens directly. A specifiedmax_vocabstill uses CountVectorizer's feature selection.Benchmark
On 33,379 text entries from the SQuAD v2 development set, median public
.compute()time fell from 316.58 ms to 203.64 ms across nine alternating runs. Peak traced allocations fell from 13.41 MiB to 6.63 MiB, measured separately. Both revisions reported 328,746 words and 17,939 unique words.For reproduction, create a list of each paragraph's context, append all questions, then append all annotated answer strings in dataset order. Pass it to
evaluate.load("./measurements/word_count", module_type="measurement", keep_in_memory=True).compute(data=texts). Tested on Windows 11, Python 3.13.3, datasets 5.2.0 and scikit-learn 1.6.1.python -m pytest tests/test_word_count.py -qpassed all three cases, covering default and capped counts, case folding, punctuation and empty vocabulary. Black, isort, flake8 andgit diff --checkpassed.AI assistance was used to prepare the patch, tests and benchmark.