SentencePieceTokenizer (Unigram, from tokenizer.json): equal-score segmentations are ordered differently from Hugging Face tokenizers
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- csharp
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
Start with SentencePieceTokenizer.CreateFromTokenizerJson and the Unigram segmentation path; compare its equal-score tie handling with Hugging Face tokenizers 0.23.3's Unigram::encode_optimized behavior described in the issue. Reproduce with the multilingual-e5-small tokenizer.json and input "aaaaaaaaaaaa". Done when tokenizer.json encoding matches the expected Hugging Face token ID order for tie cases; the issue names no test file.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
System Information:
- OS & Version: Debian 13 (trixie), x64
- ML.NET Version: Microsoft.ML.Tokenizers 3.0.0
- .NET Version: .NET SDK 10.0.404
- Reference: Hugging Face
tokenizers0.23.3
Describe the bug
On repetitive input, several Unigram segmentations can have exactly the same total score: they use the same pieces in a different order. When this happens, SentencePieceTokenizer picks a different path than Hugging Face tokenizers. The resulting token IDs are a permutation of the expected ones.
Hugging Face (Unigram::encode_optimized) keeps the path it finds first when scores are equal. Its final piece therefore starts as early as possible. SentencePiece C++ also differs from Hugging Face here, because it accumulates scores in float. So this is a parity issue rather than a single "correct" answer. But a tokenizer created with CreateFromTokenizerJson is naturally expected to reproduce the Hugging Face output for that file.
To Reproduce
Model: intfloat/multilingual-e5-small, revision 614241f622f53c4eeff9890bdc4f31cfecc418b3, file onnx/tokenizer.json.
using Microsoft.ML.Tokenizers;
using var stream = File.OpenRead("tokenizer.json");
var tokenizer = SentencePieceTokenizer.CreateFromTokenizerJson(
stream, addBeginningOfSentence: false, addEndOfSentence: false);
Console.WriteLine(string.Join(", ", tokenizer.EncodeToIds("aaaaaaaaaaaa")));
| Input | Microsoft.ML.Tokenizers 3.0.0 | Hugging Face tokenizers 0.23.3 |
|---|---|---|
"aaaaaaaaaaaa" |
[10, 83151, 83151, 11] (▁a, aaaaa, aaaaa, a) |
[10, 11, 83151, 83151] (▁a, a, aaaaa, aaaaa) |
Expected behavior
When the tokenizer is created from tokenizer.json, ties between equal-score segmentations are resolved the way Hugging Face resolves them. Alternatively, an option to choose that behavior.
Additional context
On a corpus of 12,600 real-world strings, 247 differ from Hugging Face. In every case it is the same pieces in a different order. Typical triggers are runs such as 0000…, ────, ==== and аааа. For an embedding model the order matters: cosine similarity between the embeddings of the two ID sequences drops to 0.97 in the worst case (median 0.998). That breaks parity tests that expect ≥ 0.9999.
We reimplemented the Hugging Face Viterbi pass over the library's normalized output in about 100 lines. With it, all 12,600 strings match.
A related normalization bug (control characters becoming <unk>) is reported in #7908.
- Ngôn ngữ chính
- C#
- Star
- 9.4k
- Fork
- 2k
- Merge trung bình
- 2 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 64
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/machinelearning
-
area-Native untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
dotnet/machinelearning#7837 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area-TensorFlow untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
dotnet/machinelearning#7836 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ToArrowRecordBatches accumulates arrays from previous batches, producing invalid record batchesĐang mởarea-DataFrame bug untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
dotnet/machinelearning#7799 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
LlamaTokenizer encodes some runs of repeated characters differently from SentencePieceCó thể đã có người làm @Laurianti đã nhận 42 ngày trước. Đang mởarea-Tokenizers untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
dotnet/machinelearning#7751 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
BertTokenizer merges words separated only by `\n`, `\t` or `\r`Có thể đã có người làm @Laurianti đã nhận 23 ngày trước. Đang mởarea-Tokenizers green
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
dotnet/machinelearning#7724 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của dotnet/machinelearning
Issue tương tự
-
bug emitter:client:csharp
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
microsoft/typespec#12572 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-area-label
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
AWS Lambda: KeyNotFoundException drops HTTP-triggered transactions when allowAllHeaders is disabledĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
newrelic/newrelic-dotnet-agent#3949 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area-networking
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
dotnet/aspnetcore#70545 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 87/100
Maintainer thường phản hồi trong vòng 1 ngày