rasa core interactive chatbot training error - python-3.x

I am trying to train a chatbot using the interactive module of rasa_core in Python 3.7, but I get an error. Is there a solution to fix this error?
I have written my source code in a file named "train_online.py" based on an example from the Book titled "Building Chatbots with Python Using Natural Language Processing and Machine Learning"
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
from rasa_core import utils, train
from rasa_core.utils import AvailableEndpoints
#from rasa_core.training import online
from rasa_core.training import interactive
from rasa_core.interpreter import NaturalLanguageInterpreter
import os
logger = logging.getLogger(__name__)
def train_agent(interpreter):
return train(domain_file="mybot_domain.yml",
stories_file="./data/stories.md",
output_path="./models/dialogue",
endpoints=AvailableEndpoints("endpoints.yml"),
interpreter=interpreter,
policy_config='config.yml',
kwargs={"batch_size": 50, "epochs": 200, "max_training_samples": 300})
if __name__ == '__main__':
utils.configure_colored_logging(loglevel="DEBUG")
interpreter = NaturalLanguageInterpreter.create("./models/nlu/default/mybot")
agent = train_agent(interpreter)
#online.serve_agent(agent)
interactive.run_interactive_learning(agent)
after running I got the following error:
Traceback (most recent call last):
File "f:/prog/train_online.py", line 45, in <module>
agent = train_agent(interpreter)
File "f:/prog/train_online.py", line 38, in train_agent
kwargs={"batch_size": 50, "epochs": 200, "max_training_samples": 300})
File "F:\prog\env\lib\site-packages\rasa_core\train.py", line 77, in train
policies=policies)
File "F:\prog\env\lib\site-packages\rasa_core\agent.py", line 230, in __init__
self.nlg = NaturalLanguageGenerator.create(generator, self.domain)
File "F:\prog\env\lib\site-packages\rasa_core\nlg\generator.py", line 37, in create
"".format(type(obj)))
Exception: Cannot create a NaturalLanguageGenerator based on the passed object. Type: `<class 'str'>`
The list of packages that I am using in this project is as follows:
absl-py==1.4.0
APScheduler==3.9.1.post1
astor==0.8.1
attrs==22.2.0
Automat==22.10.0
backports.zoneinfo==0.2.1
boto3==1.26.54
botocore==1.29.54
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.0.1
click==7.1.2
cloudpickle==0.6.1
colorama==0.4.6
colorclass==2.2.2
coloredlogs==10.0
colorhash==1.2.1
ConfigArgParse==0.13.0
constantly==15.1.0
cryptography==39.0.0
cycler==0.11.0
docopt==0.6.2
fakeredis==0.10.3
fbmessenger==5.6.0
Flask==1.1.4
Flask-Cors==3.0.10
Flask-JWT-Simple==0.0.3
future==0.17.1
gast==0.5.3
gevent==1.5.0
greenlet==0.4.16
grpcio==1.51.1
h5py==3.7.0
humanfriendly==10.0
hyperlink==21.0.0
idna==3.4
importlib-metadata==6.0.0
incremental==22.10.0
install==1.3.5
itsdangerous==1.1.0
Jinja2==2.11.3
jmespath==1.0.1
jsonpickle==1.5.2
jsonschema==2.6.0
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.2
kiwisolver==1.4.4
klein==17.10.0
Markdown==3.4.1
MarkupSafe==2.0.1
matplotlib==2.2.5
mattermostwrapper==2.2
mock==5.0.1
networkx==2.6.3
numpy==1.21.6
packaging==18.0
pika==0.12.0
prompt-toolkit==3.0.36
protobuf==3.20.0
pycparser==2.21
pydot==1.4.2
PyJWT==1.7.1
pykwalify==1.7.0
pymongo==3.13.0
pyparsing==3.0.9
pyreadline==2.1
python-crfsuite==0.9.8
python-dateutil==2.8.2
python-engineio==4.3.4
python-socketio==3.1.2
python-telegram-bot==11.1.0
pytz==2018.9
pytz-deprecation-shim==0.1.0.post0
PyYAML==6.0
questionary==1.10.0
rasa-core==0.14.0
rasa-core-sdk==0.13.1
rasa-nlu==0.15.0
redis==2.10.6
requests==2.28.2
requests-toolbelt==0.10.1
rocketchat-API==0.6.36
ruamel.yaml==0.15.100
s3transfer==0.6.0
scikit-learn==0.20.4
scipy==1.7.3
simplejson==3.18.1
six==1.16.0
sklearn-crfsuite==0.3.6
slackclient==1.3.2
tabulate==0.9.0
tensorboard==1.13.1
tensorflow==1.13.2
tensorflow-estimator==1.13.0
termcolor==2.2.0
terminaltables==3.1.10
tornado==6.2
tqdm==4.64.1
twilio==6.63.2
Twisted==22.10.0
twisted-iocpsupport==1.0.2
typing==3.7.4.3
typing-extensions==4.4.0
tzdata==2022.7
tzlocal==4.2
urllib3==1.26.14
wcwidth==0.2.6
webexteamssdk==1.6.1
websocket-client==0.54.0
Werkzeug==1.0.1
zipp==3.11.0
zope.interface==5.5.2

Related

How to resolve SystemError: initialization of _internal failed without raising an exception?

Problem
I have written a code that takes some historical data as input. Assuming dataset has a timeseries format, I am trying to do a regression and find a predictor.
Code
For my project, I have four files: my_project.py, utilities.py, plotter.py, and constants.py. Here is some small portions (relevant imports) of the two scripts:
my_project.py:
from time import perf_counter
from constants import (output_dir, DATAPATH, output_file)
from utilities import (dataframe_in_nutshell, excel_reader, info_printer, sys, module_creator, process_discovery, data_explanatory_analysis, excel_reader, df_cleaner, feature_extractor, ml_modelling)
from plotter import Plotter
utilities.py
import os
import sys
import inspect
from pathlib import Path
from typing import (Iterable, List, Tuple, Optional)
from itertools import zip_longest
import matplotlib.pyplot as plt
import statsmodels.tsa.api as smt
import statsmodels.api as sm
import pandas as pd
from sklearn.metrics import mean_absolute_error
from sklearn.preprocessing import scale
from pycaret.regression import (setup, compare_models, predict_model, plot_model, finalize_model, load_model)
import csv
from constants import (np, Path, nan_value, plots_dir, HOURS_PER_WEEK, LAGS_STEP_NUM, rc_params, NA_VALUES, COLUMNS_NAMES, string_columns, LAGS_LABELS, numeric_columns, output_dir, DATAPATH, dtype_dict, train_size)
from pprint import PrettyPrinter
pp = PrettyPrinter()
import seaborn as sns
sns.set()
Error Message
Traceback (most recent call last):
File "c:\Users\username\OneDrive\Desktop\project\my_project.py", line 10, in <module>
from utilities import (dataframe_in_nutshell, excel_reader, info_printer, sys, module_creator,
File "c:\Users\username\OneDrive\Desktop\project\utilities.py", line 18, in <module>
from pycaret.regression import (setup, compare_models, predict_model, plot_model, finalize_model,
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\pycaret\regression.py", line 10, in <module>
import pycaret.internal.tabular
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\pycaret\internal\tabular.py", line 48, in <module>
import pycaret.internal.preprocess
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\pycaret\internal\preprocess.py", line 27, in <module>
from pyod.models.knn import KNN
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\pyod\__init__.py", line 4, in <module>
from . import utils
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\pyod\utils\__init__.py", line 4, in <module>
from .stat_models import pairwise_distances_no_broadcast
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\pyod\utils\stat_models.py", line 11, in <module>
from numba import njit
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\numba\__init__.py", line 42, in <module>
from numba.np.ufunc import (vectorize, guvectorize, threading_layer,
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\numba\np\ufunc\__init__.py", line 3, in <module>
from numba.np.ufunc.decorators import Vectorize, GUVectorize, vectorize, guvectorize
File "C:\Users\username\anaconda3\envs\py310\lib\site-packages\numba\np\ufunc\decorators.py", line 3, in <module>
from numba.np.ufunc import _internal
SystemError: initialization of _internal failed without raising an exception
Logistics
I am running my_project.py in visual studio code on a Windows 10 machine.
All packages are based on Python 3.10 using conda-forge channel
Research
The following pages seem to explain a workaround but I am not sure if I am understanding the issue in here. I would appreciate if you can help me figure this out.
Error on import with numpy HEAD
Update ufunc loop signature resolution to use NumPy
Remove reliance on npy_ ufunc loops.
I had this very same issue today.
Solved it by downgrading Numpy to 1.23.1
So: pip install numpy==1.23.1

I am getting this error "No module named 'darkflow.cython_utils.cy_yolo_findboxes'" When I am using darknet

When I try to use Pycharm to play with YOLO, I got the error.
Here is what I got, Any help will be appreciated.
Node: I have done python3 setup.py build_ext --inplace. All the file like cy_yolo_findboxes.c and cy_yolo2_findboxes are all inside the cython_utils folder. But it does not work.
import cv2
import sys
sys.path.append('/Users/hantaoliu/darkflow-master')
import tensorflow as tf
from darkflow.net.build import TFNet
import numpy as np
import time
option = {
'model': 'cfg/yolo.cfg',
'load': 'bin/yolo.weights',
'threshold': 0.15,
'gpu': 1.0
}
capture = cv2.VideoCapture('videofile1.mp4')
colors =[tuple(255 * np.random(3)) for i in range(5)]
for color in colors:
print(color)
Here are the error message
Traceback (most recent call last):
File "/Users/hantaoliu/PycharmProjects/YOLO/sample.py", line 5, in <module>
from darkflow.net.build import TFNet
File "/Users/hantaoliu/darkflow-master/darkflow/net/build.py", line 7, in <module>
from .framework import create_framework
File "/Users/hantaoliu/darkflow-master/darkflow/net/framework.py", line 1, in <module>
from . import yolo
File "/Users/hantaoliu/darkflow-master/darkflow/net/yolo/__init__.py", line 2, in <module>
from . import predict
File "/Users/hantaoliu/darkflow-master/darkflow/net/yolo/predict.py", line 7, in <module>
from ...cython_utils.cy_yolo_findboxes import yolo_box_constructor
ImportError: No module named 'darkflow.cython_utils.cy_yolo_findboxes'
Build the cython module
cd ./cython_utils
python3 setup.py build_ext --inplace

Python package not installing dependency with python3

I've created a reusable component (package) in Python but I'm having trouble using it with python3. My package uses a 3rd party library called requests like so, in one of my files core.py:
from __future__ import print_function
import requests
import math
import time
import csv
import os
...
Here is my setup.py:
from setuptools import setup
setup(
name = 'my_package',
packages = ['my_package'],
version = '0.1.dev4',
keywords = [ ... ],
install_requires=[
'requests',
'python-dateutil'
],
classifiers = [],
...etc
)
After installing my package on my system, I'm running into this error after starting python3:
>>> import my_package
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/matthew/Desktop/my_package/my_package/__init__.py", line 1, in <module>
from my_package.core import Class
File "/Users/matthew/Desktop/my_package/my_package/core.py", line 5, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
The requests module doesn't seem to be accessible by my package, why?

Import error while importing MLPClassifier

I'm facing the below error when I try to run :
from sklearn.neural_network import MLPClassifier
Error :
from sklearn.neural_network import MLPClassifier
Traceback (most recent call last):
File "<ipython-input-77-6113b65dfa44>", line 1, in <module>
from sklearn.neural_network import MLPClassifier
File "C:\Users\anagha\Anaconda3\lib\site-packages\sklearn\neural_network\__init__.py", line 10, in <module>
from .multilayer_perceptron import MLPClassifier
File "C:\Users\anagha\Anaconda3\lib\site-packages\sklearn\neural_network\multilayer_perceptron.py", line 18, in <module>
from ..model_selection import train_test_split
File "C:\Users\anagha\Anaconda3\lib\site-packages\sklearn\model_selection\__init__.py", line 23, in <module>
from ._search import GridSearchCV
File "C:\Users\anagha\Anaconda3\lib\site-packages\sklearn\model_selection\_search.py", line 32, in <module>
from ..utils.fixes import rankdata
**ImportError: cannot import name 'rankdata'**
If you already have a working installation of numpy and scipy:
pip install -U scikit-learn
otherwise:
conda install scikit-learn
finally check for updates:
conda update pip

Cython with Numpy / AttributeError: 'module' object has no attribute 'Handler'

I want to use Numpy in Cython, but encountered the following error. This error happens even if I run the simple code, so it should be an issue related to importing Numpy.
My environment:
OS X Yosemite
Python 3.4.3
setup.py:
import numpy as np
from distutils.core import setup
from Cython.Build import cythonize
setup(
name = 'my_code',
ext_modules = cythonize('my_code.pyx'),
include_path = [numpy.get_include()]
)
my_code.pyx:
cimport numpy as np
cdef int a
Execute in Terminal:
$ python3 setup.py build_ext --inplace
Traceback (most recent call last):
File "/Users/***/setup.py", line 1, in <module>
import numpy as np
File "/usr/local/lib/python3.4/site-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/local/lib/python3.4/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python3.4/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/local/lib/python3.4/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python3.4/site-packages/numpy/core/__init__.py", line 58, in <module>
from numpy.testing import Tester
File "/usr/local/lib/python3.4/site-packages/numpy/testing/__init__.py", line 10, in <module>
from unittest import TestCase
File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/__init__.py", line 59, in <module>
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
File "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/python3.4/unittest/case.py", line 253, in <module>
class _CapturingHandler(logging.Handler):
AttributeError: 'module' object has no attribute 'Handler'
Old question but I ran into this because I had a very similar issue with numpy.
It turns out I had a directory named logging as a sibling of the script I was trying to run. So the problem was a simple naming collision between my local project folder and the logging module numpy expected to find. Renaming the project logging folder solved the issue for me.
Looking at OP's error message, I suspect this was the case for them as well.

Resources