我和Spacy合作过,到目前为止,我发现NLP非常直观和健壮。我试图从文本句子搜索,这是word base
和content type base
搜索的方式,但到目前为止,我还没有找到任何解决方案的空间。
我有这样的文字:
人工智能(
In computer science )中的人工智能(AI),有时被称为机器智能,是指机器所表现出来的智能,不同于人类和动物所表现出来的自然智能。领先的人工智能教科书将该领域定义为对“智能主体”的研究:任何感知其环境并采取行动以最大限度地实现其目标的行动的设备。1就口语而言,“人工智能”一词通常用于描述模仿人类与人类思维相关联的“认知”功能的机器(或计算机),如“学习”和“解决问题”.2。
随着机器能力的提高,被认为需要“智能”的任务往往被从人工智能的定义中删除,这一现象被称为人工智能效应。特斯勒定理中的一段俏皮话说:“人工智能是尚未完成的事情。”4例如,光学字符识别经常被排除在被认为是人工智能的事物之外,5已经成为常规技术。6通常被归类为人工智能的现代机器功能包括成功理解人类语言,7在战略游戏系统(如国际象棋和围棋)中进行最高级别的竞争,8自主操作汽车,在内容传递网络中进行智能路由,以及军事simulations9。
人工智能于1955年作为一门学术学科成立,此后的几年里经历了几次乐观浪潮,10次经历了失望和资金损失(称为“人工智能冬天”),12次之后又出现了新的方法、成功和新的资金。11在其历史的大部分时间里,人工智能研究被分成几个子领域--往往无法相互沟通的领域。15这些子领域是基于技术考虑,例如特定目标(例如“机器人”或“机器学习”),16使用特定工具(“逻辑”或人工神经网络),1719个子领域也是基于社会因素(特定的制度或特定研究人员的工作).15。
现在,我想提取多个单词或字符串匹配的多个句子。例如,我想搜索intelligent
和machine learning
。它打印所有完整的句子,其中包含这个单一的或两个给定的字符串。
有什么方法可以用spacy导入模式来感知短语的匹配..。就像它发现了所有的智能和机器学习包含文字和打印?还有其他的选择,它也能发现搜索机器学习,也建议深入学习,人工智能,模式识别等吗?
import spacy
nlp = spacy.load("en_core_web_sm")
from spacy.matcher import PhraseMatcher
phrase_matcher = PhraseMatcher(nlp.vocab)
phrases = ['machine learning', ''intelligent, 'human']
patterns = [nlp(text) for text in phrases]
phrase_matcher.add('AI', None, *patterns)
sentence = nlp (processed_article)
matched_phrases = phrase_matcher(sentence)
for match_id, start, end in matched_phrases:
string_id = nlp.vocab.strings[match_id]
span = sentence[start:end]
print(match_id, string_id, start, end, span.text)
我试了一下,它不是提供完整的句子,而是只提供与ID号匹配的单词。
总之,
发布于 2020-07-07 17:01:45
第1部分:
我想搜索智能和机器学习。它打印所有完整的句子,其中包含这个单一的或两个给定的字符串。
这是如何找到完整的句子,其中包含您的关键字,您正在寻找。请记住,句子的界限是从统计学上确定的,因此,如果收到的段落来自新闻或维基百科,也会很好,但是如果数据是来自社交媒体的话,就不会那么有效了。
import spacy
from spacy.matcher import PhraseMatcher
text = """I like tomtom and I cannot lie. In computer science, artificial intelligence (AI), sometimes called machine intelligence, is intelligence demonstrated by machines, unlike the natural intelligence displayed by humans and animals. Leading AI textbooks define the field as the study of "intelligent agents": any device that perceives its environment and takes actions that maximize its chance of successfully achieving its goals.[1] Colloquially, the term "artificial intelligence" is often used to describe machines (or computers) that mimic "cognitive" functions that humans associate with the human mind, such as "learning" and "problem solving".[2] """
nlp = spacy.load("en_core_web_sm")
phrase_matcher = PhraseMatcher(nlp.vocab)
phrases = ['machine learning', 'artificial intelligence']
patterns = [nlp(text) for text in phrases]
phrase_matcher.add('AI', None, *patterns)
doc = nlp(text)
for sent in doc.sents:
for match_id, start, end in phrase_matcher(nlp(sent.text)):
if nlp.vocab.strings[match_id] in ["AI"]:
print(sent.text)
输出
In computer science, artificial intelligence (AI), sometimes called machine intelligence, is intelligence demonstrated by machines, unlike the natural intelligence displayed by humans and animals.
Colloquially, the term "artificial intelligence" is often used to describe machines (or computers)
第2部分:
还能发现与搜索机器学习一样,也建议深入学习、人工智能、模式识别等吗?
是。这是非常可能的,您需要利用word2vec
或sense2vec
才能做到这一点。
https://stackoverflow.com/questions/62776477
复制相似问题