0

I am trying to replicate the sample restaurant search. I am running it on windows 64 / python 3.6 Anaconda 4.4. My config.json looks like this.

    {
      "name": null,
      "pipeline": ["nlp_spacy", "tokenizer_spacy", "intent_entity_featurizer_regex", "intent_featurizer_spacy", "ner_crf", "ner_synonyms",  "intent_classifier_sklearn"],
      "language": "en",
      "num_threads": 4,
      "path": "D:/rasa-nlu-working/models",
      "response_log": "logs",
      "config": "config.json",
      "log_level": "INFO",
      "port": 5000,
      "data": null,
      "emulate": null,
      "log_file": null,
      "mitie_file": "data/total_word_feature_extractor.dat",
      "spacy_model_name": null,
      "server_model_dirs": null,
      "token": null,
      "max_number_of_ngrams": 7,
      "duckling_dimensions": ["time", "number", "money","ordinal","duration"],
      "entity_crf_BILOU_flag": true,
      "entity_crf_features": [
        ["low", "title", "upper", "pos", "pos2"],
        ["bias", "low", "word3", "word2", "upper", "title", "digit", "pos", "pos2", "pattern"],
        ["low", "title", "upper", "pos", "pos2"]]
    }

I am trying to train and predict using jupyter notebook. Train steps goes on smoothly. As expected models are created. But when I try to predict using the following code.

from rasa_nlu.model import Metadata, Interpreter

# where `model_directory points to the folder the model is persisted in
interpreter = Interpreter.load('D:/rasa-nlu-working/models/model_20170904-132507', RasaNLUConfig("D:/rasa-nlu-working/config.json"))

I am getting the following error.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-9f85d157325d> in <module>()
      4 
      5 # where `model_directory points to the folder the model is persisted in
----> 6 interpreter = Interpreter.load('D:/rasa-nlu-working/models/model_20170904-132507', RasaNLUConfig("D:/rasa-nlu-working/config.json"))

D:\Anaconda3\lib\site-packages\rasa_nlu\model.py in load(model_metadata, config, component_builder, skip_valdation)
    206         # Before instantiating the component classes, lets check if all required packages are available
    207         if not skip_valdation:
--> 208             components.validate_requirements(model_metadata.pipeline)
    209 
    210         for component_name in model_metadata.pipeline:

AttributeError: 'str' object has no attribute 'pipeline'

But the same config works fine when I run it in HTTP server mode. Kindly help me in resolving the issue.

Subramanian
  • 67
  • 1
  • 10
  • Is `D:/rasa-nlu-working/models/model_20170904-132507` a directory or file? It should be directory – Ramanan Sep 04 '17 at 12:15
  • Its a directory. I has six files namely crf_model.pkl, entity_synonyms.json, intent_classifier.pkl, metadata.json, regex_featurizer.json and training_data.json. This subfolder got generated after I train with sample data. – Subramanian Sep 04 '17 at 12:22
  • Can you post the command you are using to train? Also can you post the contents of metadata.json? – Caleb Keller Sep 04 '17 at 14:06
  • Actually also you're comment "the same config works fine when I run it in HTTP server mode" when in http server mode can you load that model and parse against it just fine? The error you're encountering has nothing to do with the config file. It has to do with metadata.json, which is kind of like a snapshot of the config file for a particular model. For whatever reason it isn't being loaded and parsed correctly. – Caleb Keller Sep 04 '17 at 14:37
  • Make sure to install the latest version from github (version `0.10.0a2`). If you install from pypi the syntax is a bit different (have a look at the documentation for details): https://rasa-nlu.readthedocs.io/en/stable/python.html#prediction-time – tmbo Sep 05 '17 at 06:46

2 Answers2

2

I've asked for a few clarifications in the comments, but thought I would start writing an answer anyway.

The error that you've posted isn't actually a problem with your config file. It looks like metadata.json isn't being loaded and/or parsed correctly. metadata.json is kind of like a snapshot of the config file at the time the model was trained.

Here's the order of operations:

  1. Whenever you call Interpreter.load one of the first things that gets done is loading the metadata.json file. See here.
  2. Next over in Metadata.load we try to load and parse that file. See here
  3. Back in Interpreter we try to get the pipeline from the metadata that was returned. See here.

That's where your error is happening. For some reason the metadata.json file is loaded without errors, but isn't parsed properly.

A few possible errors:

  • metadata.json is improperly formatted JSON. not certain how this would happen, but can you provide the metadata.json so we can check it out.
  • There's a windows encoding problem that's not being handled correctly.

Also you specifically mention the http API. Can the http API load this model and use it to parse? You should be able to call the below to test it, after you've started the server.

curl -XPOST localhost:5000/parse -d '{"q":"hello there", "model": "model_20170904-132507"}'

If the HTTP server can load/parse it then we know that it's likely something in your python code specifically.

Conversely if that works, then you should try to train the data using the http API and see what is different about the metadata.json file training via http api vs your python implementation.

More to come as you provide more info.

Caleb Keller
  • 2,151
  • 17
  • 26
  • I am using 0.9.2 version. Having issues in cloning the github version due to security restriction. Will get back to you once I over come it – Subramanian Sep 05 '17 at 07:10
  • I will add my metadata.json as reply. Since its huge and cannot be pasted as comment. I looks fine for me as for as JSON is concerned. – Subramanian Sep 05 '17 at 07:11
  • @Subramanian have you find the solution for this issue, even am facing the same problem – Praveen R Sep 29 '17 at 05:07
0

I had the same problem while using rasa from python, and stumbled upon this thread while googling the same error but as mentioned above by @Caleb Keller, changing the rasa version from 0.9.0 to 0.10.0a5 solved the problem. Thanks for the help.

Drakodux
  • 1
  • 1