QuestionAnsweringTrainer cannot produce answers with characters above U+00FF (answer is decoded one byte per character)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 74/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- csharp
调研方向
Start in Roberta/QATrainer.cs, where the mapper fills PredictedAnswersBuffer, and reproduce the issue with the Korean SQuAD-format dataset described in the report. Inspect the tokenizer offsets from EncodeToTokens and the TokenizerExtensions.GetInstance path. Done means predicted answers preserve non-Latin characters and match the corresponding context substrings, with the existing reproduction completing normally.
由索引模型根据 Issue 内容生成。
描述
Description
QuestionAnsweringTrainer (Microsoft.ML.TorchSharp, Roberta/QATrainer.cs) cannot produce an answer that contains characters above U+00FF. For Korean, Chinese, Japanese, Cyrillic and similar text, the predicted answer comes out with those characters missing, so exact match is unreachable whatever the model learned.
Cause
The predicted answer is not sliced out of the context string. It is decoded from the span's token ids:
// QATrainer.cs (main), in the mapper that fills PredictedAnswersBuffer
_parent.Tokenizer.Decode(
_parent.Tokenizer.RobertaModel().ConvertOccurrenceRanksToIds(contextIds).ToArray()
.AsSpan(predictStart - questionLength - 2, predictEnd - predictStart).ToArray())
The tokenizer comes from TokenizerExtensions.GetInstance, which calls EnglishRobertaTokenizer.Create(...) with the default filterUnsupportedChars = true. On that path EnglishRobertaTokenizer.MapIdToToken maps each token character through UnicodeToByte and appends the byte value as a char. Every output character is therefore ≤ U+00FF, and multi-byte UTF-8 sequences are never reassembled into the original characters.
Reproduction
- Train
mlContext.MulticlassClassification.Trainers.QuestionAnswer(...)on a small SQuAD-format dataset whose contexts and answers are in Korean (any non-Latin script shows the same behavior). - Transform a test set and read the
Answercolumn.
Observed with 26 training rows and 10 epochs: training completes normally, but all 8 predicted answers contain only the digits, ASCII punctuation and spaces of their spans, with every Hangul character missing, e.g. "12 , 1 100". Character-level F1 is about 0.05–0.08 and exact match is 0.
Expected behavior
The predicted answer is the corresponding substring of the context, in whatever script the context uses.
Suggested fix
Map the predicted token span back to character offsets in the original context (the tokenizer already provides offsets via EncodeToTokens) and return context.Substring(start, length), instead of decoding the ids. Alternatively, decode byte-level tokens to bytes and UTF-8-decode them (filterUnsupportedChars: false with proper byte reassembly).
Environment
- Microsoft.ML 5.0.0, Microsoft.ML.TorchSharp 0.23.0 (behavior also matches the current
mainsource) - .NET 10, Windows 11, CPU
- 主要语言
- C#
- 星标
- 9.4k
- 派生
- 2k
- 平均合并
- 2 天 18 小时
- 30 天内合并 PR
- 64
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dotnet/machinelearning 的其他 Issue
-
area-Native untriaged
难度 2/5 1-3 小时 新手友好度 76/100
dotnet/machinelearning#7837 ·
维护者通常 1 天内回复
-
area-TensorFlow untriaged
难度 2/5 1-3 小时 新手友好度 62/100
dotnet/machinelearning#7836 ·
维护者通常 1 天内回复
-
area-DataFrame bug untriaged
难度 2/5 1-3 小时 新手友好度 62/100
dotnet/machinelearning#7799 ·
维护者通常 1 天内回复
-
LlamaTokenizer encodes some runs of repeated characters differently from SentencePiece可能已有人在做 @Laurianti 于 42 天前认领。 未关闭area-Tokenizers untriaged
难度 2/5 1-3 小时 新手友好度 88/100
dotnet/machinelearning#7751 · 1 条评论 ·
维护者通常 1 天内回复
-
BertTokenizer merges words separated only by `\n`, `\t` or `\r`可能已有人在做 @Laurianti 于 23 天前认领。 未关闭area-Tokenizers green
难度 2/5 1-3 小时 新手友好度 85/100
dotnet/machinelearning#7724 · 3 条评论 ·
维护者通常 1 天内回复
查看 dotnet/machinelearning 的全部 Issue
相似的 Issue
-
bug emitter:client:csharp
难度 2/5 1-3 小时 新手友好度 84/100
microsoft/typespec#12572 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
needs-area-label
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
-
AWS Lambda: KeyNotFoundException drops HTTP-triggered transactions when allowAllHeaders is disabled未关闭bug
难度 2/5 1-3 小时 新手友好度 70/100
newrelic/newrelic-dotnet-agent#3949 · 1 条评论 ·
维护者通常 1 天内回复
-
area-networking
难度 2/5 1-3 小时 新手友好度 78/100
dotnet/aspnetcore#70545 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 87/100
维护者通常 1 天内回复