python - 二元组和三元组
问题描述
我目前正在尝试创建二元组和三元组,以将我的语料库从单词重新制作为单词和短语,并使用此笔记本作为我的参考。但是,我认为应该从代码中产生的短语没有被编译。
这是我正在使用的代码:
unigram_sentences = LineSentence("*.csv")
for unigram_sentence in it.islice(unigram_sentences, 1, 5):
print (u' '.join(unigram_sentence))
print (u'')
intermediate_directory = os.path.join('.../2015/TEMP')
bigram_model_filepath = os.path.join(intermediate_directory,'bigram_model_all')
%%time
bigram_model = Phrases(unigram_sentences)
bigram_model.save(bigram_model_filepath)
# load the finished model from disk
bigram_model = Phrases.load(bigram_model_filepath)
bigram_sentences_filepath = os.path.join(intermediate_directory,
'bigram_sentences_all.txt')
%%time
with codecs.open(bigram_sentences_filepath, 'w', encoding='utf_8') as f:
for unigram_sentence in unigram_sentences:
bigram_sentence = u' '.join(bigram_model[unigram_sentence])
f.write(bigram_sentence + '\n')
bigram_sentences = LineSentence(bigram_sentences_filepath)
for bigram_sentence in it.islice(bigram_sentences, 1, 5):
print (u' '.join(bigram_sentence))
print (u'')
实际上我的 Ins(一元句子)是:
- 是的,但自我伤害焦虑抑郁症属于心理健康
- 他们最好在空气中放咸味之前提醒县的心理健康
- BBC News plasters for the mind 心理健康急救的兴起
- 今天早上通过化妆修复了我奇怪的心情 hshtg_makeup hshtg_charlottetilbury hshtg_mentalhealth
虽然我的出局(二元句)是:
- 是的,但是 self_harm 焦虑抑郁症属于心理健康
- 他们最好在空气中放咸味之前提醒县的心理健康
- bbc_news plasters_for the mind the_rise in mental health first_aid
- 今天早上通过化妆修复了我奇怪的心情 hshtg_makeup hshtg_charlottetilbury hshtg_mentalhealthList item
虽然代码确实结合了 bbc_news 和 the_rise 之类的短语,但我在这里真正期望的是看到 mental_health 被组合在一起。
问题:我做错了什么?:/
感谢您的帮助,并为凌乱的第一个计时器帖子道歉!
阿丽娜
解决方案
推荐阅读
- javascript - javascript 中 ....loop 语法有什么区别?
- apache-spark-sql - spark sql:选择 DecimalType 列的比例大于数字的行
- odoo-12 - 如何解决“Uncaught TypeError: Cannot read property 'type' of undefined when add button to tree view of Odoo”?
- javascript - 为什么从轮播内部元素的事件调用Bootstrap 4轮播暂停功能时不起作用?
- powershell - PowerShell 数组问题与变量
- maven - 如何在 Maven 中自定义 JMeter 报告以显示 Pass-Fail 而不是 OK-KO/在报告中添加更多静态值?
- release - 如果您的应用程序频繁更改,您如何让呼叫中心操作员保持最新状态?
- azure - 能否通过 Azure 防火墙路由点到站点流量?
- python - 高效的条件滚动计算 Pandas
- javascript - 当状态改变时,React 不会重新渲染我的组件