我正在使用 Spacy 以及一些自定义代码来进行一些自然语言处理工作。我们想做一些事情,我们可以通过使用论文中的位置来找到论文的撰写位置,并且很好奇是否有一个包可以找到国家、城市、州等位置?感谢您抽出时间。
最佳答案
Spacy 拥有命名实体识别 (NER)。预训练模型具有的一种实体类型是 LOC
(位置)。某些模型中还包含GPE
(地缘政治实体)。我下面使用的 en_core_web_sm
同时具有 LOC
和 GPE
。 (完整列表位于https://spacy.io/api/annotation#named-entities)。另请参阅: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
关于python - 是否有 NLP 包或函数知道或可以从文档中找到位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59327441/