This model is a fine-tuned version of
facebook/nllb-200-3.3B on the
EasyProject dataset.
1 from transformers import AutoModelForSeq2SeqLM , AutoTokenizer
2 import torch
3
4 tokenizer = AutoTokenizer . from_pretrained (
5 "facebook/nllb-200-distilled-600M" , src_lang = "eng_Latn" )
6
7 print ( "Loading model" )
8 model = AutoModelForSeq2SeqLM . from_pretrained ( "ychenNLP/nllb-200-3.3b-easyproject" )
9 model . cuda ( )
10
11 input_chunks = [ "A translator always risks inadvertently introducing source-language words, grammar, or syntax into the target-language rendering." ]
12 print ( "Start translation..." )
13 output_result = [ ]
14
15 batch_size = 1
16 for idx in tqdm ( range ( 0 , len ( input_chunks ) , batch_size ) ) :
17 start_idx = idx
18 end_idx = idx + batch_size
19 inputs = tokenizer ( input_chunks [ start_idx : end_idx ] , padding = True , truncation = True , max_length = 128 , return_tensors = "pt" ) . to ( 'cuda' )
20
21 with torch . no_grad ( ) :
22 translated_tokens = model . generate ( ** inputs , forced_bos_token_id = tokenizer . lang_code_to_id [ "zho_Hans" ] ,
23 max_length = 128 , num_beams = 5 , num_return_sequences = 1 , early_stopping = True )
24
25 output = tokenizer . batch_decode ( translated_tokens , skip_special_tokens = True )
26 output_result . extend ( output )
27 print ( output_result )
@inproceedings{chen2023easyproject,
title={Frustratingly Easy Label Projection for Cross-lingual Transfer},
author={Chen, Yang and Jiang, Chao and Ritter, Alan and Xu, Wei},
booktitle={Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Findings)},
year={2023}
}