前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Github 项目推荐 | 用 Keras 实现的神经网络机器翻译

Github 项目推荐 | 用 Keras 实现的神经网络机器翻译

作者头像
朱晓霞
发布2018-04-18 11:50:07
8390
发布2018-04-18 11:50:07
举报
文章被收录于专栏:目标检测和深度学习
本库是用 Keras 实现的神经网络机器翻译,查阅库文件请访问:

https://nmt-keras.readthedocs.io/

Github 页面:

https://github.com/lvapeab/nmt-keras

如过你需要在研究中使用本工具库,请引用以下论文:

代码语言:javascript
复制
@misc{nmt-keras2017,
  author = {Peris, {\'A}lvaro},
  title = {{NMT}-{K}eras},
  year = {2017},
  publisher = {GitHub},
  note = {GitHub repository},
  howpublished = {\url{https://github.com/lvapeab/nmt-keras}},
}

安装

假设已经安装 pip,请运行:

代码语言:javascript
复制
git clone https://github.com/lvapeab/nmt-keras
cd nmt-keras
pip install -r requirements.txt

获取运行该库所需要的软件包。

需求

安装 NMT-Keras 需要以下的库

  • 我们的 Keras 版本(推荐版本 2.0.7 或更新版本) https://github.com/MarcBS/keras
  • Multimodal Keras Wrapper(2.0 版或更新版本,文档和教程) https://github.com/lvapeab/multimodal_keras_wrapper
  • Coco-caption 评估套件(只需执行评估) https://github.com/lvapeab/coco-caption/tree/master/pycocoevalcap/

用法:

  1. 在 config.py 脚本中设置一个训练配置。请查阅文档(https://github.com/lvapeab/nmt-keras/blob/master/examples/documentation/config.md)获取有关每个特定超参数的详细信息。您也可以在按照语法 Key = Value 调用 main.py 脚本时指定参数。
  2. 开始训练!:
代码语言:javascript
复制
python main.py

解码

一旦我们的模型开始训练,我们就可以使用 sample_ensemble.py 脚本翻译新文本。有关此脚本的更多详细信息,请参阅 ensembling_tutorial:

https://github.com/lvapeab/nmt-keras/blob/master/examples/documentation/ensembling_tutorial.md

总之,如果我们想使用前三个 epoch 的模型来翻译 examples / EuTrans / test.en 文件,只需运行:

代码语言:javascript
复制
python sample_ensemble.py 
             --models trained_models/tutorial_model/epoch_1 \ 
                      trained_models/tutorial_model/epoch_2 \
             --dataset datasets/Dataset_tutorial_dataset.pkl \
             --text examples/EuTrans/test.en

评分

score.py(https://github.com/lvapeab/nmt-keras/blob/master/score.py)脚本可用于获取平行语料库的概率(-log)。 其语法如下:

代码语言:javascript
复制
python score.py --help
usage: Use several translation models for scoring source--target pairs
       [-h] -ds DATASET [-src SOURCE] [-trg TARGET] [-s SPLITS [SPLITS ...]]
       [-d DEST] [-v] [-c CONFIG] --models MODELS [MODELS ...]
optional arguments:
    -h, --help            show this help message and exit
    -ds DATASET, --dataset DATASET
                            Dataset instance with data
    -src SOURCE, --source SOURCE
                            Text file with source sentences
    -trg TARGET, --target TARGET
                            Text file with target sentences
    -s SPLITS [SPLITS ...], --splits SPLITS [SPLITS ...]
                            Splits to sample. Should be already includedinto the
                            dataset object.
    -d DEST, --dest DEST  File to save scores in
    -v, --verbose         Be verbose
    -c CONFIG, --config CONFIG
                            Config pkl for loading the model configuration. If not
                            specified, hyperparameters are read from config.py
    --models MODELS [MODELS ...]
                            path to the models
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2018-03-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 目标检测和深度学习 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
机器翻译
机器翻译(Tencent Machine Translation,TMT)结合了神经机器翻译和统计机器翻译的优点,从大规模双语语料库自动学习翻译知识,实现从源语言文本到目标语言文本的自动翻译,目前可支持十余种语言的互译。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档