Skip to content

Remove punctuation in ApplyWordEmbedding sample so every word matches - #7967

Open
krwq wants to merge 1 commit into
dotnet:mainfrom
krwq:krwq-applywordembedding-sample-punctuation
Open

krwq wants to merge 1 commit into
dotnet:mainfrom
krwq:krwq-applywordembedding-sample-punctuation

Conversation

@krwq

@krwq krwq commented Nov 27, 2026

Copy link
Copy Markdown
Member

Note

This change and description were written by GitHub Copilot (AI) on my behalf.

ApplyWordEmbedding uses the same sentence as ApplyCustomWordEmbedding, and NormalizeText keeps punctuation by default. So product. and again. were looked up with the trailing period and weren't found in the SSWE model, which has product and again. This passes keepPunctuations: false, like #7961 did for the custom-model sample.

The expected-output comment also didn't match what the sample prints today, so it's updated. It shows the first 10 of the 150 feature values. They're minimums that this change doesn't affect, so the new line only fixes the old mismatch.

Follow-up to #7961.

NormalizeText keeps punctuation by default, so "product." and "again." were
looked up with the trailing period and weren't found in the SSWE model, which
has "product" and "again". Pass keepPunctuations: false, as dotnet#7961 did for
ApplyCustomWordEmbedding.

The expected-output comment also didn't match what the sample prints, so it's
updated. It shows the first 10 of the 150 values, which are minimums that
this change doesn't affect.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

🟢 Approval recommended

No active review issues remain for the sample’s punctuation-normalization and expected-output comment updates.

No open issues 🎉

What changed in this PR

Updates the ML.NET ApplyWordEmbedding sample to remove punctuation before tokenization, allowing sentence-ending words to match the pretrained embedding vocabulary. This follows the custom-model sample fix in #7961.

Changes:

  • Passes keepPunctuations: false to NormalizeText.
  • Corrects the expected-output comment for the first 10 feature values; those minimum values are unaffected by punctuation removal.
File Description
docs/​samples/​Microsoft.ML.Samples/​Dynamic/​Transforms/​Text/​ApplyWordEmbedding.cs Removes punctuation during normalization and corrects the expected-output comment.

Review effort: Balanced

@vejbomar vejbomar 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.

Thanks, I didn't notice this sample when doing #7961, I agree it makes sense to have it consistent.

// Expected output:
// Number of Features: 150
// Features: -1.2489 0.2384 -1.3034 -0.9135 -3.4978 -0.1784 -1.3823 -0.3863 -2.5262 -0.8950 ...
// Features: -1.2489 -0.6884 -1.3034 -0.9135 -3.4978 -0.1784 -1.3823 -2.1131 -2.5262 -1.6288 ...

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.

For context on why the old Expected output comment differed: when ApplyWordEmbedding.cs was added in #3142, the initial commit (15be23ce2c) had a typo in the input text ("greate" instead of "great"), so "greate" was ignored as out-of-vocabulary when generating the comment. A review commit (58e2d4be07) fixed the typo to "great" without updating the expected output comment.

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.

3 participants