import nltk from wordcloud import WordCloud text = open('data.txt', 'r', encoding='utf-8').read() text = ' '.join(nltk.word_tokenize(text)) cloud = WordCloud().generate(text) cloud.to_file('output.png')