AttributeError:模块'keras.backend'没有属性'_BACKEND'

时间:2019-11-12 22:56:01

标签: python tensorflow keras rasa-nlu rasa

我正在关注一本有关构建聊天机器人的书,并在尝试开始交互式学习时继续遇到此错误。

完整的错误是这样的:

  

回溯(最近通话最近):     文件“ train_initialize.py”,第18行,在       代理=代理(“ horoscope_domain.yml”,策略= [MemoizationPolicy(),KerasPolicy()])      init 中的文件“ C:\ Users \ Max \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ rasa_core \ policies \ keras_policy.py”,第31行       如果KerasPolicy.is_using_tensorflow()而不是图形:     is_using_tensorflow中第48行的文件“ C:\ Users \ Max \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ rasa_core \ policies \ keras_policy.py”       return keras.backend._BACKEND ==“张量流”   AttributeError:模块'keras.backend'没有属性'_BACKEND'

我的代码看起来像这样 '''

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from rasa_core import utils
import tensorflow.keras.backend
from rasa_core.agent import Agent
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core.policies.memoization import MemoizationPolicy
from rasa_core.policies.sklearn_policy import SklearnPolicy

if __name__ == '__main__':
    utils.configure_colored_logging(loglevel="DEBUG")

    training_data_file = './data/stories.md'
    model_path = './models/dialogue'
    agent = Agent("horoscope_domain.yml", policies = [MemoizationPolicy(), KerasPolicy()])

    training_data = agent.load_data(training_data_file)

    agent.train(training_data, augmentation_factor = 50, epochs = 500, batch_size = 10, validation_split = 0.2)
    agent.persist(model_path)

'''

1 个答案:

答案 0 :(得分:0)

看起来像过时的API代码;打开错误跟踪中的文件,并用._BACKEND替换.backend()

# In "C:\Users\Max\AppData\Local\Programs\Python\Python37\lib\site-packages
# \rasa_core\policies\keras_policy.py", line 48:

# return keras.backend._BACKEND == "tensorflow" # <-- DELETE
return keras.backend.backend() == "tensorflow"  # <-- PASTE