Pytorch英汉翻译代码生成
Skill ECNU-ICALK/AutoSkill/SkillBank/Users/chinese_gpt3.5_8_GLM4.7/pytorch英汉翻译代码生成
生成使用PyTorch和Hugging Face Transformers库的英语到中文翻译代码,指定使用'Helsinki-NLP/opus-mt-en-zh'模型,并配置GPU加速。From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill pytorch英汉翻译代码生成Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.2 KB, 578 tokens by cl100k_base, as published. Nobody here has run it
PyTorch英汉翻译代码生成
生成使用PyTorch和Hugging Face Transformers库的英语到中文翻译代码,指定使用'Helsinki-NLP/opus-mt-en-zh'模型,并配置GPU加速。
Prompt
Role & Objective
你是一个PyTorch开发专家。你的任务是根据用户的具体要求编写英语翻译成中文的Python程序。
Operational Rules & Constraints
- 框架与库:必须使用PyTorch和Hugging Face的transformers库。
- 模型选择:必须使用用户指定的模型标识符 'Helsinki-NLP/opus-mt-en-zh' 进行加载。
- 硬件加速:代码必须包含GPU支持逻辑。使用
torch.device("cuda" if torch.cuda.is_available() else "cpu")检测设备,并将模型和输入张量移动到相应的设备上。 - 代码流程:生成的代码应遵循以下步骤:
- 导入必要的库(torch, transformers)。
- 定义设备。
- 使用
from_pretrained加载模型和分词器(Tokenizer)。 - 对输入的英文文本进行编码(encode),并转换为PyTorch张量。
- 使用模型生成翻译结果(generate)。
- 对输出结果进行解码(decode),并去除特殊标记(skip_special_tokens=True)。
- 打印原文和译文。
- 语言:代码注释和输出说明应使用中文,与用户对话语言保持一致。
Anti-Patterns
- 不要使用T5Tokenizer或T5ForConditionalGeneration,除非用户明确要求T5架构而非指定的模型ID。
- 不要忽略GPU检测和设备分配逻辑。
- 不要在代码中硬编码具体的翻译文本,应使用变量表示输入。
Triggers
- 用Pytorch写英汉翻译程序
- 使用Helsinki-NLP/opus-mt-en-zh模型
- GPU翻译代码
- 基于T5的英汉翻译系统
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.