机器翻译简介

使用 Keras 的机器翻译

Thushan Ganegedara

Data Scientist and Author

机器翻译

"Hello"的翻译

使用 Keras 的机器翻译

机器翻译

带 Google 图标的"Hello"翻译

使用 Keras 的机器翻译

课程提要

  • 第1章:机器翻译简介
  • 第2章:实现机器翻译模型(编码器-解码器架构)
  • 第3章:训练模型并生成翻译
  • 第4章:改进翻译模型
使用 Keras 的机器翻译

数据集(英法句子语料)

  • 英语语料
new jersey is sometimes quiet during autumn , and it is snowy in april .
the united states is usually chilly during july , and it is usually freezing ...
california is usually quiet during march , and it is usually hot in june .
  • 法语语料
new jersey est parfois calme pendant l' automne , et il est neigeux en avril .
les états-unis est généralement froid en juillet , et il gèle habituellement ...
california est généralement calme en mars , et il est généralement chaud en juin .
1 https://github.com/udacity/deep-learning/tree/master/language-translation/data
使用 Keras 的机器翻译

机器翻译 - 概览

英语到法语

使用 Keras 的机器翻译

机器翻译 - 概览

源语言与目标语言术语

使用 Keras 的机器翻译

机器翻译 - 概览

机器翻译模型

使用 Keras 的机器翻译

机器翻译 - 概览

机器翻译模型

使用 Keras 的机器翻译

独热编码向量

  • 由0/1组成的向量
  • 向量长度由词表大小决定
  • 词表:数据集中唯一词的集合

独热向量

使用 Keras 的机器翻译

独热编码向量

包含词与其索引的映射

word2index = {"I":0, "like": 1, "cats": 2}

将词转换为ID或索引

words = ["I", "like", "cats"]
word_ids = [word2index[w] for w in words]
print(word_ids)
[0, 1, 2]
使用 Keras 的机器翻译

独热编码向量

未指定输出向量长度的独热编码

onehot_1 = to_categorical(word_ids)
print([(w,ohe.tolist()) for w,ohe in zip(words, onehot_1)])
[('I', [1.0, 0.0, 0.0]), ('like', [0.0, 1.0, 0.0]), ('cats', [0.0, 0.0, 1.0])]

指定输出向量长度的独热编码

onehot_2 = to_categorical(word_ids, num_classes=5)
print([(w,ohe.tolist()) for w,ohe in zip(words, onehot_2)])
[('I', [1.0, 0.0, 0.0, 0.0, 0.0]), ('like', [0.0, 1.0, 0.0, 0.0, 0.0]), 
('cats', [0.0, 0.0, 1.0, 0.0, 0.0])]
使用 Keras 的机器翻译

让我们练习!

使用 Keras 的机器翻译

Preparing Video For Download...