機械翻訳入門

Kerasで学ぶMachine Translation

Thushan Ganegedara

Data Scientist and Author

機械翻訳

こんにちはの翻訳

Kerasで学ぶMachine Translation

機械翻訳

Google アイコン付きのこんにちはの翻訳

Kerasで学ぶMachine Translation

コース概要

  • 第1章 機械翻訳入門
  • 第2章 機械翻訳モデルの実装(エンコーダ・デコーダ)
  • 第3章 学習と翻訳生成
  • 第4章 翻訳モデルの改善
Kerasで学ぶMachine Translation

データセット(英仏対訳コーパス)

  • 英語コーパス
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で学ぶMachine Translation

機械翻訳 - 概要

英語からフランス語

Kerasで学ぶMachine Translation

機械翻訳 - 概要

ソース言語とターゲット言語の用語

Kerasで学ぶMachine Translation

機械翻訳 - 概要

機械翻訳モデル

Kerasで学ぶMachine Translation

機械翻訳 - 概要

機械翻訳モデル

Kerasで学ぶMachine Translation

ワンホットエンコードベクトル

  • 0/1 のベクトル
  • 長さは語彙サイズで決まる
  • 語彙: データセット内の一意の語の集合

ワンホットベクトル

Kerasで学ぶMachine Translation

ワンホットエンコードベクトル

語と対応するインデックスの対応表

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で学ぶMachine Translation

ワンホットエンコードベクトル

出力ベクトル長を指定しないワンホット化

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で学ぶMachine Translation

Ayo berlatih!

Kerasで学ぶMachine Translation

Preparing Video For Download...