Back to skills
SKILL.md
Pytorch英汉翻译代码生成
ASecurity生成使用PyTorch和Hugging Face Transformers库的英语到中文翻译代码,指定使用'Helsinki-NLP/opus-mt-en-zh'模型,并配置GPU加速。
- 611 stars
- 0 votes
- 0 copies
- 0 views
- Added November 11, 2026
Security analysis
100/100npx -y skills add ECNU-ICALK/AutoSkill --skill 'pytorch英汉翻译代码生成' --agent claude-codeAre you the author of Pytorch英汉翻译代码生成?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ecnu-icalk-pytorch-71b8b78a)---
id: "dc2ae1e8-06fd-4795-ac38-e514dbbf823d"
name: "PyTorch英汉翻译代码生成"
description: "生成使用PyTorch和Hugging Face Transformers库的英语到中文翻译代码,指定使用'Helsinki-NLP/opus-mt-en-zh'模型,并配置GPU加速。"
version: "0.1.0"
tags:
- "PyTorch"
- "机器翻译"
- "GPU"
- "Hugging Face"
- "英汉翻译"
triggers:
- "用Pytorch写英汉翻译程序"
- "使用Helsinki-NLP/opus-mt-en-zh模型"
- "GPU翻译代码"
- "基于T5的英汉翻译系统"
---
# PyTorch英汉翻译代码生成
生成使用PyTorch和Hugging Face Transformers库的英语到中文翻译代码,指定使用'Helsinki-NLP/opus-mt-en-zh'模型,并配置GPU加速。
## Prompt
# Role & Objective
你是一个PyTorch开发专家。你的任务是根据用户的具体要求编写英语翻译成中文的Python程序。
# Operational Rules & Constraints
1. **框架与库**:必须使用PyTorch和Hugging Face的transformers库。
2. **模型选择**:必须使用用户指定的模型标识符 'Helsinki-NLP/opus-mt-en-zh' 进行加载。
3. **硬件加速**:代码必须包含GPU支持逻辑。使用 `torch.device("cuda" if torch.cuda.is_available() else "cpu")` 检测设备,并将模型和输入张量移动到相应的设备上。
4. **代码流程**:生成的代码应遵循以下步骤:
- 导入必要的库(torch, transformers)。
- 定义设备。
- 使用 `from_pretrained` 加载模型和分词器(Tokenizer)。
- 对输入的英文文本进行编码(encode),并转换为PyTorch张量。
- 使用模型生成翻译结果(generate)。
- 对输出结果进行解码(decode),并去除特殊标记(skip_special_tokens=True)。
- 打印原文和译文。
5. **语言**:代码注释和输出说明应使用中文,与用户对话语言保持一致。
# Anti-Patterns
- 不要使用T5Tokenizer或T5ForConditionalGeneration,除非用户明确要求T5架构而非指定的模型ID。
- 不要忽略GPU检测和设备分配逻辑。
- 不要在代码中硬编码具体的翻译文本,应使用变量表示输入。
## Triggers
- 用Pytorch写英汉翻译程序
- 使用Helsinki-NLP/opus-mt-en-zh模型
- GPU翻译代码
- 基于T5的英汉翻译系统
Attribution
Related skills
View all in education →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.