在spaCy中,可以使用Count类来实现词频统计。具体步骤如下:
导入spacy库并加载模型import spacynlp = 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中的词频统计功能。


