【发布时间】:2019-02-11 23:35:19
【问题描述】:
有人可以帮忙吗。
我正在尝试使用 Spacy 对文档进行标记,从而对命名实体进行标记。例如:
'纽约是美国的一个城市'
将被标记为:
['New York', 'is', 'a', 'city', 'in', 'the', 'United States of America']
非常欢迎任何有关如何执行此操作的提示。看过使用 span.merge(),但没有成功,但我是编码新手,所以可能错过了一些东西。
提前谢谢你
【问题讨论】:
-
到目前为止你有什么代码?您是否使用 Spacy 的 NER 标记功能来识别实体令牌的开始和结束?
-
我已经取得了一些进展,代码如下: import spacy from spacy.pipeline import merge_entities print('setting up pipeline') coref_nlp = spacy.load('en_coref_md') spacy_nlp = spacy. load('en_core_web_sm') spacy_nlp.add_pipe(merge_entities) spacy_nlp.add_pipe(spacy_nlp.create_pipe('sentencizer')) doc = '纽约是美国的一个城市。这是一个令人兴奋的地方' print('applying pipelines') new_doc = spacy_nlp(coref_nlp(doc)._.coref_resolved) # 用根引用替换共同引用实体
-
这是它的标记化方式: doc_array = [] print('Tokenizing document') for sentence in new_doc.sents: doc_array.append([(token.text).lower() for token in句子 if (not token.is_stop and token.pos_ != "PUNCT" and token.text != '\n')]) print(doc_array)
-
您对如何改进有任何想法吗?我要分析的主要文件是乔治·布什 9/11 后的演讲:millercenter.org/the-presidency/presidential-speeches/…
-
请编辑您的问题以包含您粘贴在 cmets 中的代码,使用正确的降价将其格式化为代码。粘贴在 cmets 中的代码很难审查。如果您正确格式化代码并添加到您的问题中,获得好的答案的可能性会更高。
标签: nlp tokenize spacy named-entity-recognition