Indicbart
IndicBART是一個專注於印度語言和英語的多語言序列到序列預訓練模型,支持11種印度語言,基於mBART架構構建。
下載量 4,120
發布時間 : 3/2/2022
模型概述
IndicBART是一個多語言序列到序列預訓練模型,專注於印度語言和英語的自然語言生成任務,如機器翻譯、摘要生成和問題生成等。
模型特點
多語言支持
支持11種印度語言和英語,包括阿薩姆語、孟加拉語、古吉拉特語等。
高效計算
模型比mBART和mT5(基礎版)小得多,因此在微調和解碼時計算成本更低。
大規模預訓練
在大型印度語言語料庫(4.52億句子和90億詞元)上訓練,其中包括印度英語內容。
統一書寫系統
除英語外,所有語言均以天城文書寫,以促進相關語言之間的遷移學習。
模型能力
文本生成
機器翻譯
摘要生成
問題生成
使用案例
自然語言處理
機器翻譯
將英語翻譯為印度語言或將印度語言翻譯為英語。
摘要生成
生成印度語言文本的摘要。
問題生成
根據印度語言文本生成相關問題。
🚀 IndicBART
IndicBART 是一個多語言的序列到序列預訓練模型,專注於印度語言和英語。它目前支持 11 種印度語言,基於 mBART 架構構建。你可以通過使用有監督的訓練數據對 IndicBART 模型進行微調,來構建適用於印度語言的自然語言生成應用,如機器翻譯、摘要生成、問題生成等任務。
🚀 快速開始
你可以參考以下代碼示例快速使用 IndicBART 模型:
from transformers import MBartForConditionalGeneration, AutoModelForSeq2SeqLM
from transformers import AlbertTokenizer, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("ai4bharat/IndicBART", do_lower_case=False, use_fast=False, keep_accents=True)
# Or use tokenizer = AlbertTokenizer.from_pretrained("ai4bharat/IndicBART", do_lower_case=False, use_fast=False, keep_accents=True)
model = AutoModelForSeq2SeqLM.from_pretrained("ai4bharat/IndicBART")
# Or use model = MBartForConditionalGeneration.from_pretrained("ai4bharat/IndicBART")
# Some initial mapping
bos_id = tokenizer._convert_token_to_id_with_added_voc("<s>")
eos_id = tokenizer._convert_token_to_id_with_added_voc("</s>")
pad_id = tokenizer._convert_token_to_id_with_added_voc("<pad>")
# To get lang_id use any of ['<2as>', '<2bn>', '<2en>', '<2gu>', '<2hi>', '<2kn>', '<2ml>', '<2mr>', '<2or>', '<2pa>', '<2ta>', '<2te>']
# First tokenize the input and outputs. The format below is how IndicBART was trained so the input should be "Sentence </s> <2xx>" where xx is the language code. Similarly, the output should be "<2yy> Sentence </s>".
inp = tokenizer("I am a boy </s> <2en>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids # tensor([[ 466, 1981, 80, 25573, 64001, 64004]])
out = tokenizer("<2hi> मैं एक लड़का हूँ </s>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids # tensor([[64006, 942, 43, 32720, 8384, 64001]])
# Note that if you use any language other than Hindi or Marathi, you should convert its script to Devanagari using the Indic NLP Library.
model_outputs=model(input_ids=inp, decoder_input_ids=out[:,0:-1], labels=out[:,1:])
# For loss
model_outputs.loss ## This is not label smoothed.
# For logits
model_outputs.logits
# For generation. Pardon the messiness. Note the decoder_start_token_id.
model.eval() # Set dropouts to zero
model_output=model.generate(inp, use_cache=True, num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=pad_id, bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2en>"))
# Decode to get output strings
decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
print(decoded_output) # I am a boy
# Note that if your output language is not Hindi or Marathi, you should convert its script from Devanagari to the desired language using the Indic NLP Library.
# What if we mask?
inp = tokenizer("I am [MASK] </s> <2en>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
model_output=model.generate(inp, use_cache=True, num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=pad_id, bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2en>"))
decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
print(decoded_output) # I am happy
inp = tokenizer("मैं [MASK] हूँ </s> <2hi>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
model_output=model.generate(inp, use_cache=True, num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=pad_id, bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2en>"))
decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
print(decoded_output) # मैं जानता हूँ
inp = tokenizer("मला [MASK] पाहिजे </s> <2mr>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
model_output=model.generate(inp, use_cache=True, num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=pad_id, bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2en>"))
decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
print(decoded_output) # मला ओळखलं पाहिजे
✨ 主要特性
- 支持多種語言:支持阿薩姆語、孟加拉語、古吉拉特語、印地語、馬拉地語、奧里亞語、旁遮普語、卡納達語、馬拉雅拉姆語、泰米爾語、泰盧固語和英語。並非所有這些語言都被 mBART50 和 mT5 支持。
- 輕量級模型:該模型比 mBART 和 mT5(-base) 模型小得多,因此在微調和解碼時計算成本更低。
- 大規模語料訓練:在大型印度語言語料庫(4.52 億個句子和 90 億個標記)上進行訓練,其中還包括印度英語內容。
- 促進遷移學習:除英語外,所有語言都以天城文表示,以促進相關語言之間的遷移學習。
📦 安裝指南
文檔未提及具體安裝步驟,可參考相關依賴庫的官方安裝說明進行安裝。
💻 使用示例
基礎用法
# 以下是使用 IndicBART 進行基礎文本處理的示例代碼
from transformers import MBartForConditionalGeneration, AutoModelForSeq2SeqLM
from transformers import AlbertTokenizer, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("ai4bharat/IndicBART", do_lower_case=False, use_fast=False, keep_accents=True)
model = AutoModelForSeq2SeqLM.from_pretrained("ai4bharat/IndicBART")
# 輸入和輸出的分詞處理
inp = tokenizer("I am a boy </s> <2en>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
out = tokenizer("<2hi> मैं एक लड़का हूँ </s>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
model_outputs = model(input_ids=inp, decoder_input_ids=out[:,0:-1], labels=out[:,1:])
# 獲取損失值
print(model_outputs.loss)
# 獲取對數幾率
print(model_outputs.logits)
高級用法
# 以下是使用 IndicBART 進行文本生成的示例代碼
model.eval()
bos_id = tokenizer._convert_token_to_id_with_added_voc("<s>")
eos_id = tokenizer._convert_token_to_id_with_added_voc("</s>")
pad_id = tokenizer._convert_token_to_id_with_added_voc("<pad>")
inp = tokenizer("I am [MASK] </s> <2en>", add_special_tokens=False, return_tensors="pt", padding=True).input_ids
model_output = model.generate(inp, use_cache=True, num_beams=4, max_length=20, min_length=1, early_stopping=True, pad_token_id=pad_id, bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2en>"))
decoded_output = tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
print(decoded_output)
📚 詳細文檔
🔧 技術細節
預訓練語料庫
我們使用了 IndicCorp 數據,涵蓋 12 種語言,包含 4.52 億個句子(90 億個標記)。該模型使用了 mBART 中採用的文本填充目標進行訓練。
下游任務微調
📄 許可證
該模型遵循 MIT 許可證。
📖 引用
如果你使用了 IndicBART,請引用以下論文:
@misc{dabre2021indicbart,
title={IndicBART: A Pre-trained Model for Natural Language Generation of Indic Languages},
author={Raj Dabre and Himani Shrotriya and Anoop Kunchukuttan and Ratish Puduppully and Mitesh M. Khapra and Pratyush Kumar},
year={2021},
eprint={2109.02903},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
⚠️ 重要提示
- 該模型與最新版本的 transformers 兼容,但開發時使用的是 4.3.2 版本,因此如果可能的話,建議使用 4.3.2 版本。
- 雖然文檔中僅展示瞭如何獲取對數幾率、損失值以及如何生成輸出,但你可以執行
MBartForConditionalGeneration
類所能執行的幾乎所有操作,具體可參考 這裡。 - 注意,文檔中使用的分詞器基於 sentencepiece 而非 BPE。因此,使用了
AlbertTokenizer
類而非MBartTokenizer
類。 - 如果你希望使用非天城文書寫的語言(英語除外),則應首先使用 Indic NLP Library 將其轉換為天城文。獲得輸出後,應將其轉換回原始文字。
💡 使用建議
在使用 IndicBART 模型時,可根據具體任務需求選擇合適的微調方法和參數設置,以獲得更好的性能。同時,注意處理非天城文語言時的文字轉換問題。
Phi 2 GGUF
其他
Phi-2是微軟開發的一個小型但強大的語言模型,具有27億參數,專注於高效推理和高質量文本生成。
大型語言模型 支持多種語言
P
TheBloke
41.5M
205
Roberta Large
MIT
基於掩碼語言建模目標預訓練的大型英語語言模型,採用改進的BERT訓練方法
大型語言模型 英語
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基礎模型的蒸餾版本,在保持相近性能的同時更輕量高效,適用於序列分類、標記分類等自然語言處理任務。
大型語言模型 英語
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一個多語言大語言模型,針對多語言對話用例進行了優化,在常見的行業基準測試中表現優異。
大型語言模型 英語
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基於100種語言的2.5TB過濾CommonCrawl數據預訓練的多語言模型,採用掩碼語言建模目標進行訓練。
大型語言模型 支持多種語言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基於Transformer架構的英語預訓練模型,通過掩碼語言建模目標在海量文本上訓練,支持文本特徵提取和下游任務微調
大型語言模型 英語
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI發佈的開放預訓練Transformer語言模型套件,參數量從1.25億到1750億,旨在對標GPT-3系列性能,同時促進大規模語言模型的開放研究。
大型語言模型 英語
O
facebook
6.3M
198
1
基於transformers庫的預訓練模型,適用於多種NLP任務
大型語言模型
Transformers

1
unslothai
6.2M
1
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多語言大語言模型系列,包含8B、70B和405B參數規模,支持8種語言和代碼生成,優化了多語言對話場景。
大型語言模型
Transformers 支持多種語言

L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基礎版是由Google開發的文本到文本轉換Transformer模型,參數規模2.2億,支持多語言NLP任務。
大型語言模型 支持多種語言
T
google-t5
5.4M
702
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98