是否有 NLP 包或函数知道或可以从文档中找到位置?
Is there a NLP package or function that knows or can find locations from a document?
我正在使用 Spacy 以及一些自定义代码来为工作做一些自然语言处理。我们想做一些事情,我们可以通过使用论文中的位置找到论文的写作地点,并且很好奇是否有一个包可以找到国家、城市、州等位置?感谢您的宝贵时间。
Spacy 已命名实体识别 (NER)。预训练模型具有的一种实体类型是 LOC
位置。某些模型中还有 GPE
(地缘政治实体)。我在下面使用的 en_core_web_sm
有 LOC
和 GPE
。 (完整列表在 https://spacy.io/api/annotation#named-entities). See also: https://spacy.io/usage/linguistic-features#named-entities
开箱即用不会很完美,但可能会有用。
最小示例:
import spacy # install cmd: pip3 install spacy --user
import en_core_web_sm # install cmd: python3 -m spacy download en_core_web_sm --user
text='San Fransisco is in California and my friend Frank lives there, close to the bay. He purchased his first house last January.'
NLP = en_core_web_sm.load()
output = NLP(text)
for item in output.ents:
print(item.label_, item)
有这个输出:
GPE San Fransisco
GPE California
PERSON Frank
DATE last January
我正在使用 Spacy 以及一些自定义代码来为工作做一些自然语言处理。我们想做一些事情,我们可以通过使用论文中的位置找到论文的写作地点,并且很好奇是否有一个包可以找到国家、城市、州等位置?感谢您的宝贵时间。
Spacy 已命名实体识别 (NER)。预训练模型具有的一种实体类型是 LOC
位置。某些模型中还有 GPE
(地缘政治实体)。我在下面使用的 en_core_web_sm
有 LOC
和 GPE
。 (完整列表在 https://spacy.io/api/annotation#named-entities). See also: https://spacy.io/usage/linguistic-features#named-entities
开箱即用不会很完美,但可能会有用。
最小示例:
import spacy # install cmd: pip3 install spacy --user
import en_core_web_sm # install cmd: python3 -m spacy download en_core_web_sm --user
text='San Fransisco is in California and my friend Frank lives there, close to the bay. He purchased his first house last January.'
NLP = en_core_web_sm.load()
output = NLP(text)
for item in output.ents:
print(item.label_, item)
有这个输出:
GPE San Fransisco
GPE California
PERSON Frank
DATE last January