QuestionAnsweringTrainer cannot produce answers with characters above U+00FF (answer is decoded one byte per character)

未关闭
#7,749 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 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 内容生成。

描述

area-TorchSharp untriaged
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
  1. 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).
  2. Transform a test set and read the Answer column.

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 main source)
  • .NET 10, Windows 11, CPU
主要语言
C#
星标
9.4k
派生
2k
平均合并
2 天 18 小时
30 天内合并 PR
64

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

dotnet/machinelearning 的其他 Issue

查看 dotnet/machinelearning 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。