Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ChatterBot错误-OSError:[E941]Can';找不到型号';en';_Python_Python 3.x_Spacy_Chatterbot - Fatal编程技术网

Python ChatterBot错误-OSError:[E941]Can';找不到型号';en';

Python ChatterBot错误-OSError:[E941]Can';找不到型号';en';,python,python-3.x,spacy,chatterbot,Python,Python 3.x,Spacy,Chatterbot,我试着运行我的第一个Chatterbot程序(它来自Chatterbot的PyPi页面),当我运行它时,我得到一个错误。该错误与Spacy有关,但我无法找到解决方案 代码如下: from chatterbot.trainers import ChatterBotCorpusTrainer chatbot = ChatBot('Ron Obvious') trainer = ChatterBotCorpusTrainer(chatbot) trainer.train("chatte

我试着运行我的第一个Chatterbot程序(它来自Chatterbot的PyPi页面),当我运行它时,我得到一个错误。该错误与Spacy有关,但我无法找到解决方案

代码如下:

from chatterbot.trainers import ChatterBotCorpusTrainer

chatbot = ChatBot('Ron Obvious')

trainer = ChatterBotCorpusTrainer(chatbot)

trainer.train("chatterbot.corpus.english")

chatbot.get_response("Hello, how are you today?")
下面是错误:

Traceback (most recent call last):
  File "c:/users/USER/desktop/bot.py", line 77, in <module>
    chatbot = ChatBot('Ron Obvious')
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\chatterbot.py", line 28, in __init__
    self.storage = utils.initialize_class(storage_adapter, **kwargs)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\utils.py", line 33, in initialize_class
    return Class(*args, **kwargs)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\storage\sql_storage.py", line 20, in __init__
    super().__init__(**kwargs)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\storage\storage_adapter.py", line 21, in __init__
    'tagger_language', languages.ENG
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\tagging.py", line 13, in __init__
    self.nlp = spacy.load(self.language.ISO_639_1.lower())
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy\__init__.py", line 47, in load
    return util.load_model(name, disable=disable, exclude=exclude, config=config)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy\util.py", line 328, in load_model
    raise IOError(Errors.E941.format(name=name, full=OLD_MODEL_SHORTCUTS[name]))
OSError: [E941] Can't find model 'en'. It looks like you're trying to load a model from a shortcut, which is deprecated as of spaCy v3.0. To load the model, use its full name instead:

nlp = spacy.load("en_core_web_sm")

For more details on the available models, see the models directory: https://spacy.io/models. If you want to create a blank model, use spacy.blank: nlp = spacy.blank("en")
回溯(最近一次呼叫最后一次):
文件“c:/users/USER/desktop/bot.py”,第77行,在
chatbot=chatbot('Ron显而易见')
文件“C:\Users\USER\AppData\Local\Programs\Python37\lib\site packages\chatterbot\chatterbot.py”,第28行,在\uuu init中__
self.storage=utils.initialize_类(存储_适配器,**kwargs)
初始化类中的文件“C:\Users\USER\AppData\Local\Programs\Python37\lib\site packages\chatterbot\utils.py”,第33行
返回类(*args,**kwargs)
文件“C:\Users\USER\AppData\Local\Programs\Python37\lib\site packages\chatterbot\storage\sql\u storage.py”,第20行,在u init中__
超级()
文件“C:\Users\USER\AppData\Local\Programs\Python37\lib\site packages\chatterbot\storage\storage\u adapter.py”,第21行,在u init中__
“tagger_语言”,languages.ENG
文件“C:\Users\USER\AppData\Local\Programs\Python37\lib\site packages\chatterbot\tagging.py”,第13行,在uu init中__
self.nlp=spacy.load(self.language.ISO_639_1.lower())
文件“C:\Users\USER\AppData\Local\Programs\Python37\lib\site packages\spacy\\uuuuuu init\uuuuuu.py”,第47行,已加载
return util.load_model(name,disable=disable,exclude=exclude,config=config)
文件“C:\Users\USER\AppData\Local\Programs\Python37\lib\site packages\spacy\util.py”,第328行,在load\u模型中
raise IOError(Errors.E941.format(name=name,full=OLD\u MODEL\u快捷方式[name]))
OSError:[E941]找不到型号“en”。看起来您正试图从快捷方式加载模型,该快捷方式在spaCy v3.0中已被弃用。要加载模型,请改用其全名:
nlp=spacy.load(“en_core\u web\u sm”)
有关可用模型的更多详细信息,请参阅模型目录:https://spacy.io/models. 如果要创建空白模型,请使用spacy.blank:nlp=spacy.blank(“en”)

如果有人能找到解决办法,这将是很有帮助的。谢谢。

确保您实际安装了正确的spacy型号。例如,在终端中使用
python-mspacy download en\u core\u web\u sm
命令安装
en\u core\u web\u sm

接下来,修复此错误:

File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\tagging.py", line 13, in __init__
    self.nlp = spacy.load(self.language.ISO_639_1.lower())
就是

  • 打开
    C:\Users\USER\AppData\Local\Programs\Python37\lib\site packages\chatterbot\tagging.py
    文件
  • 去13号线
  • 将self.nlp=spacy.load(self.language.ISO_639_1.lower())替换为
  • 如果self.language.ISO_639_1.lower()
    self.nlp=spacy.load('en\u core\u web\u sm')
    其他:
    self.nlp=spacy.load(self.language.ISO_639_1.lower())
    

    您需要为需要支持的其他语言添加更多条件。

    我更改了代码,但问题是相同的

    我不明白这个

    回溯(最近一次呼叫最后一次): 文件“testapp.py”,第4行,在 chatbot=chatbot('Toni') 文件“/home/interc3/virtualenv/toni/3.7/lib/python3.7/site packages/chatterbot/chatterbot.py”,第28行,在init self.storage=utils.initialize_类(存储_适配器,**kwargs) 初始化类中的文件“/home/interc3/virtualenv/toni/3.7/lib/python3.7/site packages/chatterbot/utils.py”,第33行 返回类(*args,**kwargs) 文件“/home/interc3/virtualenv/toni/3.7/lib/python3.7/site packages/chatterbot/storage/sql_storage.py”,第20行,在init super().init(**kwargs) 文件“/home/interc3/virtualenv/toni/3.7/lib/python3.7/site packages/chatterbot/storage/storage_adapter.py”,第21行,在init “tagger_语言”,languages.ENG 文件“/home/interc3/virtualenv/toni/3.7/lib/python3.7/site packages/chatterbot/tagging.py”,第22行,在init self.nlp=spacy.load(self.language.ISO_639_1.lower()) 文件“/home/interc3/virtualenv/toni/3.7/lib/python3.7/site packages/spacy/init.py”,第47行,已加载 return util.load_model(name,disable=disable,exclude=exclude,config=config) 文件“/home/interc3/virtualenv/toni/3.7/lib/python3.7/site packages/spacy/util.py”,第328行,加载模式 raise IOError(Errors.E941.format(name=name,full=OLD\u MODEL\u快捷方式[name])) OSError:[E941]找不到型号“en”。看起来您正试图从快捷方式加载模型,该快捷方式在spaCy v3.0中已被弃用。要加载模型,请改用其全名:

    nlp=spacy.load(“en_core\u web\u sm”)

    有关可用模型的更多详细信息,请参阅模型目录:。如果要创建空白模型,请使用spacy.blank:nlp=spacy.blank(“en”)

    。。。。。。。。在我不明白的情况下。。。。。 有关可用模型的更多详细信息,请参阅模型目录:

    我需要什么型号的?????我不知道。。。。(可能是美国模特小姐

    查看代码taggng.py

    #supuestamente arreglado
    import string
    from chatterbot import languages
    import spacy
    
    
    class PosLemmaTagger(object):
    
        def __init__(self, language=None):
            self.language = language or languages.ENG
    
            self.punctuation_table = str.maketrans(dict.fromkeys(string.punctuation))
    
            if self.language.ISO_639_1.lower() == 'en':
                self.nlp = spacy.load('en_core_web_sm')
            else:
                self.nlp = spacy.load(self.language.ISO_639_1.lower())
        
            if self.language.ISO_639_1.lower() == 'es':
                self.nlp = spacy.load('es_core_news_sm')
            else:
                self.nlp = spacy.load(self.language.ISO_639_1.lower())
    
            if self.language.ISO_639_1.lower() == 'xx':
                self.nlp = spacy.load('xx_ent_wiki_sm')
            else:
                self.nlp = spacy.load(self.language.ISO_639_1.lower())
    
        def get_bigram_pair_string(self, text):
            """
            Return a string of text containing part-of-speech, lemma pairs.
            """
            bigram_pairs = []
    
            if len(text) <= 2:
                text_without_punctuation = text.translate(self.punctuation_table)
                if len(text_without_punctuation) >= 1:
                    text = text_without_punctuation
    
            document = self.nlp(text)
    
            if len(text) <= 2:
                bigram_pairs = [
                    token.lemma_.lower() for token in document
                ]
            else:
                tokens = [
                    token for token in document if token.is_alpha and not token.is_stop
                ]
    
                if len(tokens) < 2:
                    tokens = [
                        token for token in document if token.is_alpha
                    ]
    
                for index in range(1, len(tokens)):
                    bigram_pairs.append('{}:{}'.format(
                        tokens[index - 1].pos_,
                        tokens[index].lemma_.lower()
                    ))
    
            if not bigram_pairs:
                bigram_pairs = [
                    token.lemma_.lower() for token in document
                ]
    
            return ' '.join(bigram_pairs)
    
    #supuestamente arreglado
    导入字符串
    从chatterbot导入语言
    进口空间
    类poslemmatager(对象):
    定义初始化(self,语言=None):
    self.language=language或languages.ENG
    self.percentration_table=str.maketrans(dict.fromkeys(string.percentration))
    如果self.language.ISO_639_1.lower()
    self.nlp=spacy.load('en\u core\u web\u sm')
    其他:
    self.nlp=spacy.load(self.language.ISO_639_1.lower())
    如果self.language.ISO_639_1.lower()
    self.nlp=spacy.load('es\u core\u news\u sm')
    其他:
    self.nlp=spacy.load(self.language.ISO_639_1.lower())
    如果self.language.ISO_639_1.lower()
    self.nlp=spacy.load('xx\u ent\u wiki\u sm')
    其他:
    self.nlp=spacy.load(self.language.ISO_639_1.lower())
    def get_bigram_pair_字符串(self,text):
    """
    返回包含词性、引理对的文本字符串。
    """
    
     python -m spacy download en_core_web_sm
    
    nlp = spacy.load("en_core_web_sm")
    
    python -m spacy link en_core_web_sm en
    
    import spacy
    from spacy.cli.download import download
    download(model="en_core_web_sm")
    
    self.nlp = spacy.load(self.language.ISO_639_1.lower()) 
    
      if self.language.ISO_639_1.lower() == 'en':
         self.nlp = spacy.load('en_core_web_sm')
      else:
        self.nlp = spacy.load(self.language.ISO_639_1.lower())