I have trained my custom keras policy, in which I have overridden the methods of model_architecture(), train(), and predict_action_probabilities().
@staticmethod
def _standard_featurizer(max_history=None) -> MaxHistoryTrackerFeaturizer:
return MaxHistoryTrackerFeaturizer(
BinarySingleStateFeaturizer(), max_history=max_history
)
I have used sequencetosequence learning model of keras in the model_architecture(), for which I have used model functional API of keras
I have trained my model successfully according to the requirements of model functional API of keras
I have overridden the predict_action_probabilities using seq2seq architecture as suggested in keras (Sequence to sequence - training - Keras Documentation). Please note the inference mode of this script. I have used rasa.core.trackers.DiualogueStateTracker to track the current state of the dialogue, which I have used as input during inference to get an appropriate output.
For certain inputs, I have got responses as follows,
Bot loaded. Type a message and press enter (use '/stop' to exit):
Your input -> hello
generalgreet
inference present in input
[0.04813954 0.04518778 0.04732276 0.04781925 0.04653163 0.04731432
0.04707719 0.04808358 0.04925855 0.0464602 0.04733092 0.04808548
0.04901079 0.04893062 0.04812032 0.04859824 0.04857181 0.04791202
0.04678375 0.04635942 0.0471018 ]
generalgreet
inference present in input
[0.05048081 0.05068788 0.04745176 0.04923806 0.04534654 0.04931565
0.04933983 0.04575039 0.04857415 0.04926641 0.0463514 0.04609929
0.04893394 0.04815006 0.04594346 0.04610807 0.04870501 0.04803631
0.0453928 0.0448509 0.04597724]
Hello! Welcome to Cambridge Restaurant Reservation
Your input -> please look for cheap restaurants in south of town?
restaurantinform Area south , Price cheap
inference present in input
[0.04671149 0.04779284 0.04789561 0.04604625 0.04754759 0.04716274
0.04731586 0.04703237 0.04781988 0.04646458 0.04832926 0.04842366
0.04939745 0.04669243 0.04830892 0.04933191 0.04751237 0.0474623
0.04848694 0.04641495 0.04785059]
restaurantinform Area south , Price cheap
inference present in input
[0.04720559 0.04704393 0.04728524 0.04821112 0.0484213 0.0479328
0.04886735 0.04693772 0.0477605 0.04802501 0.04710285 0.04748202
0.04773774 0.0480679 0.04838854 0.04704604 0.04797858 0.04732408
0.04689602 0.04740844 0.04687722]
Please wait, I am processing your request
The predict_action_probabilities() method returns the above-seen numpy array
I have received the following error for certain user inputs,
Your input -> ok, could you suggest me any cheap restaurants in south of town?
restaurantinform Area south , Price cheap
inference present in input
[0.04869927 0.04725369 0.04871094 0.04800798 0.04761689 0.04908743
0.04798222 0.04921195 0.04638006 0.04428944 0.04719522 0.04895578
0.04675346 0.04532265 0.04668255 0.04748159 0.04754604 0.04865643
0.04826559 0.0483827 0.04751805]
2019-12-09 10:57:26 ERROR asyncio - Task exception was never retrieved
future: <Task finished coro=<configure_app.<locals>.run_cmdline_io() done, defined at C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\run.py:124> exception=TimeoutError()>
Traceback (most recent call last):
File "C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\run.py", line 128, in run_cmdline_io
server_url=constants.DEFAULT_SERVER_FORMAT.format("http", port)
File "C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\channels\console.py", line 135, in record_messages
async for response in bot_responses:
File "C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\channels\console.py", line 101, in send_message_receive_stream
async for line in resp.content:
File "c:\apps\sa2446\lib\site-packages\aiohttp\streams.py", line 40, in __anext__
rv = await self.read_func()
File "c:\apps\sa2446\lib\site-packages\aiohttp\streams.py", line 329, in readline
await self._wait('readline')
File "c:\apps\sa2446\lib\site-packages\aiohttp\streams.py", line 297, in _wait
await waiter
File "c:\apps\sa2446\lib\site-packages\aiohttp\helpers.py", line 585, in __exit__
raise asyncio.TimeoutError from None
concurrent.futures._base.TimeoutError
Transport closed @ ('127.0.0.1', 60416) and exception experienced during error handling
2019-12-09 10:57:26 ERROR asyncio - Task exception was never retrieved
future: <Task finished coro=<RestInput.on_message_wrapper() done, defined at C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\channels\channel.py:392> exception=AttributeError("'numpy.ndarray' object has no attribute 'index'")>
Traceback (most recent call last):
File "C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\channels\channel.py", line 406, in on_message_wrapper
await on_new_message(message)
File "C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\channels\channel.py", line 82, in handler
await app.agent.handle_message(*args, **kwargs)
File "C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\agent.py", line 486, in handle_message
return await processor.handle_message(message)
File "C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\processor.py", line 96, in handle_message
await self._predict_and_execute_next_action(message, tracker)
File "C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\processor.py", line 410, in _predict_and_execute_next_action
action, policy, confidence = self.predict_next_action(tracker)
File "C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\processor.py", line 201, in predict_next_action
action_confidences, policy = self._get_next_action_probabilities(tracker)
File "C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\processor.py", line 621, in _get_next_action_probabilities
tracker, self.domain
File "C:\Users\SA2446\AppData\Roaming\Python\Python37\site-packages\rasa\core\policies\ensemble.py", line 402, in probabilities_using_best_policy
and result.index(max_confidence)
AttributeError: 'numpy.ndarray' object has no attribute 'index'
Could I get help to solve this issue?