產生詞向量
在這個練習中,你將為一句話中的所有單字兩兩計算相似度分數。這句話已以 sent 提供,並已經列印到主控台方便你查看。
本練習屬於課程
Python 中文本特徵工程
練習說明
- 以
sent建立Doc物件doc。 - 在巢狀迴圈中,計算
token1與token2的相似度。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the doc object
doc = nlp(___)
# Compute pairwise similarity scores
for token1 in doc:
for token2 in doc:
print(token1.text, token2.text, token1.similarity(token2))