- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我试图从以下段落结构中提取此类信息:
women_ran men_ran kids_ran walked
1 2 1 3
2 4 3 1
3 6 5 2
text = ["On Tuesday, one women ran on the street while 2 men ran and 1 child ran on the sidewalk. Also, there were 3 people walking.", "One person was walking yesterday, but there were 2 women running as well as 4 men and 3 kids running.", "The other day, there were three women running and also 6 men and 5 kids running on the sidewalk. Also, there were 2 people walking in the park."]
我正在使用 Python 的 spaCy
作为我的 NLP 库。我是 NLP 工作的新手,希望就什么是从此类句子中提取表格信息的最佳方式提供一些指导。
如果只是简单地识别是否有人运行或行走,我会使用 sklearn
来拟合分类模型,但我需要提取的信息显然比那(我正在尝试检索每个子类别和值)。任何指导将不胜感激。
最佳答案
为此你需要使用依赖解析。您可以使用 the displaCy visualiser 查看示例句子的可视化效果.
您可以通过几种不同的方式实现您需要的规则——就像总是有多种方式来编写 XPath 查询、DOM 选择器等一样。
像这样的东西应该可以工作:
nlp = spacy.load('en')
docs = [nlp(t) for t in text]
for i, doc in enumerate(docs):
for j, sent in enumerate(doc.sents):
subjects = [w for w in sent if w.dep_ == 'nsubj']
for subject in subjects:
numbers = [w for w in subject.lefts if w.dep_ == 'nummod']
if len(numbers) == 1:
print('document.sentence: {}.{}, subject: {}, action: {}, numbers: {}'.format(i, j, subject.text, subject.head.text, numbers[0].text))
对于您在 text
中的示例,您应该得到:
document.sentence: 0.0, subject: men, action: ran, numbers: 2
document.sentence: 0.0, subject: child, action: ran, numbers: 1
document.sentence: 0.1, subject: people, action: walking, numbers: 3
document.sentence: 1.0, subject: person, action: walking, numbers: One
关于python - NLP - Python 中的信息提取 (spaCy),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40453503/
我尝试进行词形还原,即识别动词的词形和可能的阿拉伯语词根,例如: يتصل ==> lemma(动词的不定式)==> اتصل ==> root(三字根/Jidr thoulathi) ==> و ص
在执行 NLP 或 IR/IE 相关任务时,是否有人们通常用来删除标点符号和关闭类别词(例如 he, she, it)的停用词列表? 我一直在尝试使用 gibbs 抽样来进行词义消歧的主题建模,并且它
我不知道StackOverflow是否涵盖NLP,所以我来试试。 我有兴趣从特定 Realm 中找到两个词的语义相关性,即“图像质量”和“噪声”。我正在做一些研究,以确定相机的评论对于相机的特定属性是
是否有算法或方法可以评估文本项之间的共同趋势/主题? 例如,假设有四个数据点(文本条目): “我发现学校今天压力很大” “物理测试非常容易。” “我的物理测试根本没有挑战” “每个人都提早离开了,因为
我有兴趣了解有关 Natural Language Processing 的更多信息(NLP)并且我很好奇目前是否有任何不基于字典识别的策略来识别文本中的专有名词?另外,任何人都可以解释或链接到解释当
特征用于模型训练和测试。自然语言处理中的词汇特征和正字法特征有什么区别?例子首选。 最佳答案 我不知道这样的区别,大多数时候当人们谈论词汇特征时,他们谈论的是使用这个词本身,而不是仅使用其他特征,即它
在 NLP 任务中,人们用 SOC(句子开头)和 EOC(句子结尾)注释句子是很常见的。他们为什么这样做? 这是一个任务相关的表现吗?例如,您在 NER 问题中进行填充的原因与您在翻译问题中进行填充的
我一直在研究 NLP 并使用 notepad++ 来处理文本文件。这很好,在某些情况下,但问题是无法使用包含大量文本的大型文件进行锻炼。 VIM 不支持 UTF-8。哪一个是最好的支持 unicode
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 3年前关闭。 Improve this questi
我在 Stanford CoreNLP demo page 中解析了以下句子和 Stanford parser demo page .尽管两者都会导致可以暗示目的语义的解析(相应地取决于 advcl
语义网和自然语言处理之间究竟有什么区别? 语义网是自然语言处理的一部分吗? 最佳答案 这是两个独立的学科领域,但它们在某些地方确实重叠。因为文档,无论其格式如何,都是由异构语法和语义组成的,所以目标是
我需要解析非结构化文本并将相关概念转换为格式,以便所有三元组可以合并形成一个图。例如如果我有 2 个句子,比如 A improves B 和 B improves C,我应该能够创建一个像这样的图 A
使用 GATE 时,本体在自然语言处理中的作用是什么? 据我了解,在较高层次上,本体允许对由类、它们的实例、这些实例的属性以及域中类之间的关系组成的域进行建模。 但是,在使用 GATE 时创建自定义本
我最后一年的工程项目要求我使用 Java 或 Python 构建一个应用程序,该应用程序使用自然语言处理来总结文本文档。我什至如何开始编写这样的应用程序? 根据一些研究,我刚刚注意到基于提取的摘要对我
我想知道是否可以使用 Stanford CoreNLP检测一个句子是用哪种语言写的?如果是这样,这些算法的精确度如何? 最佳答案 几乎可以肯定,此时斯坦福 COreNLP 中没有语言识别。 “几乎”
我在一家制造可以与 child 交谈的玩具车的公司工作。我们想使用斯坦福核心 NLP 作为解析器。但是,它以 GPL 许可:他们不允许在商业上使用 NLP。我可以从斯坦福 NLP 小组购买其他许可证吗
我想使用 Natural Language Processing Libraries 从句子中找到谓词和主语.这种技术在NLP的世界里有什么名字吗?或者有没有办法做到这一点? Example : He
所以,这个问题可能有点幼稚,但我认为询问 Stackoverflow 的友好人士不会有什么坏处。 我现在的公司已经使用第三方 API 进行 NLP 一段时间了。我们基本上对一个字符串进行 URL 编码
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 3年前关闭。 Improve thi
这可能是一个愚蠢的问题,但是如何迭代解析树作为 NLP 解析器(如斯坦福 NLP)的输出?它都是嵌套的括号,既不是 array 也不是 dictionary 或我使用过的任何其他集合类型。 (ROOT
我是一名优秀的程序员,十分优秀!