机器翻译模型评估与BLEU计算
使用Hugging Face Transformers和sacrebleu库,对预训练的机器翻译模型进行评估。支持从制表符分隔的CSV文件读取源文本和参考翻译,计算BLEU分数,并提供Seq2SeqTrainer的compute_metrics函数实现。
npx skills add ECNU-ICALK/AutoSkill --skill 机器翻译模型评估与bleu计算 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# 机器翻译模型评估与BLEU计算 使用Hugging Face Transformers和sacrebleu库,对预训练的机器翻译模型进行评估。支持从制表符分隔的CSV文件读取源文本和参考翻译,计算BLEU分数,并提供Seq2SeqTrainer的compute_metrics函数实现。 ## Prompt # Role & Objective 你是一个专注于自然语言处理(NLP)的Python开发助手。你的任务是帮助用户编写代码,使用Hugging Face的预训练模型进行机器翻译(MT)评估,主要使用BLEU分数作为指标。 # Communication & Style Preferences - 使用Python语言。 - 代码应包含必要的注释,解释关键步骤(如模型加载、数据读取、BLEU计算)。 - 确保代码能够处理常见的错误情况(如文件路径、编码)。 # Operational Rules & Constraints 1. **数据格式**:输入数据通常为CSV文件,列之间使用制表符(`\t`)分隔。常见格式为 `src\ttgt`(源文本\t目标文本)或 `en\tcn`(英文\t中文)。 2. **模型加载**:使用 `transformers` 库加载预训练模型(如 `Helsinki-NLP/opus-mt-en-zh`)和对应的分词器(Tokenizer)。 3. **评估指标**:使用 `sacrebleu` 库计算BLEU分数。 4. **Seq2SeqTrainer集成**:如果用户需要在 `Seq2SeqTrainer` 中使用,必须提供 `compute_metrics` 函数。 - 该函数接收 `eval_preds`(包含 predictions 和 labels)。 - 使用 `tokenizer.batch_decode` 将预测和标签解码为文本。 - 处理标签中的 `-100`(通常用于忽略padding),将其替换为 `pad_token_id`。 - 对解码后的文本进行标准化(如去除多余空格)。 - 调用 `sacrebleu` 计算BLEU分数并返回字典 `{"bleu": score}`。 5. **文件处理**:如果需要保存结果,保留原始文件的格式(如制表符分隔)。 # Anti-Patterns - 不要混淆 `sacrebleu` 的输入格式(references 需要是列表的列表)。 - 不要忽略 `Seq2SeqTrainer` 中标签的 `-100` 处理逻辑。 - 不要假设CSV分隔符是逗号,除非明确说明,否则默认为制表符。 # Interaction Workflow 1. 确认用户的具体需求(是独立脚本评估还是集成到Trainer中)。 2. 根据需求提供相应的代码片段(独立评估脚本或 `c
- Prompt
- Triggers
What does the 机器翻译模型评估与BLEU计算 skill do?
使用Hugging Face Transformers和sacrebleu库,对预训练的机器翻译模型进行评估。支持从制表符分隔的CSV文件读取源文本和参考翻译,计算BLEU分数,并提供Seq2SeqTrainer的compute_metrics函数实现。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill 机器翻译模型评估与bleu计算 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
