第 1 部分:探索数据集
现在请先对数据集做一些探索。您将先直观了解数据的样貌。您会打印部分数据,并学习如何将数据中的句子切分(分词)为单个单词。对于英语,分词看起来是个相对简单的任务;然而,像日语这样的语言并不像英语那样用空格做出一致的分隔。
在本练习中,您会得到两个数据集:en_text 和 fr_text。en_text 包含英语句子的列表,fr_text 则包含与之对应的法语句子列表。
本练习是课程的一部分
使用 Keras 的机器翻译
练习说明
- 编写一个
zip()调用,同时遍历英语句子(en_text)和法语句子(fr_text)的前 5 个句子。 - 从
en_text中获取第一条英语句子。 - 使用空格字符配合
split()函数对该句子进行分词,并将结果赋给first_words。 - 打印分词后的单词。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Iterate through the first 5 English and French sentences in the dataset
for en_sent, fr_sent in zip(____, ____):
print("English: ", en_sent)
print("\tFrench: ", fr_sent)
# Get the first sentence of the English dataset
first_sent = ____[____]
print("First sentence: ", first_sent)
# Tokenize the first sentence
____ = ____.____(____)
# Print the tokenized words
print("\tWords: ", ____)