Error in the definition of roles for entites

Hello. I’m having problems with entities roles. Once I try to train a Core agent, defining roles for the entities:

entities:
  - people
  - number:
      roles:
      - inf
      - sup
  - color:
      roles:
      - favorite

the training does not start. yelding this error:

Traceback (most recent call last):
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\a.porporato\Anaconda3\envs\rasatestenv\Scripts\rasa.exe\__main__.py", line 7, in <module>
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\site-packages\rasa\__main__.py", line 117, in main
    cmdline_arguments.func(cmdline_arguments)
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\site-packages\rasa\cli\train.py", line 59, in <lambda>
    train_parser.set_defaults(func=lambda args: run_training(args, can_exit=True))
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\site-packages\rasa\cli\train.py", line 91, in run_training
    training_result = train_all(
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\site-packages\rasa\api.py", line 109, in train
    return rasa.utils.common.run_in_loop(
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\site-packages\rasa\utils\common.py", line 296, in run_in_loop
    result = loop.run_until_complete(f)
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\asyncio\base_events.py", line 608, in run_until_complete
    return future.result()
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\site-packages\rasa\model_training.py", line 100, in train_async
    domain = await file_importer.get_domain()
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\site-packages\rasa\shared\utils\common.py", line 141, in decorated
    return await cache.cached_result()
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\site-packages\rasa\shared\importers\importer.py", line 448, in get_domain
    original, e2e_domain = await asyncio.gather(
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\site-packages\rasa\shared\utils\common.py", line 141, in decorated
    return await cache.cached_result()
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\site-packages\rasa\shared\importers\importer.py", line 331, in get_domain
    existing_domain = existing_domain.merge(domain_with_retrieval_intents)
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\site-packages\rasa\shared\core\domain.py", line 313, in merge
    combined[key] = merge_lists(combined[key], domain_dict[key])
  File "c:\users\a.porporato\anaconda3\envs\rasatestenv\lib\site-packages\rasa\shared\core\domain.py", line 283, in merge_lists
    return sorted(list(set(list1 + list2)))
TypeError: unhashable type: 'dict'

If I remove the roles in the definition of the roles from the entities, all works smoothly.

Rasa Version      :         2.8.0
Minimum Compatible Version: 2.8.0
Rasa SDK Version  :         2.8.0
Rasa X Version    :         None
Python Version    :         3.8.0
Operating System  :         Windows-10-10.0.19041-SP0
Python Path       :         c:\users\a.porporato\anaconda3\envs\rasatestenv\python.exe

I’m using rasa 2.8.0, but the same error occurs even with rasa 2.6.x or 2.7

Is a known problem? There is some errors in the deninition of my entities? I need to update some dependencies?

Thank you for your help.

Hi @a-porporato The format of your entities seems correct - let’s troubleshoot this together further.

Are you able to confirm if you’re using one domain file, or multiple domain files split in different files? Could you also please share your domain file(s)? Also, have you edited the config file too or are you using the default one? Please also confirm if the command you’ve tried running was rasa train core.

  • I am using a single domain file: domain.yml (4.6 KB)
  • The configuration that I am using: config.yml (2.8 KB); however, I get te same error even with the deafult pipeline:
# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: en

pipeline:
# # No configuration for the NLU pipeline was provided. The following default pipeline was used to train your model.
# # If you'd like to customize it, uncomment and adjust the pipeline.
# # See https://rasa.com/docs/rasa/tuning-your-model for more information.
#   - name: WhitespaceTokenizer
#   - name: RegexFeaturizer
#   - name: LexicalSyntacticFeaturizer
#   - name: CountVectorsFeaturizer
#   - name: CountVectorsFeaturizer
#     analyzer: char_wb
#     min_ngram: 1
#     max_ngram: 4
#   - name: DIETClassifier
#     epochs: 100
#     constrain_similarities: true
#   - name: EntitySynonymMapper
#   - name: ResponseSelector
#     epochs: 100
#     constrain_similarities: true
#   - name: FallbackClassifier
#     threshold: 0.3
#     ambiguity_threshold: 0.1
  

# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
# See https://rasa.com/docs/rasa/policies for more information.
  # - name: MemoizationPolicy
  - name: TEDPolicy
    max_history: 15
    epochs: 400
    constrain_similarities: True

    e2e_confidence_threshold: 0.9
    evaluate_on_number_of_examples: 0
    evaluate_every_number_of_epochs: 20
    tensorboard_log_directory: "./tensorboard"
    tensorboard_log_level: "epoch"
    random_seed: 43
    model_confidence: softmax

  - name: RulePolicy
    # # Confidence threshold for the `core_fallback_action_name` to apply.
    # # The action will apply if no other action was predicted with
    # # a confidence >= core_fallback_threshold
    # core_fallback_threshold: 0.4
    # core_fallback_action_name: "action_default_fallback"
    # enable_fallback_prediction: True
  • The command that i used was rasa train: the training of the NLU components finishes without error (just some strange warning about the absence for responses for ‘faq’ and ‘chitchat’ intent, that are indeed present), and just before the error there is some information about conditional response variation
  • The list of packages installed in my conda environment: conda_pack.txt (12.1 KB)

Thank you very much for your intereset.

@a-porporato Hey! I run your code based on domain.yml and config.yml I can train. I guess your error is associated with other files (may be stories or rules), so if you can share complete zip folder of project, I can run and check the error.

Please, if you can create the fresh environment of Python 3.8 and with Rasa 2.8.0 and Rasa-sdk 2.8.1, please don’t ignore the red warnings. Copy you folder and try run.

For your error cause:

The “TypeError: unhashable type: ‘dict’” error is raised when you try to create an item in a dictionary whose key is an unhashable object. Only immutable objects like strings, tuples, and integers can be used as a key in a dictionary.

To solve this error, make sure that you only use hashable objects when creating an item in a dictionary.

Thank you for the resposes.

I made more tests, and it seems that there is some issues with the use of retrieval intent defined in the nlu.yml file and entity roles definition, even if the said intent do not use any entity with role:

# CHITCHAT
- intent: chitchat/ask_name
  metadata:
    sentiment: neutral
  examples: |
    - What is your name?
    - May I know your name?
    - What do people call you?
    - What do peeple call you?
    - Do you have a name for yourself?
    - What's you _unk_ name?
    - How can I call oyu?
    - Do you have a name?
    - How do you want that I call you?
- intent: chitchat/ask_age
  metadata:
    sentiment: neutral
  examples: |
    - What's your birth day?
    - When you were born?
    - How old are you?
    - How lod are you?
    - I wolud like to know your age.
    - What's your _unk_ age?
  - chitchat:
      use_entities: []

Are entity roles and retrieval intent related in some way?

@a-porporato Did you mention this in your config.yml

pipeline:
# Other components
- name: ResponseSelector
  epochs: 100
  retrieval_intent: faq
- name: ResponseSelector
  epochs: 100
  retrieval_intent: chitchat

Ref link: Chitchat and FAQs

Are entity roles and retrieval intent related in some way?

Looking at the traceback you shared, it seems that the program fails when it’s trying to merge the entities lists of 2 Domain objects - the existing domain and a domain that gets created internally to handle retrieval intents, if any. For some reason I don’t know yet and requires more debugging, one of these two domains is not returning a list of entities.

Are you able to share the full log with all the warnings you get when running rasa train? Also worth running rasa data validate to check for errors in your yaml files, that could help rule out issues. At this stage, I would suggest resolving the CLI warnings you get.