Skip to content
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

Make mini-batch TF-IDF raise an exception #1631

Merged
merged 3 commits into from
Nov 14, 2024
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: 4 additions & 0 deletions docs/releases/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

- Make `drift.ADWIN` comply with the reference MOA implementation.

## feature extraction

- The mini-batch methods for `feature_extraction.TFIDF` now systematically raise an exception, as they are not implemented.

## stats

- Removed the unexported class `stats.CentralMoments`.
Expand Down
13 changes: 13 additions & 0 deletions river/feature_extraction/vectorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ def __init__(
strip_accents=True,
lowercase=True,
preprocessor: typing.Callable | None = None,
stop_words: set[str] | None = None,
tokenizer_pattern=r"(?u)\b\w[\w\-]+\b",
tokenizer: typing.Callable | None = None,
ngram_range=(1, 1),
):
Expand All @@ -459,6 +461,8 @@ def __init__(
strip_accents=strip_accents,
lowercase=lowercase,
preprocessor=preprocessor,
stop_words=stop_words,
tokenizer_pattern=tokenizer_pattern,
tokenizer=tokenizer,
ngram_range=ngram_range,
)
Expand Down Expand Up @@ -489,3 +493,12 @@ def transform_one(self, x):
norm = math.sqrt(sum(tfidf**2 for tfidf in tfidfs.values()))
return {term: tfidf / norm for term, tfidf in tfidfs.items()}
return tfidfs

# Mini-batch methods should be done well™ and not just be a loop over the *_one equivalent.
def learn_many(self, X):
"Not available, will raise an exception."
raise NotImplementedError

def transform_many(self, X):
"Not available, will raise an exception."
raise NotImplementedError
Loading