开始使用免费开始使用

完成文本反转模型

现在,您将实现文本反转模型的解码器部分,用于将编码器产生的上下文向量转换为反转后的单词序列。

您将定义两个函数 onehot2words()decoder()onehot2words() 函数接收一组 id 和字典 index2word,把一组独热向量数组转换为单词列表。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
编辑并运行代码