Git Product home page Git Product logo

_rasa_chatbot's Introduction

note:

项目已跟进到rasa新版本,一些新特性后面尝试后补充。rasa 版本更新太快,本项目滞后最新版本较大,仅供参考,建议根据需要阅读最新rasa文档。

rasa_chatbot

A Chinese task oriented chatbot in IVR(Interactive Voice Response) domain, Implement by rasa nlu and rasa core. This is a demo with toy dataset.

install dependency:

python3

install or update to python 3

install rasa_core, this will install rasa nlu too, and now support chinese.

pip install rasa_core==0.9.0

this command will install rasa nlu too.

install sklearn and MITIE

pip install -U scikit-learn sklearn-crfsuite
pip install git+https://github.com/mit-nlp/MITIE.git

dir tree

_rasa_chatbot/
├── bot.py
├── chat_detection
├── data
│   ├── mobile_nlu_data.json # train data json format
│   ├── mobile_raw_data.txt # train data raw
│   ├── mobile_story.md # toy dialogue train data 
│   └── total_word_feature_extractor.dat # pretrained mitie word vector
├── httpserver.py # rasa nlu httpserver
├── __init__.py
├── INSTALL.md
├── ivr_chatbot.yml # rasa nlu config file
├── mobile_domain.yml # rasa core config file
├── projects # pretrained models
│   ├── dialogue
│   └── ivr_nlu
├── README.md
├── tools # tools of data process
└── train.sh # train script of rasa nlu

train nlu model

sh train.sh

命令运行耗时较长,模型训练完毕生成:

projects/
└── ivr_nlu
    └── demo
        ├── entity_extractor.dat
        ├── entity_synonyms.json
        ├── intent_classifier_sklearn.pkl
        ├── metadata.json
        └── training_data.json

test rasa nlu

$ python httpserver.py
$ curl -X POST localhost:1235/parse -d '{"q":"我的流量还剩多少"}' | python -m json.tool
{
    'q': '我的流量还剩多少', 
    'intent': 'request_search', 
    'entities': {
        'item': '流量'
    }
}

train dialogue

python bot.py train-dialogue

模型训练完毕生成:

projects
├── dialogue
│   ├── domain.json
│   ├── domain.yml
│   ├── policy_0_MemoizationPolicy
│   │   ├── featurizer.json
│   │   └── memorized_turns.json
│   ├── policy_1_KerasPolicy
│   │   ├── featurizer.json
│   │   ├── keras_arch.json
│   │   ├── keras_policy.json
│   │   └── keras_weights.h5
│   ├── policy_metadata.json
│   └── stories.md
└── ivr_nlu

train dialogue in online mode

python bot.py online_train

test

Run command below:

python bot.py run

Example1:

Bot loaded. Type a message and press enter : 
YOU:你是谁
BOT:您好!,我是机器人小热,很高兴为您服务。
YOU:我想看一下消费情况
BOT:您想查询哪个月的消费?
YOU:十月份的
BOT:好,请稍等
BOT:您好,您十月份共消费二十八元。
YOU:好谢谢
BOT:您开心我就开心
BOT:您还想干什么
YOU:没什么了
BOT:Bye, 下次再见

Example2:

Bot loaded. Type a message and press enter : 
YOU:给我看看我上月用了多少话费
BOT:好,请稍等
BOT:您好,您上月共消费二十八元。
BOT:您还想干什么

train word vector

You can train your own MITIE model using following method:

$ git clone https://github.com/mit-nlp/MITIE.git
$ cd MITIE/tools/wordrep
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build . --config Release
$ ./wordrep -e /path/to/your/folder_of_cutted_text_files

/path/to/your/folder_of_cutted_text_files above is a directory path in which has word cutted data files to train. This process may cost one or two days.

_rasa_chatbot's People

Contributors

zqhzy 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

_rasa_chatbot's Issues

python bot.py online_train err

运行 python bot.py online_train err 报错如下
pykwalify.errors.CoreError: <CoreError: error code 3: Unable to load any data from source yaml file: Path: '/'>
请问如何解决

训练rasa nlu模型出现错误

D:\pycharm\pycharmproject\rasa_chatbot_v1>python bot.py train-nlu
No Jieba User Dictionary found.
D:\python3.6\lib\site-packages\sklearn\base.py:311: UserWarning: Trying to unpickle estimator LabelEncoder from version 0.18.1 when using v
ersion 0.19.1. This might lead to breaking code or invalid results. Use at your own risk.
UserWarning)
D:\python3.6\lib\site-packages\sklearn\base.py:311: UserWarning: Trying to unpickle estimator SVC from version 0.18.1 when using version 0.
19.1. This might lead to breaking code or invalid results. Use at your own risk.
UserWarning)
D:\python3.6\lib\site-packages\sklearn\base.py:311: UserWarning: Trying to unpickle estimator GridSearchCV from version 0.18.1 when using v
ersion 0.19.1. This might lead to breaking code or invalid results. Use at your own risk.
UserWarning)
Traceback (most recent call last):
File "bot.py", line 160, in
train_nlu()
File "bot.py", line 107, in train_nlu
from rasa_nlu.converters import load_data
ModuleNotFoundError: No module named 'rasa_nlu.converters'

一个应该是说 No Jieba User Dictionary found.,另一个是ModuleNotFoundError: No module named 'rasa_nlu.converters',我安装的是中文版的rasa nlu 也安装了结巴分词,不知道为啥出现这个问题

python bot.py train-dialogue error

运行python bot.py train-dialogue会get this exception, 然后我把它删掉了:
if kwargs.get('featurizer') or kwargs.get('max_history'):
raise Exception("Passing featurizer and max_history "
"to agent.train(...) is not supported anymore. "
"Pass appropriate featurizer "
"directly to the policy instead. More info "
"https://core.rasa.com/migrations.html#x-to-0-9-0")
但是会得到:
Traceback (most recent call last):
File "bot.py", line 163, in
train_dialogue()
File "bot.py", line 100, in train_dialogue
validation_split=0.2
File "anaconda3/lib/python3.6/site-packages/rasa_core/agent.py", line 264, in train
**kwargs)
File "anaconda3/lib/python3.6/site-packages/rasa_core/policies/ensemble.py", line 72, in train
policy.train(training_trackers, domain, **kwargs)
File "anaconda3/lib/python3.6/site-packages/rasa_core/policies/keras_policy.py", line 146, in train
shuffled_y.shape[1:])
TypeError: model_architecture() missing 1 required positional argument: 'max_history_len'
请问怎么解决啊,感谢🙏

train-dialogue报错

请问什么时候可以更新呢?我是完全按照 README 去做的,目前这个开源代码运行到python bot.py train-dialogue就运行不了了,报错:

Traceback (most recent call last):
  File "/home/jiahang/env/lib/python3.6/site-packages/rasa_nlu/model.py", line 74, in load
    data = utils.read_json_file(metadata_file)
  File "/home/jiahang/env/lib/python3.6/site-packages/rasa_nlu/utils/__init__.py", line 208, in read_json_file
    content = read_file(filename)
  File "/home/jiahang/env/lib/python3.6/site-packages/rasa_nlu/utils/__init__.py", line 202, in read_file
    with io.open(filename, encoding=encoding) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'models/ivr/demo/metadata.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bot.py", line 120, in <module>
    interpreter=RasaNLUInterpreter("models/ivr/demo"),
  File "/home/jiahang/env/lib/python3.6/site-packages/rasa_core/interpreter.py", line 245, in __init__
    self._load_interpreter()
  File "/home/jiahang/env/lib/python3.6/site-packages/rasa_core/interpreter.py", line 261, in _load_interpreter
    self.interpreter = Interpreter.load(self.model_directory)
  File "/home/jiahang/env/lib/python3.6/site-packages/rasa_nlu/model.py", line 288, in load
    model_metadata = Metadata.load(model_dir)
  File "/home/jiahang/env/lib/python3.6/site-packages/rasa_nlu/model.py", line 79, in load
    "from '{}'. {}".format(abspath, e))
rasa_nlu.model.InvalidProjectError: Failed to load model metadata from '/home/jiahang/_rasa_chatbot/models/ivr/demo/metadata.json'. [Errno 2] No such file or directory: 'models/ivr/demo/metadata.json'

之前已经用python -m rasa_nlu.train --config mobile_nlu_model_config.json --data data/mobile_nlu_data.json --path models训练好数据了,求解答。

error about metadata.json

Hi,

Can you tell me how to fix this issue? I can not find metadata.json in project.
Thanks.

C:\Project\RASA_DEMO_rasa_chatbot-master>python bot.py train-nlu
Traceback (most recent call last):
File "C:\python\python3_6_5_64\lib\site-packages\rasa_nlu\model.py", line 56, in load
with io.open(metadata_file, encoding="utf-8") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'models/ivr/demo\metadata.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "bot.py", line 120, in
interpreter=RasaNLUInterpreter("models/ivr/demo"),
File "C:\python\python3_6_5_64\lib\site-packages\rasa_core\interpreter.py", line 219, in init
self._load_interpreter()
File "C:\python\python3_6_5_64\lib\site-packages\rasa_core\interpreter.py", line 238, in _load_interpreter
os.environ))
File "C:\python\python3_6_5_64\lib\site-packages\rasa_nlu\model.py", line 228, in load
model_metadata = Metadata.load(model_dir)
File "C:\python\python3_6_5_64\lib\site-packages\rasa_nlu\model.py", line 62, in load
"from '{}'. {}".format(abspath, e))
rasa_nlu.model.InvalidProjectError: Failed to load model metadata from 'C:\Project\RASA_DEMO_rasa_chatbot-master\models\ivr\demo\metadata.json'. [Errno 2] No such file or directory: 'models/ivr/demo\metadata.json'

运行python bot.py train-nlu出现错误

在rasa.core==0.9.8版本下运行命令时提示错误:ModuleNotFoundError: No module named 'rasa_nlu.converters'
但是无法通过pip进行安装,请问有没有人有解决方式

問題 Got some problem <CoreError: error code 3: ...>

有人遇到 相同的問題 有解決辦法嗎?

我在 python bot.py train-dialogue 後 出現這個問題

pykwalify.errors.CoreError: <CoreError: error code 3: Unable to load any data from source yaml file: Path: '/'>

謝謝各位! Thanks!

How to end a conversation(story) and start a new conversation(story)?

For example, a story may like this:

## Generated Story 1
* greet
    - utter_greet
* log_search{"item": "日志"}
    - slot{"item": "日志"}
    - utter_inform_date
* inform_date{"date": "2018.01.01"}
    - slot{"date": "2018.01.01"}
    - action_log_date_consume
* confirm
    - utter_confirm

Start bot's cmd:

python bot.py run

After this conversation, I don't want to use CTRL-C to end the conversation, but to start a new conversation, how to complete this function? Thx~

yml文件中的coversations如何训练使用

如题,楼主chat_detection\data\chinese_dialogs目录下有很多yml文件,其中都语句对,请问这个文件夹下的数据如何加到bot中去。或者有什么链接介绍如何使用的,给一个也行。谢谢

actions没搞上

NameError: Cannot access action 'action_search_consume', as that name is not a registered action for this domain.
这个怎么解决?

关于MITIE的原始语料

您好,我想问下,您知道哪里可以获取电信领域客服的大量原始语料吗。或者您原先使用的语料现在能否开放?多谢您了

mitie question

python -m rasa_nlu.train --config mobile_nlu_model_config.json --data data/mobile_nlu_data.json --path models

运行的时候,找不到mitie
pip list
发现我已经安装了 mitie

运行这一步时候报错 curl -X POST localhost:1235/parse -d '{"q":"我的流量还剩多少"}' | python -m json.tool请大神帮帮忙看看

2019-05-15 11:15:37+0800 [-] Unhandled Error
Traceback (most recent call last):
File "D:\anaconda\envs\rasa\lib\site-packages\twisted\web\server.py", line 259, in render
body = resrc.render(self)
File "D:\anaconda\envs\rasa\lib\site-packages\klein\resource.py", line 210, in render
d = defer.maybeDeferred(_execute)
File "D:\anaconda\envs\rasa\lib\site-packages\twisted\internet\defer.py", line 151, in maybeDeferred
result = f(*args, **kw)
File "D:\anaconda\envs\rasa\lib\site-packages\klein\resource.py", line 204, in _execute
**kwargs)
--- ---
File "D:\anaconda\envs\rasa\lib\site-packages\twisted\internet\defer.py", line 151, in maybeDeferred
result = f(*args, **kw)
File "D:\anaconda\envs\rasa\lib\site-packages\klein\app.py", line 128, in execute_endpoint
return endpoint_f(self._instance, *args, **kwargs)
File "D:\anaconda\envs\rasa\lib\site-packages\klein\app.py", line 227, in _f
return _call(instance, f, request, *a, **kw)
File "D:\anaconda\envs\rasa\lib\site-packages\klein\app.py", line 50, in _call
result = f(*args, **kwargs)
File "E:/Rasa/rasa_chatbot-master/httpserver.py", line 28, in save_item
data = json.loads(data_string)
File "D:\anaconda\envs\rasa\lib\json_init
.py", line 354, in loads
return _default_decoder.decode(s)
File "D:\anaconda\envs\rasa\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "D:\anaconda\envs\rasa\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

2019-05-15 11:15:37+0800 [-] "127.0.0.1" - - [15/May/2019:03:15:37 +0000] "POST /parse HTTP/1.1" 500 7650 "-" "curl/7.55.1"

nlu如何更改训练次数

我在rasa_nlu下没找到训练次数的修改参数,您能指导下吗
words in dictionary: 26649
num features: 271
now do training
C: 20
epsilon: 0.01
num threads: 1
cache size: 5
max iterations: 2000

max iterations: 2000这个值怎么更改呢

请问mitie支持python3.6吗?我安装的时候总出现这个问题

C:\Users\user>pip3.6 install git+https://github.com/mit-nlp/MITIE.git
Collecting git+https://github.com/mit-nlp/MITIE.git
Cloning https://github.com/mit-nlp/MITIE.git to c:\users\user\appdata\local\te
mp\pip-cn8fkq0n-build
Installing collected packages: mitie
Running setup.py install for mitie ... error
Exception:
Traceback (most recent call last):
File "d:\python3.6\lib\site-packages\pip\compat_init_.py", line 73, in cons
ole_to_str
return s.decode(sys.stdout.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 24: invalid
continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "d:\python3.6\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "d:\python3.6\lib\site-packages\pip\commands\install.py", line 342, in ru
n
prefix=options.prefix_path,
File "d:\python3.6\lib\site-packages\pip\req\req_set.py", line 784, in install

**kwargs

File "d:\python3.6\lib\site-packages\pip\req\req_install.py", line 878, in ins
tall
spinner=spinner,
File "d:\python3.6\lib\site-packages\pip\utils_init_.py", line 676, in call
subprocess
line = console_to_str(proc.stdout.readline())
File "d:\python3.6\lib\site-packages\pip\compat_init
.py", line 75, in cons
ole_to_str
return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 24: invalid
continuation byte

issue

Could you please share the start code? thanks!

python httpserver.py报错

按文档要求安装的
系统环境(MAC OS):
python:3.6.4
rasa_core:0.9.0
rasa_nlu:0.12.3
mitie:0.5.0
scikit-learn:0.19.0
执行python httpserver.py时报错(python bot.py run等也是报这个错误)

/Volumes/DATA/python/virtualenv/chatbot/lib/python3.6/site-packages/sklearn/base.py:312: UserWarning: Trying to unpickle estimator LabelEncoder from version 0.19.1 when using version 0.19.0. This might lead to breaking code or invalid results. Use at your own risk.
UserWarning)
/Volumes/DATA/python/virtualenv/chatbot/lib/python3.6/site-packages/sklearn/base.py:312: UserWarning: Trying to unpickle estimator SVC from version 0.19.1 when using version 0.19.0. This might lead to breaking code or invalid results. Use at your own risk.
UserWarning)
Traceback (most recent call last):
File "bot.py", line 118, in
interpreter=RasaNLUInterpreter("projects/ivr_nlu/demo"),
File "/Volumes/DATA/python/virtualenv/chatbot/lib/python3.6/site-packages/rasa_core/interpreter.py", line 221, in init
self._load_interpreter()
File "/Volumes/DATA/python/virtualenv/chatbot/lib/python3.6/site-packages/rasa_core/interpreter.py", line 237, in _load_interpreter
self.interpreter = Interpreter.load(self.model_directory)
File "/Volumes/DATA/python/virtualenv/chatbot/lib/python3.6/site-packages/rasa_nlu/model.py", line 276, in load
skip_validation)
File "/Volumes/DATA/python/virtualenv/chatbot/lib/python3.6/site-packages/rasa_nlu/model.py", line 303, in create
model_metadata, **context)
File "/Volumes/DATA/python/virtualenv/chatbot/lib/python3.6/site-packages/rasa_nlu/components.py", line 398, in load_component
cached_component, **context)
File "/Volumes/DATA/python/virtualenv/chatbot/lib/python3.6/site-packages/rasa_nlu/registry.py", line 131, in load_component_by_name
return component_clz.load(model_dir, metadata, cached_component, **kwargs)
File "/Volumes/DATA/python/virtualenv/chatbot/lib/python3.6/site-packages/rasa_nlu/classifiers/sklearn_intent_classifier.py", line 233, in load
return utils.pycloud_unpickle(classifier_file)
File "/Volumes/DATA/python/virtualenv/chatbot/lib/python3.6/site-packages/rasa_nlu/utils/init.py", line 322, in pycloud_unpickle
return cloudpickle.load(f, encoding="latin-1")

AttributeError: Can't get attribute 'DeprecationDict' on <module 'sklearn.utils.deprecation' from '/Volumes/DATA/python/virtualenv/chatbot/lib/python3.6/site-packages/sklearn/utils/deprecation.py'>

同一句话,不同上下文,不同的intent, 怎么做?

比如说, 是的

可能的对话:
bot:你肚子疼吗?
user:是的
bot:你有呕吐现象吗?
user:是的

那么这块两个是的是反映不同的情况,这个问题怎么解决呢?
我从AI研习社看到了您的分享,所以想请教下您这个问题,期待您的解答

requirements.txt文件?

麻烦博主能分享下环境配置文件吗?碰到好多配置,估计大部分都是module的版本问题。

python bot.py online_train eorror

Hello, when I exec like this command "python bot.py online_train". the error as bellow, could you help me check it? thanks a lot

Traceback (most recent call last):
File "bot.py", line 120, in
interpreter=RasaNLUInterpreter("models/ivr/demo"),
File "/usr/local/lib/python3.5/dist-packages/rasa_core/interpreter.py", line 219, in init
self._load_interpreter()
File "/usr/local/lib/python3.5/dist-packages/rasa_core/interpreter.py", line 234, in _load_interpreter
from rasa_nlu.config import RasaNLUConfig
ImportError: cannot import name 'RasaNLUConfig'

MITIE 模型训练数据

我在您的博客了解到“项目链接里包含了用真实电信业务数据训练的total_word_feature_extractor.dat”,请问训练用的数据可以从哪里获取到吗?

test rasa nlu时报错builtins.ValueError: bad input shape (1, 13)

你好,我按照Readme.md一步步搭建环境,做到"test rasa nlu"这一步时遇到解决不掉的问题,执行【python httpserver.py】可以正常启动,新开窗口执行curl命令后,httpserver端报错“Unhandled Error”、“builtins.ValueError: bad input shape (1, 13)”,这里不会解决了,请问这个是什么情况啊,需要如何解决?我的操作系统是CentOS 6.3。

关于rasa能否实现状态切换以及话题切换的问题?

多轮对话中,经常出现用户会更改纠正之前的说话,伴随着应该有槽值的替换,想问下rasa能实现这种状态切换?
然后还有就是话题切换,多轮对话中用户会主动或者被动进行话题切换,话题切换回的时候有rasa有记忆效应吗?
期待您的回复。

如何部署Rasa_Core

您好 请问该如何部署 一个Rasa_core 到我自己的APP应用里呢 只是在本地运行 可以实现对话

The config file 'ivr_chatbot.yml' is missing mandatory parameters: 'policies'. Add missing parameters to config file and try again.

It tell me the rasa_nlu.train is obsolete and I change it to rasa.nlu.train as being told by cmd, then it said that rasa.nlu.train should not be run directly, and I follow its advice and change it to rasa train, this time it told me --path and --project is redundant and so I remove them, then it told me that the config.yml the command specified lack mandatory param called "policies", now I dont know how to fix it...maybe the changing api of rasa is the root of all these issues...

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.