python - Spacy:如何使用您自己的分隔符创建标记器
问题描述
我需要创建一个标记器,它将使用逗号分割我的文本。
对于那个文本
"5g, dynamic vision sensor (dvs), 3-d reconstruction, neuromorphic engineering, neural networks, humanoid robots, neuromorphics, closed loop systems, field programmable gate arrays, spiking motor controller, neuromorphic implementation, icub, relation neural network"
我想得到这个输出
['5g', 'dynamic vision sensor (dvs)', '3-d reconstruction', 'neuromorphic engineering', 'neural networks', 'humanoid robots', 'neuromorphics', 'closed loop systems', 'field programmable gate arrays', 'spiking motor controller', 'neuromorphic implementation', 'icub', 'relation neural network']
我尝试使用自定义标记器
def custom_tokenizer(nlp):
pattern = re.compile(r'([\sa-z0-9\(\)-]+)')
return Tokenizer(nlp.vocab,
token_match=pattern.finditer)
nlp.tokenizer = custom_tokenizer(nlp)
但它返回了我
['5g,', 'dynamic', 'vision', 'sensor', '(dvs),', '3-d', 'reconstruction,', 'neuromorphic', 'engineering,', 'neural', 'networks,', 'humanoid', 'robots,', 'neuromorphics,', 'closed', 'loop', 'systems,', 'field', 'programmable', 'gate', 'arrays,', 'spiking', 'motor', 'controller,', 'neuromorphic', 'implementation,', 'icub,', 'relation', 'neural', 'network']
我检查了模式,它工作正常。如何停止使用空格分割文本?
解决方案
推荐阅读
- oracle - 如何使用 LPAD 在 Oracle 中修复 ORA-01850 小时必须介于 0 到 23 之间的问题
- python - Plotly-Dash 显示错误的图形(线图而不是漏斗图)
- android - Android 导航图,嵌套图问题
- c - 是否有可能用 C 语言获得准确的时间?
- c# - 无法使用 GraphQL 和 .NET 核心调用 Activator.CreateInstance
- javascript - 如何在数组中加入 JS 对象?在线人
- spring - 整个春季批量测试中的模拟对象
- typescript - 打字稿:元素隐式具有“任何”类型,因为索引表达式不是“数字”类型
- python - 如何从 JSON 中的键中获取值
- python-3.x - 如何在 Python Selenium Appium 的 textarea 中“发送_keys”多行?