在spaCy中,可以使用Count類來實現詞頻統計。具體步驟如下:
import spacy
nlp = spacy.load("en_core_web_sm")
word_freq = {}
text = "This is a sample text for word frequency analysis."
doc = nlp(text)
for token in doc:
word = token.text
if word not in word_freq:
word_freq[word] = 1
else:
word_freq[word] += 1
for word, freq in word_freq.items():
print(word, freq)
通過以上步驟,就可以實現spaCy中的詞頻統計功能。