Teacher Forcing परिचय

Keras के साथ Machine Translation

Thushan Ganegedara

Data Scientist and Author

पिछला मशीन अनुवादक मॉडल

  • पिछला मॉडल

एन्कोडर डिकोडर पूर्ण मॉडल

  • Encoder GRU
    • अंग्रेजी शब्द लेता है
    • एक context vector आउटपुट करता है
  • Decoder GRU
    • context vector लेता है
    • GRU आउटपुट्स की sequence देता है
  • Decoder Prediction layer
    • GRU आउटपुट्स की sequence लेता है
    • फ़्रेंच शब्दों के लिए prediction probabilities देता है
Keras के साथ Machine Translation

उपमा: Teacher Forcing के बिना प्रशिक्षण

बिना teacher forcing 1

Keras के साथ Machine Translation

उपमा: Teacher Forcing के बिना प्रशिक्षण

बिना teacher forcing 2

Keras के साथ Machine Translation

উপमा: Teacher Forcing के बिना प्रशिक्षण

बिना teacher forcing 3

Keras के साथ Machine Translation

उपमा: Teacher Forcing के साथ प्रशिक्षण

teacher forcing 1

Keras के साथ Machine Translation

उपमा: Teacher Forcing के साथ प्रशिक्षण

teacher forcing 2

Keras के साथ Machine Translation

उपमा: Teacher Forcing के साथ प्रशिक्षण

teacher forcing 3

Keras के साथ Machine Translation

उपमा: Teacher Forcing के साथ प्रशिक्षण

teacher forcing 4

Keras के साथ Machine Translation

पिछला मशीन अनुवादक मॉडल

  • पिछला मॉडल

एन्कोडर डिकोडर पूर्ण मॉडल

  • Teacher-forced मॉडल

Teacher forcing के साथ एन्कोडर डिकोडर मॉडल

Keras के साथ Machine Translation

Teacher Forcing के साथ मॉडल लागू करना

  • Encoder
    en_inputs = layers.Input(shape=(en_len, en_vocab))
    en_gru = layers.GRU(hsize, return_state=True)
    en_out, en_state = en_gru(en_inputs)
    
  • Decoder GRU
    de_inputs = layers.Input(shape=(fr_len-1, fr_vocab))
    de_gru = layers.GRU(hsize, return_sequences=True)
    de_out = de_gru(de_inputs, initial_state=en_state)
    
Keras के साथ Machine Translation

इनपुट और आउटपुट

  • Encoder input - जैसे I, like, dogs
  • Decoder input - जैसे J'aime, les
  • Decoder output - जैसे les, chiens

Teacher forcing इनपुट और आउटपुट

Keras के साथ Machine Translation

Teacher Forcing के साथ मॉडल लागू करना

  • Encoder
    en_inputs = layers.Input(shape=(en_len, en_vocab))
    en_gru = layers.GRU(hsize, return_state=True)
    en_out, en_state = en_gru(en_inputs)
    
  • Decoder GRU
    de_inputs = layers.Input(shape=(fr_len-1, fr_vocab))
    de_gru = layers.GRU(hsize, return_sequences=True)
    de_out = de_gru(de_inputs, initial_state=en_state)
    
  • Decoder Prediction
    de_dense = layers.TimeDistributed(layers.Dense(fr_vocab, activation='softmax'))
    de_pred = de_dense(de_out)
    
Keras के साथ Machine Translation

मॉडल कम्पाइल करना

nmt_tf = Model(inputs=[en_inputs, de_inputs], outputs=de_pred)
nmt_tf.compile(optimizer='adam', loss="categorical_crossentropy", metrics=["acc"])
Keras के साथ Machine Translation

डेटा का प्रीप्रोसेसिंग

  • Encoder

    • इनपुट्स - सभी अंग्रेजी शब्द (onehot encoded)
      • en_x = sents2seqs('source', en_text, onehot=True, reverse=True)
  • Decoder

    de_xy = sents2seqs('target', fr_text, onehot=True)
    
    • इनपुट्स - अंतिम शब्द छोड़कर सभी फ़्रेंच शब्द (onehot encoded)
      • de_x = de_xy[:,:-1,:]
    • आउटपुट्स/टारगेट्स - पहले शब्द को छोड़कर सभी फ़्रेंच शब्द (onehot encoded)
      • de_y = de_xy[:,1:,:]
Keras के साथ Machine Translation

अभ्यास करते हैं!

Keras के साथ Machine Translation

Preparing Video For Download...