Giter VIP home page Giter VIP logo

rasa_ch_faq's Introduction

rasa_ch_bot

RASA 实现 RASA Bot 后端。 能够回答关于 RASA 的问题,以及一些例子。 欢迎大家多提 RASA 相关的问题,或者想看的示例,我会补充在这里。

前端地址: 这里

功能更新

  • [2021-08-04] 增加 onnx + 量化(用于提高特征提取的速度)的 feature 提取组件 # 一些注意事项
  • [2021-06-24] 增加知图谱的接入(放在GRAPH分支了)
  • [2021-06-01] 增加文本纠错 pipeline (由于 demo 较慢,默认未开启,如何开启?)
  • [2021-05-20] AlbertFeaturizer (在dev分支)
  • [2021-05-13] 增加按钮 demo
  • [2021-05-11] 支持查看 BTC 行情
  • [2021-05-08] 支持 吸猫\狗\狐狸。支持 根据图片搜索动漫出处。
  • [2021-05-06] 支持 找饭店 demo。
  • [2021-04-13] 实现追问demo,实现细节

部分功能展示

FAQ

grtKwF.gif

天气查询及BTC查询功能

grtGS1.gif

吸动物

grt2m8.gif

搜动漫

grtUeO.gif

知识图谱

RQE8gA.gif

支持的问题列表

请参见: 问题列举

一些配置

分词使用的 bert, 自定义了 tokenizers

如何运行

由于使用了 bert_chinese, 所以 需要下载 bert_chinese 模型。 并放到 pre_models 文件夹中,重命名为 tf_model.h5 命令执行:

curl -L https://www.flyai.com/m/bert-base-chinese-tf_model.h5 -o pre_models/tf_model.h5
rasa train

一些文件说明

run.py  # 相当于运行 rasa run
train.py  # == rasa train
run_action_server.py  # == rasa run actions
load_model.py   # 直接加载并运行模型,与 server 无关。(需要先训练好一个模型) 

一些工具

back_translation.py  # 回译脚本
# 使用方式
python back_translation.py 需要回译的文本

ONNX注意事项

1. 使用说明

config 更改为:

  - name: compoments.nlu.featurizer.lm_featurizer.OnnxLanguageModelFeaturizer
    cache_dir: ./tmp
    model_name: bert
    model_weights: pre_models
    onnx: false  # 是否开启 onnx
    quantize: true  # 是否使用量化

下载 torch 的模型

curl -L https://www.flyai.com/m/bert-base-chinese-pytorch_model.bin -o pre_models/pytorch_model.bin

2. 依赖安装

pip install torch==1.9.0 transformers==4.8.2 onnx==1.9.0 onnxruntime==1.8.0 onnxruntime-tools==1.7.0 psutil==5.8.0

3. 一些注释

  1. 速度能提升多少, 可以参考这篇文章
  2. 量化后 速度有额外提升,但是效果可能会变差,需要根据语料调整
  3. 如何测试效果并查看结果
rasa train nlu && rasa test nlu
cat results/intent_errors.json
  1. 为什么没有用 tensorflow 用来做 onnx 尝试多次,都失败了,暂时未找到解决办法(输入的纬度不匹配),如果有人成功了,可以告诉我!!感谢!!!🙏

从零开始搭建机器人

1. 下载项目并进入

git clone https://github.com/Dustyposa/rasa_ch_faq.git 
cd rasa_ch_faq

2. 安装依赖

pip install -r requirements.txt
curl -L https://www.flyai.com/m/bert-base-chinese-tf_model.h5 -o pre_models/tf_model.h5
rasa train

ps: 注意 python 版本 37+

3. 训练模型

rasa train

4. 运行机器人

需要开两个 shell/iterm 第一个:

rasa shell

第二个:

rasa run actions

然后就可以在第一个 shell 窗口对话了

从 1 开始搭建机器人

这个是干啥的?如果第一个你已经会了,我们加点前端展示的,效果参看这里

1. 下载前端项目并进入

git clone -#-depth 1 https://github.com/Dustyposa/rasa_bot_front
cd rasa_bot_front

2. 启动前端

参照文档

3. 启动 rasa

同样是两个 shell/iterm,第一个命令稍有不同:

rasa run --cors "*"

第二个:

rasa run actions

rasa_ch_faq's People

Contributors

dustyposa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rasa_ch_faq's Issues

python train.py 报错,麻烦帮看下啥问题

Some layers from the model checkpoint at pre_models were not used when initializing TFBertModel: ['mlm___cls', 'nsp___cls']

  • This IS expected if you are initializing TFBertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
  • This IS NOT expected if you are initializing TFBertModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
    All the layers of TFBertModel were initialized from the model checkpoint at pre_models.
    If your task is similar to the task the model of the checkpoint was trained on, you can already use TFBertModel for predictions without further training.
    2021-01-29 19:33:57.271548: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at einsum_op_impl.h:714 : Resource exhausted: OOM when allocating tensor with shape[64,12,218,218] and type float on /job:localhost/replica:0/task:0/device:CPU:0 by allocator cpu
    Traceback (most recent call last):
    File "train.py", line 6, in
    training_files="data",
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/train.py", line 109, in train
    loop,
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/utils/common.py", line 308, in run_in_loop
    result = loop.run_until_complete(f)
    File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/train.py", line 174, in train_async
    finetuning_epoch_fraction=finetuning_epoch_fraction,
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/train.py", line 353, in _train_async_internal
    finetuning_epoch_fraction=finetuning_epoch_fraction,
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/train.py", line 396, in _do_training
    finetuning_epoch_fraction=finetuning_epoch_fraction,
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/train.py", line 818, in _train_nlu_with_validated_data
    **additional_arguments,
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/nlu/train.py", line 116, in train
    interpreter = trainer.train(training_data, **kwargs)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/nlu/model.py", line 209, in train
    updates = component.train(working_data, self.config, **context)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py", line 814, in train
    batch_docs = self._get_docs_for_batch(batch_messages, attribute)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py", line 767, in _get_docs_for_batch
    batch_token_ids, batch_tokens, batch_examples, attribute, inference_mode
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py", line 685, in _get_model_features_for_batch
    batch_attention_mask, padded_token_ids
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py", line 537, in _compute_batch_sequence_features
    np.array(padded_token_ids), attention_mask=np.array(batch_attention_mask)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 985, in call
    outputs = call_fn(inputs, *args, **kwargs)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/transformers/models/bert/modeling_tf_bert.py", line 901, in call
    training=inputs["training"],
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 985, in call
    outputs = call_fn(inputs, *args, **kwargs)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/transformers/models/bert/modeling_tf_bert.py", line 694, in call
    training=inputs["training"],
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 985, in call
    outputs = call_fn(inputs, *args, **kwargs)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/transformers/models/bert/modeling_tf_bert.py", line 452, in call
    hidden_states, attention_mask, head_mask[i], output_attentions, training=training
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 985, in call
    outputs = call_fn(inputs, *args, **kwargs)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/transformers/models/bert/modeling_tf_bert.py", line 418, in call
    hidden_states, attention_mask, head_mask, output_attentions, training=training
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 985, in call
    outputs = call_fn(inputs, *args, **kwargs)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/transformers/models/bert/modeling_tf_bert.py", line 354, in call
    input_tensor, attention_mask, head_mask, output_attentions, training=training
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 985, in call
    outputs = call_fn(inputs, *args, **kwargs)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/transformers/models/bert/modeling_tf_bert.py", line 288, in call
    attention_scores = tf.einsum("aecd,abcd->acbe", key_layer, query_layer)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/tensorflow/python/util/dispatch.py", line 201, in wrapper
    return target(*args, **kwargs)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/tensorflow/python/ops/special_math_ops.py", line 684, in einsum
    return _einsum_v2(equation, *inputs, **kwargs)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/tensorflow/python/ops/special_math_ops.py", line 1113, in _einsum_v2
    return gen_linalg_ops.einsum(inputs, resolved_equation)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/tensorflow/python/ops/gen_linalg_ops.py", line 1088, in einsum
    _ops.raise_from_not_ok_status(e, name)
    File "/root/anaconda3/envs/rasa/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 6843, in raise_from_not_ok_status
    six.raise_from(core._status_to_exception(e.code, message), None)
    File "", line 3, in raise_from
    tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[64,12,218,218] and type float on /job:localhost/replica:0/task:0/device:CPU:0 by allocator cpu [Op:Einsum]

RASA提问,增加RASA FAQ的语料库

想到一个加一个吧。

  • 1. rasa run和rasa run actions的区别?
  • 2. Rasa和RasaX的区别?
  • 3. Rasa在何处调用Bert?
  • 4. 回译文本工具的作用是什么?
  • 5. API的形式调用Rasa的地址是多少以及需要传递什么参数?(答案)

训练时间过长

当nlu的语料>20000条,训练的时候,如果不用ONNX模型花费的时间为15分钟,使用ONNX模型需要花费2个多小时,即使用GPU也是这样,这个有什么优化方法吗?

企业微信截图_16448316568471

多轮对话确定一个推荐,怎么实现?

多轮对话确定一个推荐,怎么实现?
人:你好
AI:你好
人:我要找大学
AI:你什么学历
人:高中
AI:你什么年龄
人:18岁
AI:你想读什么专业
人:计算机
AI:你想再什么地区
人:北京
AI:推荐你北京大学

如果要实现多轮条件合并才能推出结果,怎么实现呢?

关于前端文件的使用

我使用了您开源出来的前端项目,另外我没有使用 npm 部署前端服务, 而是直接使用了您给出的命令行: --cors "*" 加载了这个前端文件。但是我有一个问题:

  1. rasa 的 core 服务是如何和这个前端服务打通的,也就是说,打开前端后,我每次从前端输入的一句话是如何进入到 rasa 内部中,并且 rasa 可以维持住这个对话的状态的。
  2. 这个问题基础上面的第一点,因为我现在有一个训练好的 rasa 服务,但是我需要把这个服务添加(或者说引入)到一个目前现有的聊天对话页面中,我应该如何做呢?

还请您不吝赐教。期待得到您的回复,我的 VX:18336304089
如果您愿意提供帮助,我愿意有偿获得您的指导与帮助。

运行rasa train时报错显示OSError

运行rasa train时报错,报错信息如下:
Traceback (most recent call last):
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/transformers/modeling_tf_utils.py", line 1232, in from_pretrained
missing_keys, unexpected_keys = load_tf_weights(model, resolved_archive_file)
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/transformers/modeling_tf_utils.py", line 459, in load_tf_weights
with h5py.File(resolved_archive_file, "r") as f:
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/h5py/_hl/files.py", line 406, in init
fid = make_fid(name, mode, userblock_size,
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/h5py/_hl/files.py", line 173, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5f.pyx", line 88, in h5py.h5f.open
OSError: Unable to open file (file signature not found)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/anaconda3/envs/rasa/bin/rasa", line 8, in
sys.exit(main())
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/main.py", line 117, in main
cmdline_arguments.func(cmdline_arguments)
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/cli/train.py", line 59, in
train_parser.set_defaults(func=lambda args: run_training(args, can_exit=True))
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/cli/train.py", line 91, in run_training
training_result = train_all(
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/api.py", line 109, in train
return rasa.utils.common.run_in_loop(
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/utils/common.py", line 296, in run_in_loop
result = loop.run_until_complete(f)
File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/model_training.py", line 108, in train_async
return await _train_async_internal(
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/model_training.py", line 289, in _train_async_internal
await _do_training(
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/model_training.py", line 335, in _do_training
model_path = await _train_nlu_with_validated_data(
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/model_training.py", line 759, in _train_nlu_with_validated_data
await rasa.nlu.train.train(
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/nlu/train.py", line 97, in train
trainer = Trainer(
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/nlu/model.py", line 167, in init
self.pipeline = self._build_pipeline(cfg, component_builder)
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/nlu/model.py", line 178, in _build_pipeline
component = component_builder.create_component(component_cfg, cfg)
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/nlu/components.py", line 938, in create_component
component = registry.create_component_by_config(component_config, cfg)
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/nlu/registry.py", line 193, in create_component_by_config
return component_class.create(component_config, config)
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py", line 105, in create
return cls(component_config, hf_transformers_loaded=hf_transformers_loaded)
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/rasa/nlu/featurizers/dense_featurizer/lm_featurizer.py", line 88, in init
self._load_model_instance(skip_model_load)
File "/Users/wenhk/Downloads/rasa_ch_faq/compoments/nlu/featurizer/lm_featurizer.py", line 83, in _load_model_instance
self.model = model_class_dict[self.model_name].from_pretrained(
File "/Users/anaconda3/envs/rasa/lib/python3.8/site-packages/transformers/modeling_tf_utils.py", line 1234, in from_pretrained
raise OSError(
OSError: Unable to load weights from h5 file. If you tried to load a TF 2.0 model from a PyTorch checkpoint, please set from_pt=True.

请问这是什么问题?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.