我有一个小程序,它使用 NLTK 来获取相当大的数据集的频率分布。问题是,几百万字之后,我开始耗尽系统上的所有 RAM。这是我认为相关的代码行:
freq_distribution = nltk.FreqDist(filtered_words) # get the frequency distribution of all the words
top_words = freq_distribution.keys()[:10] # get the top used words
bottom_words = freq_distribution.keys()[-10:] # get the least used words
必须有一种方法可以将密钥、值存储写入磁盘,我只是不确定如何。我试图远离像 MongoDB 这样的文档存储并保持纯粹的 Python 风格。如果有人有一些建议,我将不胜感激。