许可证: mit
语言:
- 英语
- 孟加拉语
- 印地语
- 马拉地语
- 泰米尔语
- 泰卢固语
- 马拉雅拉姆语
- 旁遮普语
- 古吉拉特语
- 奥里亚语
基础模型:
- ai4bharat/indictrans2-en-indic-1B
任务标签: 翻译
评估指标:
- BLEU
- 谷歌BLEU
- chrF++
推理: 不支持
数据集:
- MILPaC
标签:
- InLegalTrans
- 法律
- 自然语言处理
InLegalTrans
这是InLegalTrans-En2Indic-1B翻译模型的介绍页,该模型是基于IndicTrans2模型微调的版本,专门用于将印度法律文本从英语翻译为印度语言。
训练数据
我们使用MILPaC(多语言印度法律平行语料库)进行微调。这是首个高质量的印度法律平行语料库,包含英语(EN)与九种印度语言(IN)——孟加拉语(BN)、印地语(HI)、马拉地语(MR)、泰米尔语(TA)、泰卢固语(TE)、马拉雅拉姆语(ML)、旁遮普语(PA)、古吉拉特语(GU)和奥里亚语(OR)——的平行对齐文本单元。更多关于该语料库的细节,请参阅论文。
在微调过程中,我们按语言将MILPaC随机划分为80%(训练)、10%(验证)和10%(测试)的比例。我们使用80%的训练集(每种英语到印度语言对的80%组合)来微调IndicTrans2模型,并使用10%的验证集(每种英语到印度语言对的10%组合)来选择最佳检查点并防止过拟合。
模型概述与使用说明
InLegalTrans模型使用了与IndicTrans2相同的分词器,并具有相同的架构,参数约1.12B。
import torch
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
from IndicTransToolkit import IndicProcessor
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
src_lang, tgt_lang = "eng_Latn", "ben_Beng"
tokenizer = AutoTokenizer.from_pretrained("ai4bharat/indictrans2-en-indic-1B", trust_remote_code=True)
model = AutoModelForSeq2SeqLM.from_pretrained(
"law-ai/InLegalTrans-En2Indic-1B",
trust_remote_code=True,
attn_implementation="eager",
low_cpu_mem_usage=True,
).to(device)
ip = IndicProcessor(inference=True)
input_sentences = [
"(7) Any such allowance for the maintenance and expenses for proceeding shall be payable from the date of the order, or, if so ordered, from the date of the application for maintenance or expenses of proceeding, as the case may be.",
"(2) Where it appears to the Tribunal that, in consequence of any decision of a competent Civil Court, any order made under section 9 should be cancelled or varied, it shall cancel the order or, as the case may be, vary the same accordingly.",
]
batch = ip.preprocess_batch(input_sentences, src_lang=src_lang, tgt_lang=tgt_lang)
input_text_encoding = tokenizer(
batch,
max_length=256,
truncation=True,
padding="longest",
return_tensors="pt",
return_attention_mask=True,
).to(device)
generated_tokens = model.generate(
**input_text_encoding,
max_length=256,
do_sample=True,
num_beams=4,
num_return_sequences=1,
early_stopping=False,
use_cache=True,
)
with tokenizer.as_target_tokenizer():
generated_tokens = tokenizer.batch_decode(
generated_tokens.detach().cpu().tolist(),
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}")
微调结果
下表展示了InLegalTrans模型与IndicTrans2模型在MILPaC的10%测试集上的性能对比。评估指标包括BLEU、GLEU和chrF++。在所有英语到印度语言的翻译任务中,InLegalTrans均显著优于IndicTrans2,在所有评估指标上均表现更优。
英语到印度语言 |
模型 |
BLEU |
GLEU |
chrF++ |
英语到孟加拉语 |
IndicTrans2 |
25.4 |
28.8 |
53.7 |
|
InLegalTrans |
45.8 |
47.6 |
70.9 |
英语到印地语 |
IndicTrans2 |
41.0 |
42.5 |
59.9 |
|
InLegalTrans |
56.9 |
57.1 |
73.8 |
英语到马拉地语 |
IndicTrans2 |
25.2 |
28.7 |
55.4 |
|
InLegalTrans |
44.4 |
46.0 |
68.9 |
英语到泰米尔语 |
IndicTrans2 |
32.8 |
35.3 |
62.3 |
|
InLegalTrans |
40.0 |
42.5 |
69.9 |
英语到泰卢固语 |
IndicTrans2 |
10.7 |
14.2 |
37.9 |
|
InLegalTrans |
31.3 |
31.6 |
58.5 |
英语到马拉雅拉姆语 |
IndicTrans2 |
21.9 |
25.8 |
52.9 |
|
InLegalTrans |
37.4 |
40.3 |
69.7 |
英语到旁遮普语 |
IndicTrans2 |
27.8 |
31.6 |
51.5 |
|
InLegalTrans |
44.3 |
45.6 |
65.5 |
英语到古吉拉特语 |
IndicTrans2 |
27.5 |
31.1 |
55.7 |
|
InLegalTrans |
42.8 |
45.2 |
68.8 |
英语到奥里亚语 |
IndicTrans2 |
06.6 |
12.6 |
37.1 |
|
InLegalTrans |
14.2 |
19.9 |
47.5 |
引用
如果您使用了InLegalTrans翻译模型或MILPaC语料库,请引用以下论文:
@article{mahapatra2024milpacnovelbenchmarkevaluating,
title = {MILPaC: A Novel Benchmark for Evaluating Translation of Legal Text to Indian Languages},
author = {Sayan Mahapatra and Debtanu Datta and Shubham Soni and Adrijit Goswami and Saptarshi Ghosh},
year = {2024},
journal = {ACM Trans. Asian Low-Resour. Lang. Inf. Process.},
publisher = {Association for Computing Machinery},
}
关于我们
我们是来自印度理工学院(IIT)克勒格布尔的自然语言处理(NLP)研究团队。我们的研究兴趣主要集中在机器学习、深度学习和自然语言处理在法律领域的应用,特别关注印度法律场景的挑战与机遇。我们当前和过去的研究项目包括:
- 法律条文识别
- 法律文档的语义分割
- 法律文档的单语(如英语到英语)和跨语言(如英语到印地语)摘要
- 印度法律领域的翻译
- 法院判决预测
- 法律文档匹配
访问我们的公开代码和数据集:Law and AI, IIT Kharagpur。