radinplaid commited on
Commit
955f9e6
·
verified ·
1 Parent(s): b4ae4f1

Upload folder using huggingface_hub

Browse files
.ipynb_checkpoints/README-checkpoint.md ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - ja
5
+ tags:
6
+ - translation
7
+ license: cc-by-4.0
8
+ datasets:
9
+ - quickmt/quickmt-train.ja-en
10
+ model-index:
11
+ - name: quickmt-ja-en
12
+ results:
13
+ - task:
14
+ name: Translation jpn-eng
15
+ type: translation
16
+ args: jpn-eng
17
+ dataset:
18
+ name: flores101-devtest
19
+ type: flores_101
20
+ args: jpn_Japn eng_Latn devtest
21
+ metrics:
22
+ - name: CHRF
23
+ type: chrf
24
+ value: 57.06
25
+ - name: BLEU
26
+ type: bleu
27
+ value: 27.91
28
+ - name: COMET
29
+ type: comet
30
+ value: 87.29
31
+ ---
32
+
33
+
34
+ # `quickmt-ja-en` Neural Machine Translation Model
35
+
36
+ `quickmt-ja-en` is a reasonably fast and reasonably accurate neural machine translation model for translation from `ja` into `en`.
37
+
38
+
39
+ ## Model Information
40
+
41
+ * Trained using [`eole`](https://github.com/eole-nlp/eole)
42
+ * 185M parameter transformer 'big' with 8 encoder layers and 2 decoder layers
43
+ * 20k sentencepiece vocabularies
44
+ * Exported for fast inference to [CTranslate2](https://github.com/OpenNMT/CTranslate2) format
45
+ * Training data: https://huggingface.co/datasets/quickmt/quickmt-train.ja-en/tree/main
46
+
47
+ See the `eole` model configuration in this repository for further details and the `eole-model` for the raw `eole` (pytorch) model.
48
+
49
+
50
+ ## Usage with `quickmt`
51
+
52
+ You must install the Nvidia cuda toolkit first, if you want to do GPU inference.
53
+
54
+ Next, install the `quickmt` python library and download the model:
55
+
56
+ ```bash
57
+ git clone https://github.com/quickmt/quickmt.git
58
+ pip install ./quickmt/
59
+
60
+ quickmt-model-download quickmt/quickmt-ja-en ./quickmt-ja-en
61
+ ```
62
+
63
+ Finally use the model in python:
64
+
65
+ ```python
66
+ from quickmt import Translator
67
+
68
+ # Auto-detects GPU, set to "cpu" to force CPU inference
69
+ t = Translator("./quickmt-ja-en/", device="auto")
70
+
71
+ # Translate - set beam size to 5 for higher quality (but slower speed)
72
+ sample_text = 'ノバスコシア州ハリファックスにあるダルハウジー大学医学部教授でカナダ糖尿病協会の臨床・科学部門の責任者を務めるエフード・ウル博士は、この研究はまだ初期段階にあるとして注意を促しました。'
73
+ t(sample_text, beam_size=5)
74
+
75
+ > 'Dr. Ehud Ulu, a professor of medicine at Dalhousie University in Halifax, Nova Scotia and head of the clinical and scientific division of the Canadian Diabetes Association, cautioned that the study is still in its early stages.'
76
+
77
+ # Get alternative translations by sampling
78
+ # You can pass any cTranslate2 `translate_batch` arguments
79
+ t([sample_text], sampling_temperature=1.2, beam_size=1, sampling_topk=50, sampling_topp=0.9)
80
+
81
+ > 'Dr Ehud Ul, professor of medicine at the University of Dalhousie’s Halifax, Nova Scotia and head of the clinical and scientific division of the Canadian Diabetes Society, noted the study is in its early stages.'
82
+ ```
83
+
84
+ 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`.
85
+
86
+
87
+ ## Metrics
88
+
89
+ `bleu` and `chrf2` are calculated with [sacrebleu](https://github.com/mjpost/sacrebleu) on the [Flores200 `devtest` test set](https://huggingface.co/datasets/facebook/flores) ("jpn_Jpan"->"eng_Latn"). `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 using a large batch size).
90
+
91
+ | | bleu | chrf2 | comet22 | Time (s) |
92
+ |:---------------------------------|-------:|--------:|----------:|-----------:|
93
+ | quickmt/quickmt-ja-en | 27.91 | 57.06 | 87.29 | 1.00 |
94
+ | Helsink-NLP/opus-mt-ja-en | 19.22 | 49.15 | 82.64 | 3.54 |
95
+ | facebook/nllb-200-distilled-600M | 24.05 | 53.39 | 85.84 | 22.5 |
96
+ | facebook/nllb-200-distilled-1.3B | 28.4 | 56.96 | 87.47 | 37.15 |
97
+ | facebook/m2m100_418M | 18.82 | 49.55 | 82.59 | 18.27 |
98
+ | facebook/m2m100_1.2B | 23.32 | 53.46 | 85.43 | 35.44 |
99
+
100
+ `quickmt-ja-en` is the fastest and nearly as high-quality as facebook/nllb-200-distilled-1.3B.
README.md CHANGED
@@ -1,3 +1,100 @@
1
- ---
2
- license: cc-by-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - ja
5
+ tags:
6
+ - translation
7
+ license: cc-by-4.0
8
+ datasets:
9
+ - quickmt/quickmt-train.ja-en
10
+ model-index:
11
+ - name: quickmt-ja-en
12
+ results:
13
+ - task:
14
+ name: Translation jpn-eng
15
+ type: translation
16
+ args: jpn-eng
17
+ dataset:
18
+ name: flores101-devtest
19
+ type: flores_101
20
+ args: jpn_Japn eng_Latn devtest
21
+ metrics:
22
+ - name: CHRF
23
+ type: chrf
24
+ value: 57.06
25
+ - name: BLEU
26
+ type: bleu
27
+ value: 27.91
28
+ - name: COMET
29
+ type: comet
30
+ value: 87.29
31
+ ---
32
+
33
+
34
+ # `quickmt-ja-en` Neural Machine Translation Model
35
+
36
+ `quickmt-ja-en` is a reasonably fast and reasonably accurate neural machine translation model for translation from `ja` into `en`.
37
+
38
+
39
+ ## Model Information
40
+
41
+ * Trained using [`eole`](https://github.com/eole-nlp/eole)
42
+ * 185M parameter transformer 'big' with 8 encoder layers and 2 decoder layers
43
+ * 20k sentencepiece vocabularies
44
+ * Exported for fast inference to [CTranslate2](https://github.com/OpenNMT/CTranslate2) format
45
+ * Training data: https://huggingface.co/datasets/quickmt/quickmt-train.ja-en/tree/main
46
+
47
+ See the `eole` model configuration in this repository for further details and the `eole-model` for the raw `eole` (pytorch) model.
48
+
49
+
50
+ ## Usage with `quickmt`
51
+
52
+ You must install the Nvidia cuda toolkit first, if you want to do GPU inference.
53
+
54
+ Next, install the `quickmt` python library and download the model:
55
+
56
+ ```bash
57
+ git clone https://github.com/quickmt/quickmt.git
58
+ pip install ./quickmt/
59
+
60
+ quickmt-model-download quickmt/quickmt-ja-en ./quickmt-ja-en
61
+ ```
62
+
63
+ Finally use the model in python:
64
+
65
+ ```python
66
+ from quickmt import Translator
67
+
68
+ # Auto-detects GPU, set to "cpu" to force CPU inference
69
+ t = Translator("./quickmt-ja-en/", device="auto")
70
+
71
+ # Translate - set beam size to 5 for higher quality (but slower speed)
72
+ sample_text = 'ノバスコシア州ハリファックスにあるダルハウジー大学医学部教授でカナダ糖尿病協会の臨床・科学部門の責任者を務めるエフード・ウル博士は、この研究はまだ初期段階にあるとして注意を促しました。'
73
+ t(sample_text, beam_size=5)
74
+
75
+ > 'Dr. Ehud Ulu, a professor of medicine at Dalhousie University in Halifax, Nova Scotia and head of the clinical and scientific division of the Canadian Diabetes Association, cautioned that the study is still in its early stages.'
76
+
77
+ # Get alternative translations by sampling
78
+ # You can pass any cTranslate2 `translate_batch` arguments
79
+ t([sample_text], sampling_temperature=1.2, beam_size=1, sampling_topk=50, sampling_topp=0.9)
80
+
81
+ > 'Dr Ehud Ul, professor of medicine at the University of Dalhousie’s Halifax, Nova Scotia and head of the clinical and scientific division of the Canadian Diabetes Society, noted the study is in its early stages.'
82
+ ```
83
+
84
+ 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`.
85
+
86
+
87
+ ## Metrics
88
+
89
+ `bleu` and `chrf2` are calculated with [sacrebleu](https://github.com/mjpost/sacrebleu) on the [Flores200 `devtest` test set](https://huggingface.co/datasets/facebook/flores) ("jpn_Jpan"->"eng_Latn"). `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 using a large batch size).
90
+
91
+ | | bleu | chrf2 | comet22 | Time (s) |
92
+ |:---------------------------------|-------:|--------:|----------:|-----------:|
93
+ | quickmt/quickmt-ja-en | 27.91 | 57.06 | 87.29 | 1.00 |
94
+ | Helsink-NLP/opus-mt-ja-en | 19.22 | 49.15 | 82.64 | 3.54 |
95
+ | facebook/nllb-200-distilled-600M | 24.05 | 53.39 | 85.84 | 22.5 |
96
+ | facebook/nllb-200-distilled-1.3B | 28.4 | 56.96 | 87.47 | 37.15 |
97
+ | facebook/m2m100_418M | 18.82 | 49.55 | 82.59 | 18.27 |
98
+ | facebook/m2m100_1.2B | 23.32 | 53.46 | 85.43 | 35.44 |
99
+
100
+ `quickmt-ja-en` is the fastest and nearly as high-quality as facebook/nllb-200-distilled-1.3B.
config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_source_bos": false,
3
+ "add_source_eos": false,
4
+ "bos_token": "<s>",
5
+ "decoder_start_token": "<s>",
6
+ "eos_token": "</s>",
7
+ "layer_norm_epsilon": 1e-06,
8
+ "multi_query_attention": false,
9
+ "unk_token": "<unk>"
10
+ }
eole-config.yaml ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## IO
2
+ save_data: data
3
+ overwrite: True
4
+ seed: 1234
5
+ report_every: 100
6
+ valid_metrics: ["BLEU"]
7
+ tensorboard: true
8
+ tensorboard_log_dir: tensorboard
9
+
10
+ ### Vocab
11
+ src_vocab: ja.eole.vocab
12
+ tgt_vocab: en.eole.vocab
13
+ src_vocab_size: 20000
14
+ tgt_vocab_size: 20000
15
+ vocab_size_multiple: 8
16
+ share_vocab: false
17
+ n_sample: 0
18
+
19
+ data:
20
+ corpus_1:
21
+ path_src: hf://quickmt/quickmt-train.ja-en/ja
22
+ path_tgt: hf://quickmt/quickmt-train.ja-en/en
23
+ path_sco: hf://quickmt/quickmt-train.ja-en/sco
24
+ valid:
25
+ path_src: valid.ja
26
+ path_tgt: valid.en
27
+
28
+ transforms: [sentencepiece, filtertoolong]
29
+ transforms_configs:
30
+ sentencepiece:
31
+ src_subword_model: "ja.spm.model"
32
+ tgt_subword_model: "en.spm.model"
33
+ filtertoolong:
34
+ src_seq_length: 256
35
+ tgt_seq_length: 256
36
+
37
+ training:
38
+ # Run configuration
39
+ model_path: eole-model
40
+ keep_checkpoint: 4
41
+ train_steps: 108000
42
+ save_checkpoint_steps: 2000
43
+ valid_steps: 2000
44
+
45
+ # Train on a single GPU
46
+ world_size: 1
47
+ gpu_ranks: [0]
48
+
49
+ # Batching 10240
50
+ batch_type: "tokens"
51
+ batch_size: 8000
52
+ valid_batch_size: 4096
53
+ batch_size_multiple: 8
54
+ accum_count: [8]
55
+ accum_steps: [0]
56
+
57
+ # Optimizer & Compute
58
+ compute_dtype: "fp16"
59
+ optim: "adamw"
60
+ learning_rate: 2.0
61
+ warmup_steps: 4000
62
+ decay_method: "noam"
63
+ adam_beta2: 0.998
64
+
65
+ # Data loading
66
+ bucket_size: 128000
67
+ num_workers: 4
68
+ prefetch_factor: 32
69
+
70
+ # Hyperparams
71
+ dropout_steps: [0]
72
+ dropout: [0.1]
73
+ attention_dropout: [0.1]
74
+ max_grad_norm: 0
75
+ label_smoothing: 0.1
76
+ average_decay: 0.0001
77
+ param_init_method: xavier_uniform
78
+ normalization: "tokens"
79
+
80
+ model:
81
+ architecture: "transformer"
82
+ share_embeddings: false
83
+ share_decoder_embeddings: false
84
+ hidden_size: 1024
85
+ encoder:
86
+ layers: 8
87
+ decoder:
88
+ layers: 2
89
+ heads: 8
90
+ transformer_ff: 4096
91
+ embeddings:
92
+ word_vec_size: 1024
93
+ position_encoding_type: "SinusoidalInterleaved"
94
+
eole-model/config.json ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "n_sample": 0,
3
+ "overwrite": true,
4
+ "save_data": "data",
5
+ "tgt_vocab_size": 20000,
6
+ "seed": 1234,
7
+ "share_vocab": false,
8
+ "tensorboard_log_dir": "tensorboard",
9
+ "report_every": 100,
10
+ "tensorboard": true,
11
+ "tgt_vocab": "en.eole.vocab",
12
+ "vocab_size_multiple": 8,
13
+ "src_vocab": "ja.eole.vocab",
14
+ "src_vocab_size": 20000,
15
+ "tensorboard_log_dir_dated": "tensorboard/Apr-15_05-55-59",
16
+ "transforms": [
17
+ "sentencepiece",
18
+ "filtertoolong"
19
+ ],
20
+ "valid_metrics": [
21
+ "BLEU"
22
+ ],
23
+ "training": {
24
+ "save_checkpoint_steps": 2000,
25
+ "max_grad_norm": 0.0,
26
+ "dropout": [
27
+ 0.1
28
+ ],
29
+ "dropout_steps": [
30
+ 0
31
+ ],
32
+ "label_smoothing": 0.1,
33
+ "keep_checkpoint": 4,
34
+ "prefetch_factor": 32,
35
+ "valid_steps": 2000,
36
+ "optim": "adamw",
37
+ "gpu_ranks": [
38
+ 0
39
+ ],
40
+ "bucket_size": 128000,
41
+ "batch_size": 8000,
42
+ "average_decay": 0.0001,
43
+ "compute_dtype": "torch.float16",
44
+ "param_init_method": "xavier_uniform",
45
+ "decay_method": "noam",
46
+ "num_workers": 0,
47
+ "warmup_steps": 4000,
48
+ "attention_dropout": [
49
+ 0.1
50
+ ],
51
+ "model_path": "quickmt-ja-en-eole-model",
52
+ "accum_count": [
53
+ 8
54
+ ],
55
+ "batch_size_multiple": 8,
56
+ "train_steps": 200000,
57
+ "accum_steps": [
58
+ 0
59
+ ],
60
+ "adam_beta2": 0.998,
61
+ "learning_rate": 2.0,
62
+ "normalization": "tokens",
63
+ "valid_batch_size": 4096,
64
+ "world_size": 1,
65
+ "batch_type": "tokens"
66
+ },
67
+ "model": {
68
+ "transformer_ff": 4096,
69
+ "share_decoder_embeddings": false,
70
+ "architecture": "transformer",
71
+ "position_encoding_type": "SinusoidalInterleaved",
72
+ "share_embeddings": false,
73
+ "heads": 8,
74
+ "hidden_size": 1024,
75
+ "encoder": {
76
+ "layers": 8,
77
+ "transformer_ff": 4096,
78
+ "position_encoding_type": "SinusoidalInterleaved",
79
+ "src_word_vec_size": 1024,
80
+ "n_positions": null,
81
+ "encoder_type": "transformer",
82
+ "heads": 8,
83
+ "hidden_size": 1024
84
+ },
85
+ "embeddings": {
86
+ "tgt_word_vec_size": 1024,
87
+ "position_encoding_type": "SinusoidalInterleaved",
88
+ "word_vec_size": 1024,
89
+ "src_word_vec_size": 1024
90
+ },
91
+ "decoder": {
92
+ "layers": 2,
93
+ "transformer_ff": 4096,
94
+ "position_encoding_type": "SinusoidalInterleaved",
95
+ "n_positions": null,
96
+ "decoder_type": "transformer",
97
+ "tgt_word_vec_size": 1024,
98
+ "heads": 8,
99
+ "hidden_size": 1024
100
+ }
101
+ },
102
+ "transforms_configs": {
103
+ "sentencepiece": {
104
+ "src_subword_model": "${MODEL_PATH}/ja.spm.model",
105
+ "tgt_subword_model": "${MODEL_PATH}/en.spm.model"
106
+ },
107
+ "filtertoolong": {
108
+ "tgt_seq_length": 256,
109
+ "src_seq_length": 256
110
+ }
111
+ },
112
+ "data": {
113
+ "corpus_1": {
114
+ "path_tgt": "en.txt",
115
+ "path_align": null,
116
+ "transforms": [
117
+ "sentencepiece",
118
+ "filtertoolong"
119
+ ],
120
+ "path_src": "ja.txt"
121
+ },
122
+ "valid": {
123
+ "path_tgt": "valid.en",
124
+ "path_align": null,
125
+ "transforms": [
126
+ "sentencepiece",
127
+ "filtertoolong"
128
+ ],
129
+ "path_src": "valid.ja"
130
+ }
131
+ }
132
+ }
eole-model/en.spm.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:01dc857df9df5987bec61812d1fbc2e78ad530346c09fe3ffaf27184358ab8fd
3
+ size 583983
eole-model/ja.spm.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cbd449d7e92d850f6d36efeafb40cea3a8468f55db0ca751ee4ece0ceb70d19b
3
+ size 583133
eole-model/model.00.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f226e709170b27c12510b5b186f305fcc9ddb3dbf4ae3ea1066f8ff4632f7de1
3
+ size 823882912
eole-model/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f9906f44709dab21e2bd168cb19e4379326d4b8e92513dc9b4e5ff4af6cf323
3
+ size 401699775
source_vocabulary.json ADDED
The diff for this file is too large to render. See raw diff
 
src.spm.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cbd449d7e92d850f6d36efeafb40cea3a8468f55db0ca751ee4ece0ceb70d19b
3
+ size 583133
target_vocabulary.json ADDED
The diff for this file is too large to render. See raw diff
 
tgt.spm.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:01dc857df9df5987bec61812d1fbc2e78ad530346c09fe3ffaf27184358ab8fd
3
+ size 583983