gpt4 book ai didi

python - 类型错误 : __init__() got multiple values for keyword argument 'encoding'

转载 作者:行者123 更新时间:2023-12-01 09:31:41 26 4
gpt4 key购买 nike

from nltk.tag.stanford import CoreNLPNERTagger as POSTagger
english_postagger = POSTagger(RESOURCES_DIR+'jars/english-left3words-distsim.tagger',RESOURCES_DIR+'jars/stanford-postagger.jar', encoding='utf-8')

当我运行上面的代码时,出现以下错误。如何解决这个问题?

Traceback (most recent call last):
File "ILPMod.py", line 44, in <module>
english_postagger = POSTagger(RESOURCES_DIR+'jars/english-left3words-distsim.tagger',RESOURCES_DIR+'jars/stanford-postagger.jar', encoding='utf-8')
TypeError: __init__() got multiple values for keyword argument 'encoding'

最佳答案

CoreNLPNERTagger您导入为 POSTagger 的接口(interface)与 StanfordPOSTagger 具有不同的接口(interface)。来自文档:

class nltk.tag.stanford.CoreNLPNERTagger(url='http://localhost:9000',
encoding='utf8')

Bases: nltk.tag.stanford.CoreNLPTagger

This is a subclass of the CoreNLPTagger that wraps around the nltk.parse.CoreNLPParser for Named-Entity tagging.

>>> from nltk.tag.stanford import CoreNLPNERTagger
>>> CoreNLPNERTagger(url='http://localhost:9000').tag('Rami Eid is studying at Stony Brook University in NY'.split()) [('Rami', 'PERSON'),('Eid', 'PERSON'), ('is', 'O'), ('studying', 'O'), ('at', 'O'), ('Stony', 'ORGANIZATION'), ('Brook', 'ORGANIZATION'), ('University', 'ORGANIZATION'), ('in', 'O'), ('NY', 'O')]

对于CoreNLPNERTagger,您应该首先启动一个核心 NLP 服务器并像这样连接到它:

with CoreNLPServer(port=9000) as server:
tagger = CoreNLPNERTagger(url=server.url)
tagger.tag(...)

或者按照您当前尝试的方式简单地使用 StanfordPOSTagger

关于python - 类型错误 : __init__() got multiple values for keyword argument 'encoding' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49913065/

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