Spaces:
No application file
No application file
Commit
·
cf68301
1
Parent(s):
8cb4f3b
'a'
Browse files
README.md
CHANGED
@@ -1,156 +1,13 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
# Quickstart
|
15 |
-
|
16 |
-
```
|
17 |
-
|
18 |
-
## Bước 1: Chuẩn bị dữ liệu
|
19 |
-
|
20 |
-
Ví dụ thực nghiệm dựa trên cặp dữ liệu Anh-Việt nguồn từ iwslt với 133k cặp câu:
|
21 |
-
|
22 |
-
```bash
|
23 |
-
cd data/iwslt_en_vi
|
24 |
-
```
|
25 |
-
|
26 |
-
Dữ liệu bao gồm câu nguồn (`src`) và câu đích (`tgt`) dữ liệu đã được tách từ:
|
27 |
-
|
28 |
-
* `train.en`
|
29 |
-
* `train.vi`
|
30 |
-
* `tst2012.en`
|
31 |
-
* `tst2012.vi`
|
32 |
-
|
33 |
-
| Data set | Sentences | Download |
|
34 |
-
| :---------: | :--------: | :-------------------------------------------: |
|
35 |
-
| Training | 133,317 | via GitHub or located in data/train-en-vi.tgz |
|
36 |
-
| Development | 1,553 | via GitHub or located in data/train-en-vi.tgz |
|
37 |
-
| Test | 1,268 | via GitHub or located in data/train-en-vi.tgz |
|
38 |
-
|
39 |
-
|
40 |
-
**Note**:
|
41 |
-
Lưu ý:
|
42 |
-
- Dữ liệu trước khi đưa vào huấn luyện cần phải được tokenize.
|
43 |
-
- $CONFIG là đường dẫn tới vị trí chứa file config
|
44 |
-
|
45 |
-
Tách dữ liệu dev để tính toán hội tụ trong quá trình huấn luyện, thường không lớn hơn 5k câu.
|
46 |
-
|
47 |
-
```text
|
48 |
-
$ head -n 5 data/iwslt_en_vi/train.en
|
49 |
-
Rachel Pike : The science behind a climate headline
|
50 |
-
In 4 minutes , atmospheric chemist Rachel Pike provides a glimpse of the massive scientific effort behind the bold headlines on climate change , with her team -- one of thousands who contributed -- taking a risky flight over the rainforest in pursuit of data on a key molecule .
|
51 |
-
I 'd like to talk to you today about the scale of the scientific effort that goes into making the headlines you see in the paper .
|
52 |
-
Headlines that look like this when they have to do with climate change , and headlines that look like this when they have to do with air quality or smog .
|
53 |
-
They are both two branches of the same field of atmospheric science .
|
54 |
-
```
|
55 |
-
|
56 |
-
## Bước 2: Huấn luyện mô hình
|
57 |
-
|
58 |
-
Để huấn luyện một mô hình mới **hãy chỉnh sửa file YAML config**:
|
59 |
-
Cần phải sửa lại file config en_vi.yml chỉnh siêu tham số và đường dẫn tới dữ liệu huấn luyện:
|
60 |
-
|
61 |
-
```yaml
|
62 |
-
# data location and config section
|
63 |
-
data:
|
64 |
-
train_data_location: data/iwslt_en_vi/train
|
65 |
-
eval_data_location: data/iwslt_en_vi/tst2013
|
66 |
-
src_lang: .en
|
67 |
-
trg_lang: .vi
|
68 |
-
log_file_models: 'model.log'
|
69 |
-
lowercase: false
|
70 |
-
build_vocab_kwargs: # additional arguments for build_vocab. See torchtext.vocab.Vocab for mode details
|
71 |
-
# max_size: 50000
|
72 |
-
min_freq: 5
|
73 |
-
# model parameters section
|
74 |
-
device: cuda
|
75 |
-
d_model: 512
|
76 |
-
n_layers: 6
|
77 |
-
heads: 8
|
78 |
-
# inference section
|
79 |
-
eval_batch_size: 8
|
80 |
-
decode_strategy: BeamSearch
|
81 |
-
decode_strategy_kwargs:
|
82 |
-
beam_size: 5 # beam search size
|
83 |
-
length_normalize: 0.6 # recalculate beam position by length. Currently only work in default BeamSearch
|
84 |
-
replace_unk: # tuple of layer/head attention to replace unknown words
|
85 |
-
- 0 # layer
|
86 |
-
- 0 # head
|
87 |
-
input_max_length: 200 # input longer than this value will be trimmed in inference. Note that this values are to be used during cached PE, hence, validation set with more than this much tokens will call a warning for the trimming.
|
88 |
-
max_length: 160 # only perform up to this much timestep during inference
|
89 |
-
train_max_length: 50 # training samples with this much length in src/trg will be discarded
|
90 |
-
# optimizer and learning arguments section
|
91 |
-
lr: 0.2
|
92 |
-
optimizer: AdaBelief
|
93 |
-
optimizer_params:
|
94 |
-
betas:
|
95 |
-
- 0.9 # beta1
|
96 |
-
- 0.98 # beta2
|
97 |
-
eps: !!float 1e-9
|
98 |
-
n_warmup_steps: 4000
|
99 |
-
label_smoothing: 0.1
|
100 |
-
dropout: 0.1
|
101 |
-
# training config, evaluation, save & load section
|
102 |
-
batch_size: 64
|
103 |
-
epochs: 20
|
104 |
-
printevery: 200
|
105 |
-
save_checkpoint_epochs: 1
|
106 |
-
maximum_saved_model_eval: 5
|
107 |
-
maximum_saved_model_train: 5
|
108 |
-
|
109 |
-
```
|
110 |
-
|
111 |
-
Sau đó có thể chạy với câu lệnh:
|
112 |
-
|
113 |
-
```bash
|
114 |
-
python -m bin.main train --model Transformer --model_dir $MODEL/en-vi.model --config $CONFIG/en_vi.yml
|
115 |
-
```
|
116 |
-
|
117 |
-
**Note**:
|
118 |
-
Ở đây:
|
119 |
-
- $MODEL là dường dẫn tới vị trí lưu mô hình. Sau khi huấn luyện mô hình, thư mục chứa mô hình bao gồm mô hình huyến luyện, file config, file log, vocab.
|
120 |
-
- $CONFIG là đường dẫn tới vị trí chứa file config
|
121 |
-
|
122 |
-
## Bước 3: Dịch
|
123 |
-
|
124 |
-
Mô hình dịch dựa trên thuật toán beam search và lưu bản dịch tại `$your_data_path/translate.en2vi.vi`.
|
125 |
-
|
126 |
-
```bash
|
127 |
-
python -m bin.main infer --model Transformer --model_dir $MODEL/en-vi.model --features_file $your_data_path/tst2012.en --predictions_file $your_data_path/translate.en2vi.vi
|
128 |
-
```
|
129 |
-
|
130 |
-
## Bước 4: Đánh giá chất lượng dựa trên điểm BLEU
|
131 |
-
|
132 |
-
Đánh giá điểm BLEU dựa trên multi-bleu
|
133 |
-
|
134 |
-
```bash
|
135 |
-
perl thrid-party/multi-bleu.perl $your_data_path/translate.en2vi.vi < $your_data_path/tst2012.vi
|
136 |
-
```
|
137 |
-
|
138 |
-
| MODEL | BLEU (Beam Search) |
|
139 |
-
| :-----------------:| :----------------: |
|
140 |
-
| Transformer (Base) | 25.64 |
|
141 |
-
|
142 |
-
|
143 |
-
## Chi tiết tham khảo tại
|
144 |
-
[nmtuet.ddns.net](http://nmtuet.ddns.net:1190/)
|
145 |
-
|
146 |
-
## Nếu có ý kiến đóng góp, xin hãy gửi thư tới địa chỉ mail [email protected]
|
147 |
-
|
148 |
-
## Xin trích dẫn bài báo sau:
|
149 |
-
```bash
|
150 |
-
@inproceedings{ViNMT2022,
|
151 |
-
title = {ViNMT: Neural Machine Translation Toolkit},
|
152 |
-
author = {Nguyen Hoang Quan, Nguyen Thanh Dat, Nguyen Hoang Minh Cong, Nguyen Van Vinh, Ngo Thi Vinh, Nguyen Phuong Thai, Tran Hong Viet},
|
153 |
-
booktitle = {https://arxiv.org/abs/2112.15272},
|
154 |
-
year = {2022},
|
155 |
-
}
|
156 |
-
```
|
|
|
1 |
+
---
|
2 |
+
title: NMT LaVi
|
3 |
+
emoji: 🐢
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: pink
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.28.2
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: unknown
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|