Skip to content
Back to skills

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
educationpython

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill 'pytorch英汉翻译代码生成' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Pytorch英汉翻译代码生成?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Pytorch英汉翻译代码生成
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-pytorch-71b8b78a/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-pytorch-71b8b78a)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.