Kodlayıcı-çözücü mimarisi

Keras ile Machine Translation

Thushan Ganegedara

Data Scientist and Author

Kodlayıcı-çözücü modeli

Makine çevirisi modeli

Keras ile Machine Translation

Kodlayıcı

Kodlayıcı

Keras ile Machine Translation

Kodlayıcı ve çözücü

Kodlayıcı çözücü

Keras ile Machine Translation

Benzetim: Kodlayıcı-çözücü mimarisi

Kodlayıcı benzetimi

Çözücü benzetimi

Keras ile Machine Translation

Cümleleri tersine çevirme - kodlayıcı-çözücü modeli

Kodlayıcı çözücü metin ters çevirme

Keras ile Machine Translation

Kodlayıcıyı yazma

def words2onehot(word_list, word2index):
  word_ids = [word2index[w] for w in word_list]
  onehot = to_categorical(word_ids, 3)
  return onehot
def encoder(onehot):
  word_ids = np.argmax(onehot, axis=1)
  return word_ids
Keras ile Machine Translation

Kodlayıcıyı yazma

onehot = words2onehot(["I", "like", "cats"], word2index)
context = encoder(onehot)
print(context)
[0, 1, 2]
Keras ile Machine Translation

Çözücüyü yazma

  • Çözücü: Sözcük kimlikleri → Kimlikleri ters çevir → tek-sıcak vektörler
def decoder(context_vector):
  word_ids_rev = context_vector[::-1]
  onehot_rev = to_categorical(word_ids_rev, 3)
  return onehot_rev
  • Yardımcı işlev: tek-sıcak vektörleri okunabilir sözcüklere çevir
def onehot2words(onehot, index2word):
  ids = np.argmax(onehot, axis=1)
  return [index2word[id] for id in ids]
Keras ile Machine Translation

Çözücüyü yazma

onehot_rev = decoder(context)
reversed_words = onehot2words(onehot_rev, index2word)

print(reversed_words)
['cats', 'like', 'I']
Keras ile Machine Translation

Hadi pratik yapalım!

Keras ile Machine Translation

Preparing Video For Download...