在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中的词频统计功能。