Downloads · 30 days
66
6% of all-time downloads
Clancy1024/gemma-3-270m-translator-test-v1
gemma-3-270m-translator-test-v1 is a translation model from Clancy1024. Use it when you need text moved from one language to another. It is set up for transformers. The card lists the license as gemma.
这是一个基于 unsloth/gemma-3-270m-it 模型,使用 Helsinki-NLP/opus-100 数据集中 50,000 条英汉(en-zh)样本微调而成的翻译模型。
Downloads · 30 days
66
6% of all-time downloads
All-time downloads
1.1K
Public
Parameters
268M
866 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors1.1 GB · 74%
From the Hugging Face model README
这是一个基于 unsloth/gemma-3-270m-it 模型,使用 Helsinki-NLP/opus-100 数据集中 50,000 条英汉(en-zh)样本微调而成的翻译模型。
该模型利用 Unsloth 框架和 LoRA 技术进行了高效的参数微调,旨在将英文文本准确、流畅地翻译成中文。
unsloth/gemma-3-270m-it)。llama.cpp 运行。transformers 和 Unsloth (推荐)首先,请确保已安装 unsloth 和 transformers。
pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
pip install --no-deps xformers trl peft accelerate bitsandbytes
然后,您可以使用以下 Python 代码进行推理:
from unsloth import FastModel
import torch
# 从 Hub 加载模型和分词器
model, tokenizer = FastModel.from_pretrained(
model_name = "Clancy1024/gemma-3-270m-translator-test-v1", # 您的模型仓库 ID
max_seq_length = 2048,
load_in_4bit = True,
)
# 准备 Gemma 3 的聊天模板
from unsloth.chat_templates import get_chat_template
tokenizer = get_chat_template(tokenizer, chat_template="gemma3")
# 准备输入
english_text = "Hello, world! This is a test of the translation model."
instruction = f"Translate the following English text to Chinese:\n{english_text}"
messages = [{"role": "user", "content": instruction}]
input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to("cuda")
# 生成翻译结果
outputs = model.generate(input_ids=input_ids, max_new_tokens=128, use_cache=True)
response_ids = outputs[0, input_ids.shape[-1]:] # 移除输入部分
response = tokenizer.decode(response_ids, skip_special_tokens=True)
print("英文原文:", english_text)
print("中文翻译:", response.strip())
# 预期输出: 你好,世界!这是一个翻译模型的测试。
llama.cpp您也可以使用本仓库中提供的 gemma-3-translator-test-Q8_0.gguf 文件在 CPU 上进行推理。
# 首先,克隆 llama.cpp 仓库
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
# 使用 CMake 创建构建目录并生成构建文件
cmake -B build
# 执行编译 (这会自动检测并使用最适合您系统的优化)
cmake --build build --config Release
# 编译完成后,可执行文件位于 build/bin/ 目录下
# 运行推理:
./build/bin/main -m /path/to/your/gemma-3-translator-test-Q8_0.gguf \
-p "<start_of_turn>user\nTranslate the following English text to Chinese:\nHello, world!<start_of_turn>model\n" \
-n 64
unsloth/gemma-3-270m-itHelsinki-NLP/opus-100 (en-zh 子集),随机抽样 50,000 个样本。r (秩): 128lora_alpha: 128target_modules: ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]learning_rate: 2e-5num_train_epochs: 1per_device_train_batch_size: 8optimizer: adamw_8bit模型在单张 Google Colab T4 GPU 上完成训练,展现了 Unsloth 框架的高效率。
5.26482.5816损失值从 5.26 稳步下降至 2.58,表明模型在训练过程中得到了充分且有效的学习。
本模型是在 Gemma 许可证下发布的。训练数据集 Helsinki-NLP/opus-100 遵循 MIT 许可证。