spaCy 詞彙表
詞向量(word embeddings)是將詞彙以數值方式表示,讓電腦能以文字資料執行各種複雜任務。許多 spaCy 模型都包含詞向量,但也有少數模型不包含。
在這個練習中,你會練習存取 spaCy 的詞彙資訊。每個 spaCy 模型都保存了一些與詞向量相關的中繼資訊。你可以讀取這些資訊,了解詞彙量、詞向量維度等內容。
已經為你匯入 spaCy 套件。在 spaCy 模型的中繼資料中,詞彙的數量儲存在「vectors」鍵的元素中,而詞向量的維度儲存在「width」鍵的元素中。
本練習屬於課程
使用 spaCy 的自然語言處理
練習說明
- 載入
en_core_web_md模型。 - 印出
en_core_web_md模型詞彙表中的詞彙數量。 - 印出
en_core_web_md模型的詞向量維度。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Load the en_core_web_md model
md_nlp = ____
# Print the number of words in the model's vocabulary
print("Number of words: ", md_nlp.____["vectors"]["vectors"], "\n")
# Print the dimensions of word vectors in en_core_web_md model
print("Dimension of word vectors: ", md_nlp.____["vectors"]["width"])