Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
ff40b11
Initial plan
Copilot Jun 10, 2026
862be32
Add public SentencePieceTokenizer.Create(vocab) and CreateFromTokeniz…
Copilot Jun 10, 2026
112ee2b
Fix BOS/EOS positional fallback, normalizer type validation, and prep…
Copilot Jun 11, 2026
7e32c05
Fix null normalizer guard, recursive Sequence support, BOS/EOS valida…
Copilot Jun 11, 2026
057cd46
Generalize SentencePiece special tokens to prefix/suffix lists with p…
ericstj Jun 12, 2026
0725072
Support JSON-only Unigram normalizer chains and broaden tokenizer.jso…
ericstj Jun 18, 2026
96961f8
Address Copilot review: byte_fallback init, Metaspace replacement, doc
ericstj Jun 18, 2026
4de649c
Address Copilot review round 2: Nmt, processor affix validation, cleanup
ericstj Jun 18, 2026
bc46cb8
Address Copilot review round 3: clarify charsmap comment, label missi…
ericstj Jun 18, 2026
eadbf7d
Address Copilot review round 4: byte-offset gating, base64 + unk_id v…
ericstj Jun 18, 2026
1b3e19a
Address Copilot review round 5: validate unk_id and vocab entry value…
ericstj Jun 18, 2026
be2f36c
Address Copilot review round 6: validate JSON value kinds across the …
ericstj Jun 18, 2026
6f361d6
Address Copilot review round 7: validate template special-token id co…
ericstj Jun 18, 2026
45f5fd2
Address Copilot review round 8: remove redundant casts in tests
ericstj Jun 18, 2026
e1ff3c5
Address Copilot review round 9: guard normalizer Build value kinds
ericstj Jun 18, 2026
512eb13
Address Tarek review: support null unk_id and reject unknown pre-toke…
ericstj Jul 16, 2026
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
44 changes: 44 additions & 0 deletions src/Microsoft.ML.Tokenizers/Model/SentencePieceBaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,50 @@ internal SentencePieceBaseModel(ModelProto modelProto, bool addBos = false, bool
specialTokens);
}

internal SentencePieceBaseModel(
bool addBos, bool addEos,
string bosToken, int bosId,
string eosToken, int eosId,
string unkToken, int unkId,
bool addDummyPrefix, bool escapeWhiteSpaces,
bool treatWhitespaceAsSuffix, bool byteFallback,
ReadOnlySpan<byte> precompiledCharsmap, bool removeExtraWhitespaces,
IReadOnlyDictionary<string, int>? specialTokens)
{
AddBeginningOfSentence = addBos;
AddEndOfSentence = addEos;
BeginningOfSentenceToken = bosToken;
BeginningOfSentenceId = bosId;
EndOfSentenceToken = eosToken;
EndOfSentenceId = eosId;
UnknownToken = unkToken;
UnknownId = unkId;
AddDummyPrefix = addDummyPrefix;
Comment thread
ericstj marked this conversation as resolved.
EscapeWhiteSpaces = escapeWhiteSpaces;
TreatWhitespaceAsSuffix = treatWhitespaceAsSuffix;
ByteFallback = byteFallback;
SpecialTokens = specialTokens;

if (specialTokens is not null && specialTokens.Count > 0)
{
InternalSpecialTokens = new Dictionary<StringSpanOrdinalKey, int>();
SpecialTokensReverse = new Dictionary<int, string>();

foreach (var item in specialTokens)
{
InternalSpecialTokens.Add(new StringSpanOrdinalKey(item.Key), item.Value);
SpecialTokensReverse.Add(item.Value, item.Key);
}

SpecialTokensRegex = new Regex(string.Join("|", specialTokens.Keys.Select(s => Regex.Escape(s))), RegexOptions.Compiled);
}

Normalizer = new SentencePieceNormalizer(
precompiledCharsmap, removeExtraWhitespaces,
addDummyPrefix, escapeWhiteSpaces,
treatWhitespaceAsSuffix, specialTokens);
}

internal Regex? SpecialTokensRegex { get; }

internal Dictionary<StringSpanOrdinalKey, int>? InternalSpecialTokens { get; }
Expand Down
Loading
Loading