🚀 🇲🇦 泰爾吉曼大模型 v2.0 (240M)
泰爾吉曼大模型 v2.0 是 atlasia/Terjman-Large-v1.2 的改進版本,它基於強大的 Transformer 架構構建,並針對高質量、準確的翻譯進行了微調。
此版本基於 atlasia/Terjman-Large-v1.2,並在一個更大、更精細的數據集上進行了訓練,從而提升了翻譯性能。該模型在 TerjamaBench(一個用於英語 - 摩洛哥達裡傑語翻譯模型的評估基準,更側重於在文化方面挑戰模型)上取得了與 gpt-4o-2024-08-06 相當的成績。
✨ 主要特性
✅ 針對英語到摩洛哥達裡傑語翻譯進行微調。
✅ 在開源模型中達到了最先進的性能。
✅ 與 🤗 Transformers 兼容,並且可以輕鬆部署在各種硬件環境中。
📈 性能對比
下表使用 BLEU、chrF 和 TER 分數,將 泰爾吉曼大模型 v2.0 與專有模型和開源模型進行了對比。更高的 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 |
泰爾吉曼大模型 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.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-Large-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 空間中運行
可以在 Terjman-Large 空間 中交互式地試用該模型 🤗。
使用文本生成推理 (TGI)
為了實現快速推理,可以使用 Hugging Face TGI:
pip install text-generation
text-generation-launcher --model-id BounharAbdelaziz/Terjman-Large-v2.0
使用 Transformers 和 PyTorch 在本地運行
pip install transformers torch
python -c "from transformers import pipeline; print(pipeline('translation', model='BounharAbdelaziz/Terjman-Large-v2.0')('Hello there!'))"
在 API 服務器上部署
可以使用 FastAPI 將翻譯服務作為 API 提供:
from fastapi import FastAPI
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
app = FastAPI()
model_name = "BounharAbdelaziz/Terjman-Large-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.001
- 訓練批次大小:
16
- 評估批次大小:
16
- 隨機種子:
42
- 梯度累積步數:
8
- 總有效批次大小:
128
- 優化器:
AdamW (Torch)
,betas=(0.9, 0.999)
,epsilon=1e-08
- 學習率調度器:
Linear
- 預熱比例:
0.1
- 訓練輪數:
2
- 精度:
混合 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-Large-v2.0}},
license = {CC BY-NC}
}