File size: 1,613 Bytes
9ee9d47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
license: cc-by-nc-4.0
language:
- en
- zh
metrics:
- bleu
pipeline_tag: translation
---

# Model Documentation: English to Simplified Chinese Translation with NLLB-200-distilled-600M

## Model Overview

This document describes a machine translation model fine-tuned from Meta's NLLB-200-distilled-600M for translating from English to Simplified Chinese. The model, hosted at `HackerMonica/nllb-200-distilled-600M-en-zh_CN`, utilizes a distilled version of the NLLB-200 model which has been specifically optimized for translation tasks between the English and Simplified Chinese languages.

## Dependencies

The model requires the `transformers` library by Hugging Face. Ensure that you have the library installed:

```bash
pip install transformers
```

## Setup

Import necessary classes from the `transformers` library:

```python
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
```

Initialize the model and tokenizer:

```python
model = AutoModelForSeq2SeqLM.from_pretrained('HackerMonica/nllb-200-distilled-600M-en-zh_CN')
tokenizer = AutoTokenizer.from_pretrained('HackerMonica/nllb-200-distilled-600M-en-zh_CN')
```

## Usage

To use the model for translating text, use python code below to translate text from English to Simplified Chinese:

```python
def translate(text):
    inputs = tokenizer(text, return_tensors="pt").to("cuda")
    translated_tokens = model.generate(
        **inputs, forced_bos_token_id=tokenizer.lang_code_to_id["zho_Hans"], max_length=300
    )
    translation = tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
    return translation
```