Problem with Keras - Cannot cast array


I’m trying to compare some policies, but I got some problems when using Keras as policy.

In particular, when I run this command:

rasa train core -c config-keras.yml config-emb.yml -s data/ --out comparison_models/keras_emb

I get this error:

Traceback (most recent call last):
  File "_mt19937.pyx", line 178, in numpy.random._mt19937.MT19937._legacy_seeding
TypeError: 'str' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/rasa", line 8, in <module>
  File "/usr/local/lib/python3.6/dist-packages/rasa/", line 76, in main
  File "/usr/local/lib/python3.6/dist-packages/rasa/cli/", line 118, in train_core
    do_compare_training(args, story_file, additional_arguments)
  File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
  File "/usr/local/lib/python3.6/dist-packages/rasa/core/", line 160, in do_compare_training
    get_no_of_stories(args.stories, args.domain),
  File "/usr/local/lib/python3.6/dist-packages/rasa/core/", line 120, in train_comparison_models
  File "/usr/local/lib/python3.6/dist-packages/rasa/core/", line 67, in train
    agent.train(training_data, **additional_arguments)
  File "/usr/local/lib/python3.6/dist-packages/rasa/core/", line 722, in train
    self.policy_ensemble.train(training_trackers, self.domain, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/rasa/core/policies/", line 126, in train
    policy.train(training_trackers, domain, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/rasa/core/policies/", line 167, in train
  File "mtrand.pyx", line 244, in numpy.random.mtrand.RandomState.seed
  File "_mt19937.pyx", line 166, in numpy.random._mt19937.MT19937._legacy_seeding
  File "_mt19937.pyx", line 186, in numpy.random._mt19937.MT19937._legacy_seeding
TypeError: Cannot cast array from dtype('<U4') to dtype('int64') according to the rule 'safe'

Does anybody know how to solve this?

Thank you, Tiziano

How does your config-keras.yml file look like? Seems like you are trying to pass an invalid random seed according to the error.

random seed is set to None. You’re right, probably the error is there. Should I put it between parenthesis?

If you don’t want to set a random seed in your config file, just remove it from there. The default value is already set to None so no need to define it in your config file.

Yes, it was just a try for understanding how it worked, but that’s fine.

Could you please also help me to understand this?

Thank you

I assume that if you write random_seed: None into your config file, None will be interpreted as a String. So you should only put it with a valid number assigned to it.

1 Like