语言:
- 阿萨姆语
- 孟加拉语
- 博多语
- 多格拉语
- 孔卡尼语
- 古吉拉特语
- 印地语
- 卡纳达语
- 克什米尔语
- 迈蒂利语
- 马拉雅拉姆语
- 马拉地语
- 曼尼普尔语
- 尼泊尔语
- 奥里亚语
- 旁遮普语
- 梵语
- 桑塔利语
- 信德语
- 泰米尔语
- 泰卢固语
- 乌尔都语
语言详情: >-
阿萨姆语_孟加拉文, 孟加拉语_孟加拉文, 博多语_天城文, 多格拉语_天城文, 孔卡尼语_天城文, 古吉拉特语_古吉拉特文,
印地语_天城文, 卡纳达语_卡纳达文, 克什米尔语_阿拉伯文, 迈蒂利语_天城文, 马拉雅拉姆语_马拉雅拉姆文, 马拉地语_天城文,
曼尼普尔语_梅泰文, 尼泊尔语_天城文, 奥里亚语_奥里亚文, 旁遮普语_古鲁穆奇文, 梵语_天城文, 桑塔利语_奥尔奇基文,
信德语_天城文, 泰米尔语_泰米尔文, 泰卢固语_泰卢固文, 乌尔都语_阿拉伯文
标签:
许可证: MIT
数据集:
评估指标:
推理: false
印度语言互译2
这是印度语言互译2的模型卡片,展示了1B参数的印度语言间互译变体,该模型是通过拼接印度-英语1B和英语-印度1B变体后调整得到的。
关于模型训练、数据和评估指标的更多详情,请参阅博客。
使用说明
关于如何使用兼容Hugging Face的印度语言互译2模型进行推理,请参考GitHub仓库的详细说明。
import torch
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
from IndicTransToolkit.processor import IndicProcessor
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
src_lang, tgt_lang = "hin_Deva", "tam_Taml"
model_name = "ai4bharat/indictrans2-indic-indic-1B"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModelForSeq2SeqLM.from_pretrained(
model_name,
trust_remote_code=True,
torch_dtype=torch.float16,
attn_implementation="flash_attention_2"
).to(DEVICE)
ip = IndicProcessor(inference=True)
input_sentences = [
"जब मैं छोटा था, मैं हर रोज़ पार्क जाता था।",
"हमने पिछले सप्ताह एक नई फिल्म देखी जो कि बहुत प्रेरणादायक थी।",
"अगर तुम मुझे उस समय पास मिलते, तो हम बाहर खाना खाने चलते।",
"मेरे मित्र ने मुझे उसके जन्मदिन की पार्टी में बुलाया है, और मैं उसे एक तोहफा दूंगा।",
]
batch = ip.preprocess_batch(
input_sentences,
src_lang=src_lang,
tgt_lang=tgt_lang,
)
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
inputs = tokenizer(
batch,
truncation=True,
padding="longest",
return_tensors="pt",
return_attention_mask=True,
).to(DEVICE)
with torch.no_grad():
generated_tokens = model.generate(
**inputs,
use_cache=True,
min_length=0,
max_length=256,
num_beams=5,
num_return_sequences=1,
)
generated_tokens = tokenizer.batch_decode(
generated_tokens,
skip_special_tokens=True,
clean_up_tokenization_spaces=True,
)
translations = ip.postprocess_batch(generated_tokens, lang=tgt_lang)
for input_sentence, translation in zip(input_sentences, translations):
print(f"{src_lang}: {input_sentence}")
print(f"{tgt_lang}: {translation}")
引用
如果您使用我们的工作,请引用以下内容:
@article{gala2023indictrans,
title={IndicTrans2: Towards High-Quality and Accessible Machine Translation Models for all 22 Scheduled Indian Languages},
author={Jay Gala and Pranjal A Chitale and A K Raghavan and Varun Gumma and Sumanth Doddapaneni and Aswanth Kumar M and Janki Atul Nawale and Anupama Sujatha and Ratish Puduppully and Vivek Raghavan and Pratyush Kumar and Mitesh M Khapra and Raj Dabre and Anoop Kunchukuttan},
journal={Transactions on Machine Learning Research},
issn={2835-8856},
year={2023},
url={https://openreview.net/forum?id=vfT4YuzAYA},
note={}
}