在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中的词频统计功能。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:oracle统计行数的方法是什么