Fix index misalignment in char_wb ngram padding - #8429
Conversation
📝 WalkthroughSummary by CodeRabbit
Walkthrough
ChangesCharacter n-gram generation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
python/cuml/cuml/feature_extraction/_vectorizers.py (1)
216-224: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd an enabled
char_wbTfidf regression test.In
python/cuml/tests/test_text_feature_extraction.py, testTfidfVectorizer.fit_transform(analyzer="char_wb", ngram_range=(2, 6)). Compare the sparse output and feature names with scikit-learn usingget_feature_names_out().🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@python/cuml/cuml/feature_extraction/_vectorizers.py` around lines 216 - 224, Add an enabled regression test in test_text_feature_extraction.py covering TfidfVectorizer with analyzer="char_wb" and ngram_range=(2, 6). Fit and transform the same input with cuML and scikit-learn, then compare sparse outputs and feature names using get_feature_names_out().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@python/cuml/cuml/feature_extraction/_vectorizers.py`:
- Around line 216-224: Add an enabled regression test in
test_text_feature_extraction.py covering TfidfVectorizer with analyzer="char_wb"
and ngram_range=(2, 6). Fit and transform the same input with cuML and
scikit-learn, then compare sparse outputs and feature names using
get_feature_names_out().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 80ca255e-7d3d-41f0-ab51-594df4f04c33
📒 Files selected for processing (1)
python/cuml/cuml/feature_extraction/_vectorizers.py
Fixes #8416
Root cause
get_char_ngrams()pads each token withself.delimiteron both sides before generating character ngrams: