File size: 4,743 Bytes
cd7d1a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc7becc
cd7d1a5
 
 
 
 
 
dc7becc
cd7d1a5
 
 
dc7becc
 
 
 
 
 
 
 
cd7d1a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
language:
- en
- th
tags:
- translation
license: cc-by-4.0
datasets:
- quickmt/quickmt-train.th-en
model-index:
- name: quickmt-en-th
  results:
  - task:
      name: Translation eng-tha
      type: translation
      args: eng-tha
    dataset:
      name: flores101-devtest
      type: flores_101
      args: eng_Latn tha_Thai devtest
    metrics:
    - name: BLEU
      type: bleu
      value: 9.55
    - name: CHRF
      type: chrf
      value: 54.77
    - name: COMET
      type: comet
      value: 84.52
---


# `quickmt-en-th` Neural Machine Translation Model 

`quickmt-en-th` is a reasonably fast and reasonably accurate neural machine translation model for translation from `en` into `th`.


## Model Information

* Trained using [`eole`](https://github.com/eole-nlp/eole)
* 195M parameter transformer 'big' with 8 encoder layers and 2 decoder layers
* 20k sentencepiece vocabularies
* Exported for fast inference to [CTranslate2](https://github.com/OpenNMT/CTranslate2) format
* Training data: https://huggingface.co/datasets/quickmt/quickmt-train.th-en/tree/main

See the `eole` model configuration in this repository for further details and the `eole-model` for the raw `eole` (pytorch) model.


## Usage with `quickmt`

You must install the Nvidia cuda toolkit first, if you want to do GPU inference.

Next, install the `quickmt` [python library](github.com/quickmt/quickmt). 

```bash
git clone https://github.com/quickmt/quickmt.git
pip install ./quickmt/
```

Finally, use the model in python:

```python
from quickmt import Translator
from huggingface_hub import snapshot_download

# Download Model (if not downloaded already) and return path to local model
# Device is either 'auto', 'cpu' or 'cuda'
t = Translator(
    snapshot_download("quickmt/quickmt-en-th", ignore_patterns="eole-model/*"),
    device="cpu"
)

# Translate - set beam size to 5 for higher quality (but slower speed)
sample_text = 'Dr. Ehud Ur, professor of medicine at Dalhousie University in Halifax, Nova Scotia and chair of the clinical and scientific division of the Canadian Diabetes Association cautioned that the research is still in its early days.'
t(sample_text, beam_size=5)
```

> 'ดร. Ehud Ur, ศาสตราจารย์แพทย์ที่มหาวิทยาลัย Dalhousie ในแฮลิแฟกซ์, โนวาสโกเชียและเก้าอี้ของแผนกทางคลินิกและวิทยาศาสตร์ของสมาคมโรคเบาหวานแคนาดาเตือนว่าการวิจัยยังอยู่ในวันแรก.'

```python
# Get alternative translations by sampling
# You can pass any cTranslate2 `translate_batch` arguments
t([sample_text], sampling_temperature=1.2, beam_size=1, sampling_topk=50, sampling_topp=0.9)
```

> 'ศาสตราจารย์แพทย์ที่ Dalhousie University ในแฮลิแฟกซ์, โนวาสโกเทียและประธานฝ่ายทางคลินิกและวิทยาศาสตร์ของสมาคมโรคเบาหวานแห่งแคนาดาเตือนว่าการวิจัยยังอยู่ในวันแรก.'


The model is in `ctranslate2` format, and the tokenizers are `sentencepiece`, so you can use `ctranslate2` directly instead of through `quickmt`. It is also possible  to get this model to work with e.g. [LibreTranslate](https://libretranslate.com/) which also uses `ctranslate2` and `sentencepiece`.


## Metrics

`bleu` and `chrf2` are calculated with [sacrebleu](https://github.com/mjpost/sacrebleu) on the [Flores200 `devtest` test set](https://huggingface.co/datasets/facebook/flores) ("eng_Latn"->"tha_Thai"). `comet22` with the [`comet`](https://github.com/Unbabel/COMET) library and the [default model](https://huggingface.co/Unbabel/wmt22-comet-da). "Time (s)" is the time in seconds to translate (using `ctranslate2`) the flores-devtest dataset (1012 sentences) on an RTX 4070s GPU with batch size 32 (faster speed is possible with a larger batch size).

|                                  |   bleu |   chrf2 |   comet22 |   Time (s) |
|:---------------------------------|-------:|--------:|----------:|-----------:|
| quickmt/quickmt-en-th            |   9.55 |   54.77 |     84.52 |       1.27 |
| facebook/nllb-200-distilled-600M |   5.8  |   43.33 |     79.26 |      43.09 |
| facebook/nllb-200-distilled-1.3B |   6.29 |   46.91 |     83.25 |      58.57 |
| facebook/m2m100_418M             |   7.29 |   40.07 |     72.95 |      22.94 |
| facebook/m2m100_1.2B             |   8.48 |   45.02 |     78.65 |      42.88 |