Kod çözücüyü tanımlama

Keras ile Machine Translation

Thushan Ganegedara

Data Scientist and Author

Encoder–decoder modeli

  • Encoder İngilizce kelimeleri tek tek işler
  • Sonunda bağlam vektörünü üretir
  • Decoder bağlam vektörünü başlangıç durumu olarak alır
  • Decoder Fransızca kelimeleri tek tek üretir

Encoder-decoder modeli

Keras ile Machine Translation

Decoder girdisi

  • Decoder, Keras GRU katmanı ile uygulanır
  • GRU modeli iki girdi ister
    • Zaman serisi girdi (???)
    • Gizli durum

Encoder-decoder modeli

Keras ile Machine Translation

Decoder girdisi

Encoder’dan gelen bağlam vektörünü N kez yineleyin

  • 10 kelimelik Fransızca cümle için bağlam vektörünü 10 kez yinelersiniz.

Encoder–decoder modeli tekrar vektörü

Keras ile Machine Translation

RepeatVector katmanını anlama

RepeatVector katmanı:

  • Çıktı dizisinin uzunluğunu belirleyen tek bir argüman alır
  • (batch_size, girdi boyutu) biçiminde girdi alır (ör. 2 x 3)
  • (batch_size, dizi uzunluğu, girdi boyutu) biçiminde çıktı verir (ör. 2 x 3 x 3)

RepeatVector işlevselliği

Keras ile Machine Translation

RepeatVector katmanını tanımlama

from tensorflow.keras.layers import RepeatVector
rep = RepeatVector(5)
r_inp = Input(shape=(3,))
r_out = rep(r_inp)
repeat_model = Model(inputs=r_inp, outputs=r_out)
  • Aşağıdakilerin eşdeğer olduğuna dikkat ediniz
rep = RepeatVector(5)
r_out = rep(r_inp)
r_out = RepeatVector(5)(r_inp)
Keras ile Machine Translation

Modelle tahmin

Modelle tahmin

x = np.array([[0,1,2],[3,4,5]])
y = repeat_model.predict(x)
print('x.shape = ',x.shape,'\ny.shape = ',y.shape)
x.shape =  (2, 3) 
y.shape =  (2, 5, 3)
Keras ile Machine Translation

Kod çözücüyü uygulama

Kod çözücüyü tanımlama

de_inputs = RepeatVector(fr_len)(en_state)
decoder_gru = GRU(hsize, return_sequences=True)

Kod çözücünün başlangıç durumunu sabitleme

gru_outputs = decoder_gru(de_inputs, initial_state=en_state)
Keras ile Machine Translation

Modeli tanımlama

enc_dec = Model(inputs=en_inputs, outputs=gru_outputs)
Keras ile Machine Translation

Hadi pratik yapalım!

Keras ile Machine Translation

Preparing Video For Download...