Generowanie tłumaczeń za pomocą NMT

Tłumaczenie maszynowe z Keras

Thushan Ganegedara

Data Scientist and Author

Motywacja

  • Mamy wytrenowany model
  • Musi wspierać ludzi w zadaniach tłumaczenia
  • Testowanie modelu na nowych danych

  • Jak?

    • Wydzielony zbiór testowy do oceny modelu
    • Model przetestujemy, prosząc go o przetłumaczenie jednego zdania.
Tłumaczenie maszynowe z Keras

Przekształcanie danych wejściowych

  • Zdanie w języku angielskim
en_st = ['the united states is sometimes chilly during december , but it is sometimes freezing in june .']
  • Przekształcenie zdania dla enkodera
en_seq = sents2seqs('source', en_st, onehot=True, reverse=True)
print(np.argmax(en_seq, axis=-1)
English: ['the united states is sometimes chilly during december , 
           but it is sometimes freezing in june .']
Reversed sentence: ['june in freezing sometimes is it ...'] 
Reversed sequence: [[34   3  54       10        2  4  7 45  5 69 10  2 23 22  6]]
Tłumaczenie maszynowe z Keras

Generowanie tłumaczenia

  • Generowanie predykcji

    fr_pred = model.predict(en_seq)
    
  • fr_pred.shape

    • [sentences, seq len, vocab size]
  • Pobieranie przewidywanych klas
fr_seq = np.argmax(fr_pred, axis=-1)[0]
[[ 3  7 35 34  2 ...  5  4  4  0  0]] # <= fr_seq
  • fr_seq.shape
    • [num sentences, sequence len]

Tłumaczenie maszynowe z Keras

Konwersja predykcji na zdanie

  • Konwersja identyfikatorów słów na zdanie za pomocą wyrażenia listowego
fr_sentence = ' '.join([fr_id2word[i] for i in fr_seq if i != 0])
English: the united states is sometimes chilly during december , but it is sometimes freezing in june .

French: les états unis est parfois froid en décembre mais il est parfois le gel en
French (Google Translate): les etats-unis sont parfois froids en décembre, mais parfois gelés en juin
Tłumaczenie maszynowe z Keras

Wyrażenia listowe — szczegóły

  • Wyrażenie listowe
word_list = [fr_tok.index_word[i] for i in fr_seq if i != 0]
  • Pętla for
word_list = []
for i in fr_seq:
  if i != 0:
    word_list.append(fr_tok.index_word[i])
Tłumaczenie maszynowe z Keras

Czas na ćwiczenia!

Tłumaczenie maszynowe z Keras

Preparing Video For Download...