当前位置:   article > 正文

rasa_nlu踩坑经历_rasa数据训练中可能遇到的困难

rasa数据训练中可能遇到的困难

需要使用rasa_nlu来搭建对话程序,但是介于“人见人爱”的tensorflow总喜欢给新老用户一些“不一样”的感受,再加上sara_nlu的维护者貌似还没有更新tensorflow2.X下的库,所以如果你像笔者一样,直接安装tensorflow的最新版本,那么直接运行一下程序可能会报错:

from rasa_nlu.training_data import load_data
from rasa_nlu.model import Trainer
from rasa_nlu import config
from rasa_nlu.model import Interpreter

def train_horoscopebot(data_json, config_file, model_dir):
    training_data = load_data(data_json)
    trainer = Trainer(config.load(config_file))
    trainer.train(training_data)
    model_directory = trainer.persist(model_dir,
                                      fixed_model_name="horoscopebot")

def predict_intent(text):
    interpreter = Interpreter.load("./models/nlu/default/horoscopebot")
    print(Interpreter.parse(text))

train_horoscopebot("./data/data.json", "./config.json", "./model/nlu")

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

然后报错一堆=_=,错误信息为无法找到tensorflow的某些方法,很显然是tensorflow版本的锅…

  • 解决方法1:如果你是Python3.6-的玩家,那么可以考虑安装版本号低于2.0的tensorflow。那里会有rasa_nlu源代码中所需的对应方法。
  • 解决方法2:直接修改rasa_nlu报错的源码。这个不困难,因为你完全可以根据报错再面向CSDN编程修改那些被官方丢弃的tensorflow的方法。此处仅仅呈现我遇到的错误的修改方法:

23行 AttributeError: module ‘tensorflow’ has no attribute ‘set_random_seed’
解决方法: 23行的import tensorflow as tf 改成

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()  
  • 1
  • 2

278行 AttributeError: module ‘tensorflow.compat.v1’ has no attribute ‘contrib’
解决方法:278行的 reg = tf.contrib.layers.l2_regularizer(self.C2) 改成

 reg = tf.nn.l2_loss
  • 1

尽管最后又多了一些警告,但是程序可以成功运行了。

......(若干WARNING =_=)
Epochs: 100%|██████████| 300/300 [00:00<00:00, 573.16it/s, loss=0.575, acc=1.000]
  • 1
  • 2

反正是成功运行了,如果嫌WARNING看着烦,可以加入一下语句来屏蔽WARNING

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = "2"
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/343634
推荐阅读
相关标签
  

闽ICP备14008679号