繁体   English   中英

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

[英]Word Cloud python library displays an apostrophe at the end of every word

我使用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 中。 我错过了什么?

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

string_text = ' '.join(tokenized_text)    
wordcloud = WordCloud(width=1600, height=800).generate(string_text)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM