在《蠅王》中進行 POS 標註
在這個練習中,你會對史上最知名的小說之一《蠅王》(作者 William Golding)中的一段經典文字做詞性(part-of-speech, POS)標註。
這段文字已存為 lotf,並且已經列印到主控台。
本練習屬於課程
Python 中文本特徵工程
練習說明
- 載入
en_core_web_sm模型。 - 使用
nlp()為lotf建立一個 doc 物件。 - 使用
text與pos_屬性,產生各個 token 及其對應的 POS 標籤。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Load the en_core_web_sm model
nlp = spacy.load(____)
# Create a Doc object
doc = ___(___)
# Generate tokens and pos tags
pos = [(token.____, token.____) for token in doc]
print(pos)