我正在用python训练一个20 GB+的大型语料库,开发一个Markov链文本生成器。它接受纯文本并将其分成两对,当前选定的两个单词和后面的单词。这是列表的一部分:
[(('as', 'a'), 'subject'), (('a', 'subject'), 'for'), (('subject', 'for'), 'the'), (('for', 'the'), 'remarks'), (('the', 'remarks'), 'of'), (('remarks', 'of'), 'the'), (('of', 'the'), 'evening'), (('the', 'evening'), 'the'), (('evening', 'the'), 'perpetuation'), (('the', 'perpetuation'), 'of'), (('perpetuation', 'of'), 'our'), (('of', 'our'), 'political')]
然后我将其放入字典中,这样如果有一个关键字(两个单词)出现多次,我就可以将该值作为具有多个值的数组:
{('as', 'a'): ['subject', 'nation'], ('a', 'subject'): ['for'], ('subject', 'for'): ['the'], ('for', 'the'): ['remarks', 'executive', 'government', 'laws', 'redress', 'sake', 'constitution'], ('the', 'remarks'): ['of']}
我再次对添加到字典中的数千个文件执行此操作,过了一段时间,它对于ram来说太大了。有没有办法把这样的字典存储在磁盘上? 数据结构:
我认为我最好的想法是一个数据库或csv文件,但我读到他们是不切实际的
目前没有回答
相关问题 更多 >
编程相关推荐