最简版Seq2Seq的英法机器翻译实践和详细代码解释

Seq2Seq的英法机器翻译实践

本文的内容主要是基于英法平行语料库来实现一个简单的英法翻译模型。没有使用注意力机制和双向LSTM等技术,主要是为了掌握基本的Seq2Seq结构和TensorFlow函数使用。使用TensorFlow 1.12.0,主要依靠 tf.contrib.seq2seq.BasicDecoder 函数。python

手撸可运行代码 github.com/yuanxiaosc/…git

Seq2Seq 模型结构

使用方法

  1. python data_process.py
  2. python seq2seq_en_fr_translation_model.py
  3. python use_trained_model.py

使用模型作英法翻译

【Input】
  Word Ids:      [120, 89, 131, 217, 171, 38, 180, 204, 208, 89, 103, 192, 213, 177]
  English Words: ['france', 'is', 'never', 'cold', 'during', 'september', ',', 'and', 'it', 'is', 'snowy', 'in', 'october', '.']

【Prediction】
  Word Ids:      [47, 235, 302, 325, 64, 204, 127, 81, 284, 117, 302, 72, 204, 63, 256, 1]
  French Words: ['la', 'france', 'est', 'jamais', 'froid', 'en', 'septembre', ',', 'et', 'il', 'est', 'neigeux', 'en', 'janvier', '.', '<EOS>']

【Full Sentence】
la france est jamais froid en septembre , et il est neigeux en janvier . <EOS>
复制代码

代码参考以及详细的代码解释

Code reference github.com/NELSONZHAO/…github

基于TensorFlow框架的Seq2Seq英法机器翻译模型bash

tensorflow Seq2seq编码函数详解框架

更多机器翻译实战 github.com/yuanxiaosc/…函数