Skip to content

build(deps): pin NLTK 3.10.4 for the nltk tokenizer - #625

Open
gloryfromca wants to merge 2 commits into
mainfrom
fix/bump-nltk
Open

gloryfromca wants to merge 2 commits into
mainfrom
fix/bump-nltk

Conversation

@gloryfromca

Copy link
Copy Markdown
Member

Summary

The [nltk] extra and the dev group pinned NLTK 3.9.4. In that release, PorterStemmer.stem() can be driven into a slow path by a crafted word (PYSEC-2026-3738, fixed in 3.10.3), and the nltk tokenizer stems every token of ingested text. Both pins are now 3.10.4.

The pin is exact because tokens change across NLTK releases, and stored tokens must match query tokens. Measured on real text, the only difference between the two releases is a word right after an opening quote ('cause): 3.9.4 dropped it, 3.10.4 keeps it. Keyword retrieval quality does not change:

Measure 3.9.4 3.10.4
Texts whose tokens differ (LoCoMo + 120 LongMemEval haystacks, 83,484 texts, 5.0 M tokens) — 449 (0.54%)
Turn-level BM25 over the 1,977 LoCoMo questions with evidence: Hit@5 60.09% 60.04%
Hit@20 73.90% 73.90%
MRR 0.4600 0.4600

40 of the 1,977 questions change rank: 31 move up slightly and 9 move down slightly.

  • uv.lock: only nltk changes.
  • The existing harness-parity cases still match. A new test pins the one behaviour difference: 'cause is kept.
  • CHANGELOG: a Security entry, plus an Upgrade note that a store indexed with [tokenizer] name = "nltk" should run everos cascade rebuild. The default jieba tokenizer is unaffected.

Area

  • Architecture method
  • Benchmark
  • Use case
  • Documentation
  • Developer experience
  • CI, build, or release

Verification

CI's data step with 3.10.4: python -m nltk.downloader -q -e -d <dir> punkt_tab stopwords -> exit 0
tests/unit/test_component/test_tokenizer/: 25 passed (24 existing + 1 new), NLTK data present
every test file that mentions nltk (tokenizer, settings, benchmark run identity): 77 passed
new test under 3.9.4: tokens ['camp', 'fam', 'natur', 'help'] (no 'caus') -> it fails there, as intended
make lint, make docs-check, commit-message check: pass

Checklist

  • I kept the change scoped to the relevant area.
  • I am opening this from a separate branch, not pushing directly to main.
  • I updated docs, examples, or setup notes when behavior changed.
  • I added or updated tests when the change affects behavior.
  • I did not commit secrets, .env files, dependency folders, or generated output.
  • Active relative links in Markdown files resolve.

Notes for Reviewers

  • The EverAlgo LoCoMo harness still runs 3.9.4. Benchmark numbers taken with the nltk tokenizer can now differ slightly from the harness's, through those quote-prefixed words.

By submitting this pull request, I agree that my contribution is licensed under
the Apache License 2.0.

🤖 Generated with Claude Code

NLTK 3.9.4's PorterStemmer.stem() can be driven into a slow path by a
crafted word (PYSEC-2026-3738, fixed in 3.10.3), and the nltk tokenizer
stems every token of ingested text. The extra and the dev group now pin
3.10.4.

The pin was exact because tokens change across NLTK releases. Measured
on 83,484 LoCoMo and LongMemEval texts, the two releases differ only on
a word right after an opening quote ('cause), which 3.9.4 dropped (449
texts); turn-level BM25 over the 1,977 LoCoMo questions with evidence
is unchanged. A new test pins that case. Stores indexed with the nltk
tokenizer should run everos cascade rebuild.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@gloryfromca gloryfromca left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: update the NLTK-data setup for 3.10.4's private-directory requirement.

One introduced compatibility regression is marked inline.

Validation performed:

  • uv lock --check passed, and the lock installed NLTK 3.10.4 with its new defusedxml dependency.
  • With an owner-private corpus directory, the focused tokenizer suite passed (14/14) and the full unit suite passed (4,185 passed, 4 skipped).
  • With the repository's existing .venv/nltk_data setup in this mode-775 worktree, 3.10.4 refused the corpus and 11 focused tests failed; 3.9.4 reads the same corpus.
  • Ruff check/format, all 14 import contracts, asset/file-size/name/contributor-doc/datetime/singleton/OpenAPI/CJK gates passed when invoked directly (make is unavailable in this environment).

I covered CLAUDE.md and the applicable .claude/rules, the refreshed origin/main...HEAD diff, tokenizer factory/callers and dependency history, backward compatibility, test changes (none were weakened), and architecture/import constraints.

Comment thread pyproject.toml Resolved
On POSIX, NLTK 3.10 skips data another account could write (a group or
world write bit, or a foreign owner), so such data reads as missing and
the tokenizer asked for a download that changes nothing. A data
directory left group-writable by an earlier install (umask 002) keeps
its mode when the downloader runs again. The error now names the
directory and the chmod that fixes it, install-deps makes .venv/nltk_data
private after downloading, and the docs and the upgrade note say why.
Windows is unaffected: NLTK checks ownership on POSIX only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@gloryfromca gloryfromca left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blockers; this can merge as far as I am concerned.

The prior NLTK-data permission blocker is fixed and its thread is resolved. Validation on this revision:

  • reproduced the old failure with a group-writable corpus (11 tokenizer failures), then verified the new chmod -R go-w remediation (26/26 tokenizer tests passed);
  • verified the normal-process CapabilityError names the refused directory and remediation;
  • uv lock --check, diff whitespace, Ruff check/format, all 14 import contracts, documentation, asset/file-size/name/contributor-doc/datetime/singleton/OpenAPI/CJK gates passed. (make is unavailable in this environment, so its constituent gates were invoked directly.)

I covered the full refreshed diff and fix delta, applicable repository rules, tokenizer callers and dependency history, backward compatibility, test integrity, and architecture/import constraints. No tests were weakened. GitHub lint, links, package, title, and commit-message checks are also green; longer unit/integration jobs are still running.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant