🚀 🇲🇦 Terjman-Nano-v2.0 (77M)
Terjman-Nano-v2.0是atlasia/Terjman-Nano-v1的改進版本,它基於強大的Transformer架構構建,並針對高質量、準確的翻譯進行了微調。此版本基於atlasia/Terjman-Nano-v1,並在更大、更精細的數據集上進行了訓練,從而提升了翻譯性能。在TerjamaBench(一個針對英語 - 摩洛哥達里語翻譯模型的評估基準,更側重於從文化方面對模型進行挑戰)上,該模型取得了與gpt-4o-2024-08-06相當的結果。
🚀 快速開始
特性
✅ 針對英語到摩洛哥達里語的翻譯進行了微調。
✅ 在開源模型中具有最先進的性能。
✅ 與🤗 Transformers兼容,並且可以輕鬆部署在各種硬件環境中。
性能對比
以下表格對比了Terjman-Nano-v2.0與專有模型和開源模型在BLEU、chrF和TER得分上的表現。BLEU/chrF得分越高、TER得分越低,表示翻譯質量越好。
模型 |
大小 |
BLEU↑ |
chrF↑ |
TER↓ |
專有模型 |
|
|
|
|
gemini-exp-1206 |
* |
30.69 |
54.16 |
67.62 |
claude-3-5-sonnet-20241022 |
* |
30.51 |
51.80 |
67.42 |
gpt-4o-2024-08-06 |
* |
28.30 |
50.13 |
71.77 |
開源模型 |
|
|
|
|
Terjman-Ultra-v2.0 |
1.3B |
25.00 |
44.70 |
77.20 |
Terjman-Supreme-v2.0 |
3.3B |
23.43 |
44.57 |
78.17 |
Terjman-Large-v2.0 |
240M |
22.67 |
42.57 |
83.00 |
Terjman-Nano-v2.0 (本模型) |
77M |
18.84 |
38.41 |
94.73 |
atlasia/Terjman-Large-v1.2 |
240M |
16.33 |
37.10 |
89.13 |
MBZUAI-Paris/Atlas-Chat-9B |
9B |
14.80 |
35.26 |
93.95 |
facebook/nllb-200-3.3B |
3.3B |
14.76 |
34.17 |
94.33 |
atlasia/Terjman-Nano |
77M |
09.98 |
26.55 |
106.49 |
模型詳情
💻 使用示例
基礎用法
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
model_name = "BounharAbdelaziz/Terjman-Nano-v2.0"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
def translate(text):
inputs = tokenizer(text, return_tensors="pt")
output = model.generate(**inputs)
return tokenizer.decode(output[0], skip_special_tokens=True)
text = "Hello there! Today the weather is so nice in Geneva, couldn't ask for more to enjoy the holidays :)"
translation = translate(text)
print("Translation:", translation)
📚 詳細文檔
部署
在Hugging Face Space中運行
可以在Terjman-Nano Space中交互式地試用該模型 🤗。
使用Text Generation Inference (TGI)
若要進行快速推理,可以使用Hugging Face TGI:
pip install text-generation
text-generation-launcher --model-id BounharAbdelaziz/Terjman-Nano-v2.0
使用Transformers和PyTorch在本地運行
pip install transformers torch
python -c "from transformers import pipeline; print(pipeline('translation', model='BounharAbdelaziz/Terjman-Nano-v2.0')('Hello there!'))"
在API服務器上部署
可以使用FastAPI將翻譯服務作為API提供:
from fastapi import FastAPI
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
app = FastAPI()
model_name = "BounharAbdelaziz/Terjman-Nano-v2.0"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
@app.get("/translate/")
def translate(text: str):
inputs = tokenizer(text, return_tensors="pt")
output = model.generate(**inputs)
return {"translation": tokenizer.decode(output[0], skip_special_tokens=True)}
訓練細節(超參數)
該模型使用以下訓練設置進行微調:
- 學習率:
0.0001
- 訓練批次大小:
64
- 評估批次大小:
64
- 隨機種子:
42
- 梯度累積步數:
4
- 總有效批次大小:
256
- 優化器:
AdamW (Torch)
,betas=(0.9,0.999)
,epsilon=1e-08
- 學習率調度器:
Linear
- 熱身比例:
0.1
- 訓練輪數:
5
- 精度:
Mixed FP16
,用於高效訓練
框架版本
- Transformers 4.47.1
- Pytorch 2.5.1+cu124
- Datasets 3.1.0
- Tokenizers 0.21.0
📄 許可證
該模型遵循**CC BY - NC(知識共享署名 - 非商業性使用)**許可協議發佈,這意味著它可用於研究和個人項目,但不能用於商業目的。如需商業使用,請聯繫相關人員 :)
@misc{terjman-v2,
title = {Terjman-v2: High-Quality English-Moroccan Darija Translation Model},
author={Abdelaziz Bounhar},
year={2025},
howpublished = {\url{https://huggingface.co/BounharAbdelaziz/Terjman-Nano-v2.0}},
license = {CC BY-NC}
}