Python: 词云,重复词

Python: wordcloud, repetitive words

在词云中我有重复的词,我不明白为什么不把它们算在一起,然后显示为一个词。

from wordcloud import WordCloud
word_string = 'oh oh oh oh oh oh verse wrote book stand title book would life superman thats make feel count privilege love ideal honored know feel see everyday things things say rock baby truth rock love rock rock everything need rock baby rock wanna kiss ya feel ya please ya right wanna touch ya love ya baby night reward ya things rock love rock love rock oh oh oh verse try count ways make smile id run fingers run timeless things talk sugar keeps going make wanna keep lovin strong make wanna try best give want need give whole heart little piece minimum talking everything single wish talking every dream rock baby truth rock love rock rock everything need rock baby rock wanna kiss ya feel ya please ya right wanna touch ya love ya baby night reward ya things rock love rock wanna rock bridge theres options dont want theyre worth time cause oh thank like us fine rock sand smile cry joy pain truth lies matter know count oh oh oh oh oh oh rock baby truth rock love rock rock everything need rock baby rock wanna kiss ya feel ya please ya right wanna touch ya love ya baby night reward ya things rock love rock love rock oh oh oh oh oh oh wanna kiss ya feel ya please ya right wanna touch ya love ya baby night reward ya things rock love rock wanna rock party people people party popping sitting around see looking looking see look started lets hook little one one come give stuff let freshin ruff lets go lets hook start wont stop baby baby dont stop come give stuff lets go black culture black culture black culture black culture party people people party popping sitting around see looking looking see look started lets hook come one give stuff let freshin little one one ruff lets go lets hook start wont stop baby baby dont stop come give stuff lets go black culture black culture black culture black culture lets hook come give stuff let freshin little one one ruff lets go lets hook start wont stop baby baby dont stop come give stuff lets go lets hook come give stuff let freshin little one one ruff lets go lets hook start wont stop baby baby dont stop come give stuff lets go black culture black culture black culture black culture black culture black culture black culture black culture'
wordcloud = WordCloud(background_color="white",
                          width=1200, height=1000,
                          stopwords=STOPWORDS
                         ).generate(word_string)
plt.imshow(wordcloud)

如你所见 love, oh, rock, black, culture 出现了好几次,好像没算在一起。我做错了什么?

如果您查看 wordcloud.words_,您会看到频率 table 包含一些双词短语,例如 'oh oh'、'hook start'、'lets go'、'lets hook'.

您需要深入研究 .process_text() 背后的代码才能确切地了解它这样做的原因。

作为变通方法,您可以自己拆分 word_string 来构建词频 table,然后使用 .generate_from_frequencies() 创建图像。

这是 word_cloud 项目中名为 'collocations' 的功能。你可以通过设置 collocations=False 来关闭它,像这样:

    wordcloud = WordCloud(collocations=False).generate(word_string)

这将删除文本中经常组合在一起的词。它会去掉一些你可能不喜欢的东西,例如,"oh oh",它会去掉一些你可能喜欢的东西,例如,"black culture"