gpt4 book ai didi

python - 如何使用python删除语料库中的人名

转载 作者:行者123 更新时间:2023-12-03 08:32:25 25 4
gpt4 key购买 nike

我找了很长时间,找到的大部分资料都是名为识别的实体。我正在运行主题建模,但在我的数据中,文本中有太多名字。
有没有包含(英文)人名的Python库?或者如果没有,从语料库中的每个文档中删除人名的好方法是什么?这是一个简单的例子:

texts=['Melissa\'s home was clean and spacious. I would love to visit again soon.','Kevin was nice and Kevin\'s home had a huge parking spaces.'] 

最佳答案

我建议使用具有一定能力的分词器来识别和区分专有名词。 spacy 非常通用,它的默认分词器在这方面做得很好。

将名称列表当作停用词使用是有危险的 - 让我举例说明:

import spacy
import pandas as pd
nlp = spacy.load("en_core_web_sm")
texts=["Melissa's home was clean and spacious. I would love to visit again soon.",
"Kevin was nice and Kevin's home had a huge parking spaces."
"Bill sold a work of art to Art and gave him a bill"]
tokenList = []
for i, sentence in enumerate(texts):
doc = nlp(sentence)
for token in doc:
tokenList.append([i, token.text, token.lemma_, token.pos_, token.tag_, token.dep_])
tokenDF = pd.DataFrame(tokenList, columns=["i", "text", "lemma", "POS", "tag", "dep"]).set_index("i")

所以前两句很简单,spacy识别了专有名词“PROPN”: enter image description here

现在,第三句话的构造是为了说明这个问题 - 很多人的名字也是事物。 spacy 的默认分词器并不完美,但它在任务的两个方面都做了值得尊敬的工作:当名称用作常规单词(例如 cargo list 、艺术品)时,不要删除名称,并识别它们当它们被用作名称时。 (您可以看到它弄乱了对艺术(人)的引用之一。

enter image description here

关于python - 如何使用python删除语料库中的人名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64741609/

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