radinplaid commited on
Commit
4d4a7c9
·
verified ·
1 Parent(s): 7d21f10

Upload folder using huggingface_hub

Browse files
.ipynb_checkpoints/README-checkpoint.md ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - da
5
+ tags:
6
+ - translation
7
+ license: cc-by-4.0
8
+ datasets:
9
+ - quickmt/quickmt-train.da-en
10
+ model-index:
11
+ - name: quickmt-da-en
12
+ results:
13
+ - task:
14
+ name: Translation dan-eng
15
+ type: translation
16
+ args: dan-eng
17
+ dataset:
18
+ name: flores101-devtest
19
+ type: flores_101
20
+ args: dan_Latn eng_Latn devtest
21
+ metrics:
22
+ - name: BLEU
23
+ type: bleu
24
+ value: 49.02
25
+ - name: CHRF
26
+ type: chrf
27
+ value: 71.78
28
+ - name: COMET
29
+ type: comet
30
+ value: 90.00
31
+ ---
32
+
33
+
34
+ # `quickmt-da-en` Neural Machine Translation Model
35
+
36
+ `quickmt-da-en` is a reasonably fast and reasonably accurate neural machine translation model for translation from `da` into `en`.
37
+
38
+
39
+ ## Try it on our Huggingface Space
40
+
41
+ Give it a try before downloading here: https://huggingface.co/spaces/quickmt/QuickMT-Demo
42
+
43
+
44
+ ## Model Information
45
+
46
+ * Trained using [`eole`](https://github.com/eole-nlp/eole)
47
+ * 200M parameter transformer 'big' with 8 encoder layers and 2 decoder layers
48
+ * 32k separate Sentencepiece vocabs
49
+ * Exported for fast inference to [CTranslate2](https://github.com/OpenNMT/CTranslate2) format
50
+ * Training data: https://huggingface.co/datasets/quickmt/quickmt-train.da-en/tree/main
51
+
52
+ See the `eole` model configuration in this repository for further details and the `eole-model` for the raw `eole` (pytorch) model.
53
+
54
+
55
+ ## Usage with `quickmt`
56
+
57
+ You must install the Nvidia cuda toolkit first, if you want to do GPU inference.
58
+
59
+ Next, install the `quickmt` python library and download the model:
60
+
61
+ ```bash
62
+ git clone https://github.com/quickmt/quickmt.git
63
+ pip install ./quickmt/
64
+
65
+ quickmt-model-download quickmt/quickmt-da-en ./quickmt-da-en
66
+ ```
67
+
68
+ Finally use the model in python:
69
+
70
+ ```python
71
+ from quickmt import Translator
72
+
73
+ # Auto-detects GPU, set to "cpu" to force CPU inference
74
+ t = Translator("./quickmt-da-en/", device="auto")
75
+
76
+ # Translate - set beam size to 1 for faster speed (but lower quality)
77
+ sample_text = 'Dr. Ehud Ur, professor i medicin på Dalhousie University i Halifax, Nova Scotia, og formand for den kliniske og videnskabelige afdeling af Canadian Diabetes Association, advarede om at forskningen stadig er i dens tidlige stadier.'
78
+
79
+ t(sample_text, beam_size=5)
80
+ ```
81
+
82
+ > 'Dr. Ehud Ur, a professor of medicine at Dalhousie University in Halifax, Nova Scotia, and chairman of the clinical and scientific department of the Canadian Diabetes Association, warned that the research is still in its early stages.'
83
+
84
+ ```python
85
+ # Get alternative translations by sampling
86
+ # You can pass any cTranslate2 `translate_batch` arguments
87
+ t([sample_text], sampling_temperature=1.2, beam_size=1, sampling_topk=50, sampling_topp=0.9)
88
+ ```
89
+
90
+ > 'Dr Ehud Ur, professor of medicine at Dalhousie University in Halifax, Nova Scotia, and chairman of the clinical and scientific branch of the Canadian Diabetes Association, warned that the research is still in its early stages.'
91
+
92
+ 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`. A model in safetensors format to be used with `eole` is also provided.
93
+
94
+
95
+ ## Metrics
96
+
97
+ `bleu` and `chrf2` are calculated with [sacrebleu](https://github.com/mjpost/sacrebleu) on the [Flores200 `devtest` test set](https://huggingface.co/datasets/facebook/flores) ("dan_Latn"->"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 the flores-devtest dataset (1012 sentences) on an RTX 4070s GPU with batch size 32.
98
+
99
+ ## da -> en flores-devtest metrics
100
+
101
+ | | bleu | chrf2 | comet22 | Time (s) |
102
+ |:---------------------------------|-------:|--------:|----------:|-----------:|
103
+ | quickmt/quickmt-da-en | 49.02 | 71.78 | 90 | 1.18 |
104
+ | facebook/nllb-200-distilled-600M | 47.44 | 70.14 | 89.46 | 20.96 |
105
+ | facebook/nllb-200-distilled-1.3B | 49.64 | 71.61 | 90.2 | 36.46 |
106
+ | facebook/m2m100_418M | 39.23 | 65.42 | 85.85 | 17.51 |
107
+ | facebook/m2m100_1.2B | 45.24 | 69.44 | 89 | 33.9 |
108
+
README.md CHANGED
@@ -1,3 +1,108 @@
1
- ---
2
- license: cc-by-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - da
5
+ tags:
6
+ - translation
7
+ license: cc-by-4.0
8
+ datasets:
9
+ - quickmt/quickmt-train.da-en
10
+ model-index:
11
+ - name: quickmt-da-en
12
+ results:
13
+ - task:
14
+ name: Translation dan-eng
15
+ type: translation
16
+ args: dan-eng
17
+ dataset:
18
+ name: flores101-devtest
19
+ type: flores_101
20
+ args: dan_Latn eng_Latn devtest
21
+ metrics:
22
+ - name: BLEU
23
+ type: bleu
24
+ value: 49.02
25
+ - name: CHRF
26
+ type: chrf
27
+ value: 71.78
28
+ - name: COMET
29
+ type: comet
30
+ value: 90.00
31
+ ---
32
+
33
+
34
+ # `quickmt-da-en` Neural Machine Translation Model
35
+
36
+ `quickmt-da-en` is a reasonably fast and reasonably accurate neural machine translation model for translation from `da` into `en`.
37
+
38
+
39
+ ## Try it on our Huggingface Space
40
+
41
+ Give it a try before downloading here: https://huggingface.co/spaces/quickmt/QuickMT-Demo
42
+
43
+
44
+ ## Model Information
45
+
46
+ * Trained using [`eole`](https://github.com/eole-nlp/eole)
47
+ * 200M parameter transformer 'big' with 8 encoder layers and 2 decoder layers
48
+ * 32k separate Sentencepiece vocabs
49
+ * Exported for fast inference to [CTranslate2](https://github.com/OpenNMT/CTranslate2) format
50
+ * Training data: https://huggingface.co/datasets/quickmt/quickmt-train.da-en/tree/main
51
+
52
+ See the `eole` model configuration in this repository for further details and the `eole-model` for the raw `eole` (pytorch) model.
53
+
54
+
55
+ ## Usage with `quickmt`
56
+
57
+ You must install the Nvidia cuda toolkit first, if you want to do GPU inference.
58
+
59
+ Next, install the `quickmt` python library and download the model:
60
+
61
+ ```bash
62
+ git clone https://github.com/quickmt/quickmt.git
63
+ pip install ./quickmt/
64
+
65
+ quickmt-model-download quickmt/quickmt-da-en ./quickmt-da-en
66
+ ```
67
+
68
+ Finally use the model in python:
69
+
70
+ ```python
71
+ from quickmt import Translator
72
+
73
+ # Auto-detects GPU, set to "cpu" to force CPU inference
74
+ t = Translator("./quickmt-da-en/", device="auto")
75
+
76
+ # Translate - set beam size to 1 for faster speed (but lower quality)
77
+ sample_text = 'Dr. Ehud Ur, professor i medicin på Dalhousie University i Halifax, Nova Scotia, og formand for den kliniske og videnskabelige afdeling af Canadian Diabetes Association, advarede om at forskningen stadig er i dens tidlige stadier.'
78
+
79
+ t(sample_text, beam_size=5)
80
+ ```
81
+
82
+ > 'Dr. Ehud Ur, a professor of medicine at Dalhousie University in Halifax, Nova Scotia, and chairman of the clinical and scientific department of the Canadian Diabetes Association, warned that the research is still in its early stages.'
83
+
84
+ ```python
85
+ # Get alternative translations by sampling
86
+ # You can pass any cTranslate2 `translate_batch` arguments
87
+ t([sample_text], sampling_temperature=1.2, beam_size=1, sampling_topk=50, sampling_topp=0.9)
88
+ ```
89
+
90
+ > 'Dr Ehud Ur, professor of medicine at Dalhousie University in Halifax, Nova Scotia, and chairman of the clinical and scientific branch of the Canadian Diabetes Association, warned that the research is still in its early stages.'
91
+
92
+ 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`. A model in safetensors format to be used with `eole` is also provided.
93
+
94
+
95
+ ## Metrics
96
+
97
+ `bleu` and `chrf2` are calculated with [sacrebleu](https://github.com/mjpost/sacrebleu) on the [Flores200 `devtest` test set](https://huggingface.co/datasets/facebook/flores) ("dan_Latn"->"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 the flores-devtest dataset (1012 sentences) on an RTX 4070s GPU with batch size 32.
98
+
99
+ ## da -> en flores-devtest metrics
100
+
101
+ | | bleu | chrf2 | comet22 | Time (s) |
102
+ |:---------------------------------|-------:|--------:|----------:|-----------:|
103
+ | quickmt/quickmt-da-en | 49.02 | 71.78 | 90 | 1.18 |
104
+ | facebook/nllb-200-distilled-600M | 47.44 | 70.14 | 89.46 | 20.96 |
105
+ | facebook/nllb-200-distilled-1.3B | 49.64 | 71.61 | 90.2 | 36.46 |
106
+ | facebook/m2m100_418M | 39.23 | 65.42 | 85.85 | 17.51 |
107
+ | facebook/m2m100_1.2B | 45.24 | 69.44 | 89 | 33.9 |
108
+
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,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: da.eole.vocab
12
+ tgt_vocab: en.eole.vocab
13
+ src_vocab_size: 32000
14
+ tgt_vocab_size: 32000
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.da-en/da
22
+ # path_tgt: hf://quickmt/quickmt-train.da-en/en
23
+ # path_sco: hf://quickmt/quickmt-train.da-en/sco
24
+ path_src: train.da
25
+ path_tgt: train.en
26
+ valid:
27
+ path_src: valid.da
28
+ path_tgt: valid.en
29
+
30
+ transforms: [sentencepiece, filtertoolong]
31
+ transforms_configs:
32
+ sentencepiece:
33
+ src_subword_model: "da.spm.model"
34
+ tgt_subword_model: "en.spm.model"
35
+ filtertoolong:
36
+ src_seq_length: 256
37
+ tgt_seq_length: 256
38
+
39
+ training:
40
+ # Run configuration
41
+ model_path: quickmt-da-en-eole-model
42
+ #train_from: model
43
+ keep_checkpoint: 4
44
+ train_steps: 100000
45
+ save_checkpoint_steps: 5000
46
+ valid_steps: 5000
47
+
48
+ # Train on a single GPU
49
+ world_size: 1
50
+ gpu_ranks: [0]
51
+
52
+ # Batching 10240
53
+ batch_type: "tokens"
54
+ batch_size: 6000
55
+ valid_batch_size: 2048
56
+ batch_size_multiple: 8
57
+ accum_count: [20]
58
+ accum_steps: [0]
59
+
60
+ # Optimizer & Compute
61
+ compute_dtype: "fp16"
62
+ optim: "adamw"
63
+ #use_amp: False
64
+ learning_rate: 2.0
65
+ warmup_steps: 2000
66
+ decay_method: "noam"
67
+ adam_beta2: 0.998
68
+
69
+ # Data loading
70
+ bucket_size: 128000
71
+ num_workers: 4
72
+ prefetch_factor: 32
73
+
74
+ # Hyperparams
75
+ dropout_steps: [0]
76
+ dropout: [0.1]
77
+ attention_dropout: [0.1]
78
+ max_grad_norm: 0
79
+ label_smoothing: 0.1
80
+ average_decay: 0.0001
81
+ param_init_method: xavier_uniform
82
+ normalization: "tokens"
83
+
84
+ model:
85
+ architecture: "transformer"
86
+ share_embeddings: false
87
+ share_decoder_embeddings: true
88
+ hidden_size: 1024
89
+ encoder:
90
+ layers: 8
91
+ decoder:
92
+ layers: 2
93
+ heads: 8
94
+ transformer_ff: 4096
95
+ embeddings:
96
+ word_vec_size: 1024
97
+ position_encoding_type: "SinusoidalInterleaved"
98
+
eole-model/config.json ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "tgt_vocab_size": 32000,
3
+ "share_vocab": false,
4
+ "tensorboard": true,
5
+ "n_sample": 0,
6
+ "src_vocab_size": 32000,
7
+ "src_vocab": "da.eole.vocab",
8
+ "transforms": [
9
+ "sentencepiece",
10
+ "filtertoolong"
11
+ ],
12
+ "report_every": 100,
13
+ "valid_metrics": [
14
+ "BLEU"
15
+ ],
16
+ "tensorboard_log_dir_dated": "tensorboard/Oct-28_23-01-02",
17
+ "save_data": "data",
18
+ "overwrite": true,
19
+ "tensorboard_log_dir": "tensorboard",
20
+ "tgt_vocab": "en.eole.vocab",
21
+ "seed": 1234,
22
+ "vocab_size_multiple": 8,
23
+ "training": {
24
+ "param_init_method": "xavier_uniform",
25
+ "train_steps": 100000,
26
+ "attention_dropout": [
27
+ 0.1
28
+ ],
29
+ "normalization": "tokens",
30
+ "model_path": "quickmt-da-en-eole-model",
31
+ "average_decay": 0.0001,
32
+ "num_workers": 0,
33
+ "dropout_steps": [
34
+ 0
35
+ ],
36
+ "prefetch_factor": 32,
37
+ "learning_rate": 2.0,
38
+ "compute_dtype": "torch.float16",
39
+ "valid_steps": 5000,
40
+ "warmup_steps": 2000,
41
+ "adam_beta2": 0.998,
42
+ "accum_count": [
43
+ 20
44
+ ],
45
+ "batch_type": "tokens",
46
+ "batch_size_multiple": 8,
47
+ "bucket_size": 128000,
48
+ "save_checkpoint_steps": 5000,
49
+ "keep_checkpoint": 4,
50
+ "batch_size": 6000,
51
+ "dropout": [
52
+ 0.1
53
+ ],
54
+ "optim": "adamw",
55
+ "accum_steps": [
56
+ 0
57
+ ],
58
+ "valid_batch_size": 2048,
59
+ "max_grad_norm": 0.0,
60
+ "gpu_ranks": [
61
+ 0
62
+ ],
63
+ "label_smoothing": 0.1,
64
+ "decay_method": "noam",
65
+ "world_size": 1
66
+ },
67
+ "model": {
68
+ "position_encoding_type": "SinusoidalInterleaved",
69
+ "architecture": "transformer",
70
+ "share_embeddings": false,
71
+ "heads": 8,
72
+ "hidden_size": 1024,
73
+ "transformer_ff": 4096,
74
+ "share_decoder_embeddings": true,
75
+ "embeddings": {
76
+ "position_encoding_type": "SinusoidalInterleaved",
77
+ "word_vec_size": 1024,
78
+ "tgt_word_vec_size": 1024,
79
+ "src_word_vec_size": 1024
80
+ },
81
+ "decoder": {
82
+ "position_encoding_type": "SinusoidalInterleaved",
83
+ "tgt_word_vec_size": 1024,
84
+ "heads": 8,
85
+ "layers": 2,
86
+ "n_positions": null,
87
+ "hidden_size": 1024,
88
+ "decoder_type": "transformer",
89
+ "transformer_ff": 4096
90
+ },
91
+ "encoder": {
92
+ "position_encoding_type": "SinusoidalInterleaved",
93
+ "src_word_vec_size": 1024,
94
+ "heads": 8,
95
+ "encoder_type": "transformer",
96
+ "layers": 8,
97
+ "n_positions": null,
98
+ "hidden_size": 1024,
99
+ "transformer_ff": 4096
100
+ }
101
+ },
102
+ "transforms_configs": {
103
+ "sentencepiece": {
104
+ "tgt_subword_model": "${MODEL_PATH}/en.spm.model",
105
+ "src_subword_model": "${MODEL_PATH}/da.spm.model"
106
+ },
107
+ "filtertoolong": {
108
+ "tgt_seq_length": 256,
109
+ "src_seq_length": 256
110
+ }
111
+ },
112
+ "data": {
113
+ "corpus_1": {
114
+ "path_align": null,
115
+ "path_tgt": "train.en",
116
+ "path_src": "train.da",
117
+ "transforms": [
118
+ "sentencepiece",
119
+ "filtertoolong"
120
+ ]
121
+ },
122
+ "valid": {
123
+ "path_align": null,
124
+ "path_tgt": "valid.en",
125
+ "path_src": "valid.da",
126
+ "transforms": [
127
+ "sentencepiece",
128
+ "filtertoolong"
129
+ ]
130
+ }
131
+ }
132
+ }
eole-model/da.spm.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:688ecf3cf51d2cf7497720ba36e5f3c6bdfea75630c2c2c8afcf8a0de3580d06
3
+ size 814697
eole-model/en.spm.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8eda8069d07624408f632a155bbfb6db9794b8bb7bdbc9040c8ec16d499b6ef2
3
+ size 800426
eole-model/model.00.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6acf5dd3d4a3f8efe9f32ffa635944452f9c3361fe63de85e33453d4e076af03
3
+ size 840314816
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:b8e3d7ae48cd5fc340ae381477206a6fcefc1f2329364d1b22d108373b903e6d
3
+ size 409915789
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:688ecf3cf51d2cf7497720ba36e5f3c6bdfea75630c2c2c8afcf8a0de3580d06
3
+ size 814697
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:8eda8069d07624408f632a155bbfb6db9794b8bb7bdbc9040c8ec16d499b6ef2
3
+ size 800426