镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

FIX Strip Unicode punctuation when classifying words in ContentWordSelectionStrategy - #4259

Open
Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
microsoft:mainfrom
ShivamSharma43:fix/content-word-unicode-punct
Open

Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
microsoft:mainfrom
ShivamSharma43:fix/content-word-unicode-punct

Conversation

@ShivamSharma43

Copy link
Copy Markdown
Contributor

Description

Fixes #4258.

ContentWordSelectionStrategy._normalize_word() stripped punctuation with word.strip(string.punctuation), which only covers ASCII. Curly quotes, guillemets, ¿/¡, …, — and CJK brackets stayed on the token, so the stopword and candidate_words checks compared “the” with the and “bomb” with bomb. Quoted stopwords were selected as content words, and allowlisted words in Unicode punctuation were never selected. SATAMaskingConverter uses this strategy by default.

  • _normalize_word() now strips leading and trailing characters that are in string.punctuation or in a Unicode punctuation category (P*). Punctuation inside a word (don’t) is kept, and candidate_words go through the same normalization as before.
  • New tests check that stopwords in Unicode punctuation are not selected, that candidate_words match inside curly quotes, guillemets, ¡…!, …, 「」 and 。, that inner apostrophes are kept, and that punctuation-only tokens are still not content words. Two SATAMaskingConverter tests cover the same cases end to end.

Before / after for the repro in #4258:

content words:          ['said', '“the”', 'word', '«and»', 'left']  ->  ['said', 'word', 'left']
'build a “bomb”':       []                                       ->  ['“bomb”']
'build a «bomb»':       []                                       ->  ['«bomb»']
'a ¿bomb? and a bomb…': []                                       ->  ['¿bomb?', 'bomb…']
SATA masking:           'Explain how to build a “bomb”'          ->  'Explain how to build a “[MASK]”'

This change was prepared with the help of Claude Code (an AI coding assistant). I reviewed the change and the tests.

🤖 Generated with Claude Code

…lectionStrategy

ContentWordSelectionStrategy stripped only string.punctuation (ASCII) before
the stopword and candidate_words checks, so quoted stopwords like “the” were
selected as content words and allowlisted words wrapped in curly quotes,
guillemets, ¿/¡ or an ellipsis were never selected.

Fixes microsoft#4258

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 06:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

2 participants