開始使用免費開始

完成文字反轉模型

你現在要實作文字反轉模型的解碼器部分,將編碼器輸出的情境向量轉換為反轉後的單字。

你會定義兩個函式 onehot2words()decoder()onehot2words() 會接收一組 id 清單與字典 index2word,把一組 one-hot 向量陣列轉成單字清單。decoder() 則會接收情境向量(也就是單字 id 的清單),並將其轉換為反轉後的單字清單。

在本練習中,會提供 index2word 字典、情境向量 contextencoder() 函式,以及 words2onehot() 函式。

本練習屬於課程

使用 Keras 進行機器翻譯

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Define the onehot2words function that returns words for a set of onehot vectors
def ____(onehot, index2word):
  ids = np.____(____, ____=____)
  res = [____[____] for id in ids]
  return res
編輯並執行程式碼