gpt4 book ai didi

python - 如何将句子拆分成相关的词(术语提取)?

转载 作者:太空宇宙 更新时间:2023-11-03 11:17:38 26 4
gpt4 key购买 nike

是否有任何 NLP python 库可以将句子拆分或将单词连接成相关的单词对?例如:

That is not bad example -> "That" "is" "not bad" "example"

“不错”与“好”的意思相同,因此在机器学习中将其处理为“不错”和“不好”是没有用的。我什至不知道如何称呼这些相关的词对。 (术语提取?阶段提取?)或者用名词拆分成形容词会更好,例如:

dishonest media relating about tax cuts -> "dishonest media", "relating", "about", "tax cuts"

我找到了 topia.termextract,但它不适用于 python3。

最佳答案

结帐 Spacy library (查看链接)。

它没有开箱即用的功能,因为您需要构建规则,但规则非常易于阅读,并且您可以输入许多选项(POS 标签、正则表达式、引理或任何这些的组合,等等)

特别值得注意的是 PhraseMarker() 上的部分 class .

直接从文档中复制的是代码示例:

import spacy
from spacy.matcher
import PhraseMatcher

nlp = spacy.load('en')
matcher = PhraseMatcher(nlp.vocab)
terminology_list = ['Barack Obama', 'Angela Merkel', 'Washington, D.C.']
patterns = [nlp(text) for text in terminology_list]
matcher.add('TerminologyList', None, *patterns)

doc = nlp(u"German Chancellor Angela Merkel and US President Barack Obama "
u"converse in the Oval Office inside the White House in Washington, D.C.")
matches = matcher(doc)

关于python - 如何将句子拆分成相关的词(术语提取)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48913352/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com