Word Cloud python库在每个单词的末尾显示一个撇号

问题描述 投票:0回答:1

我用nltk.tokenize标记了一个txt文件,并生成了一个新文件,我们称它为“ File_B”。

然后我跑步:

from wordcloud import WordCloud
import matplotlib.pyplot as plt

text = open('File_B').read()

wordcloud = WordCloud(width=1600, height=800).generate(text)

wordcloud = WordCloud(font_path=font_path, width=1600, height=800).generate(text)
plt.figure(figsize=(20,10))
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.tight_layout(pad=0)
plt.savefig("wordcloud.png", bbox_inches='tight')

这是结果:

https://i.stack.imgur.com/RnoJ7.png

即使每个单词都没有出现在File_B中,每个单词的末尾都有一个撇号。我想念什么?

python nltk word-cloud
1个回答
0
投票

当将标记化的文本转换为字符串时,不出现撇号:

string_text = ' '.join(tokenized_text)    
wordcloud = WordCloud(width=1600, height=800).generate(string_text)
© www.soinside.com 2019 - 2024. All rights reserved.