Keras로 배우는 Machine Translation
Thushan Ganegedara
Data Scientist and Author


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 .





단어와 해당 인덱스를 매핑한 사전
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]
출력 벡터 길이 미지정 원-핫 인코딩
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