句子與字詞的斷詞(tokenization)
斷詞是 NLP 的第一個重要步驟。它會把文字切分為較小的單位(tokens),這是處理語言資料的關鍵。你的任務是把一段新聞文章同時切分成句子與字詞。
本練習屬於課程
Python 的 Natural Language Processing(NLP)
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import nltk
____
# Download the punkt_tab package
____
text = """
The stock market saw a significant dip today. Experts believe the downturn may continue.
However, many investors are optimistic about future growth.
"""
# Tokenize the text into sentences
sentences = ____
print(sentences)