python-3.x - 使用 keras ootb text_to_word_sequence 防止拆分包含 - 的单词
问题描述
我在用:
from keras.preprocessing.text import text_to_word_sequence
text = 'Decreased glucose-6-phosphate dehydrogenase activity along with oxidative stress affects visual contrast sensitivity in alcoholics.'
words = set(text_to_word_sequence(text))
print(words)
这导致:
{'oxidative', 'contrast', '6', 'affects', 'in', 'dehydrogenase', 'visual', 'stress', 'glucose', 'phosphate', 'along', 'activity', 'with', 'alcoholics', 'decreased', 'sensitivity'}
有没有办法防止单词分裂:葡萄糖-6-磷酸
解决方案
是的,通过从参数中删除连字符filters
:
from keras_preprocessing.text import text_to_word_sequence
text = 'Decreased glucose-6-phosphate ...'
words = set(text_to_word_sequence(text,
filters='!"#$%&()*+,./:;<=>?@[\\]^_`{|}~\t\n'))
words
{'activity',
'affects',
'alcoholics',
'along',
'contrast',
'decreased',
'dehydrogenase',
'glucose-6-phosphate',
'in',
'oxidative',
'sensitivity',
'stress',
'visual',
'with'}
这当然会影响文本中包含连字符的任何单词。
推荐阅读
- sql - 在 SQL 内连接查询中包含 SUM
- python - OperationalError:无法连接到服务器:操作超时 - 尝试将数据库从 sqlite 更改为 postresql
- c# - 如何获取类型的 IEnumerable 类型
- javascript - 如何释放 Angular2 更改检测监控的 Array 上的内存?
- javascript - 改变值并通过 jquery 自动提交
- module - Pycharm模块安装具体目录
- javascript - 当过滤器上没有可用项目时,如何在 shuffle.js 上显示消息?
- css - 使tablesorter响应
- sql-server-2012 - 具有记录类型的数据库范围表或引用表
- java - 控制台日志中的 Firebase 错误:firebase-database-connection 错误搜索