Skip to content

Commit

Permalink
添加使用方法
Browse files Browse the repository at this point in the history
  • Loading branch information
moon-hotel committed Jun 26, 2021
1 parent 490d652 commit 470dac8
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## A Transformer Framework Based Translation Task
### 一个基于Transformer网络结构的文本翻译模型

### 论文[Attention Is All You Need](https://arxiv.org/abs/1706.03762) 基于PyTorch的实现



## 1. 环境准备
* Python==3.x
* PyTorch==1.5.0
* torchtext==0.6.0

## 2. 使用方法
* STEP 1. 直接下载或克隆本项目:https://github.com/moon-hotel/TransformerTranslation
* STEP 2. 可自定义修改配置文件`config.py`中的配置参数,也可以保持默认
### 2.1 训练
直接执行如下命令即可进行模型训练:
```
python train.py
```
训练过程:
```python
Epoch: 2, Train loss: 5.685, Train acc: 0.240947
Epoch: 2, Train loss: 5.668, Train acc: 0.241493
Epoch: 2, Train loss: 5.714, Train acc: 0.224682
Epoch: 2, Train loss: 5.660, Train acc: 0.235888
Epoch: 2, Train loss: 5.584, Train acc: 0.242052
Epoch: 2, Train loss: 5.611, Train acc: 0.243428
```
学习率变化:
<img src = "imgs/learning_rate.jpg" style="zoom:50%;" >


## 2.2 预测(inference)
直接运行如下命令即可:

```
python translate.py
```

示例结果:

```python
德语:Eine Gruppe von Menschen steht vor einem Iglu.
翻译:A group of people standing in fraon of an igloo .
英语:A group of people are facing an igloo.
=========
德语:Ein Mann in einem blauen Hemd steht auf einer Leiter und putzt ein Fenster.
翻译:A man in a blue shirt is standing on a ladder cleaning a window.
英语:A man in a blue shirt is standing on a ladder cleaning a window.
```
## 3. 结果
bleu评测结果

|val | test_2016_flickr |
|--|--|
| | |

0 comments on commit 470dac8

Please sign in to comment.