第 1 部分:探索資料集
現在來稍微探索一下資料集。你會先了解資料長什麼樣子。你會列印部分資料,並學會如何把資料中的句子斷詞(tokenize)為單字。對英文來說,斷詞看似是件輕鬆的事;然而,像日文這類語言,分隔符號就沒有英文那麼一致。
在本練習中,你會拿到兩個資料集: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: ", ____)