Data Validation

Hello,

I am trying to write a validation script for my data as suggested in the document Validate Data. But, m getting error while running my script. Can you please help me with the place where m going wrong ?

-------validation.py file--------

import logging
from rasa.core.validator import Validator

logfile = 'nlu_model.log'
logging.basicConfig(filename=logfile, level=logging.DEBUG)
validator = Validator('domain.yml', 'data/nlu.md', 'data/stories.md')
validator.verify_all()

------Error------

Traceback (most recent call last):
  File "validate.py", line 12, in <module>
    validator.verify_all()
  File "/home/user/Documents/dev_env/venv/lib64/python3.6/site-packages/rasa/core/validator.py", line 152, in verify_all
    self.verify_intents_in_stories()
  File "/home/user/Documents/dev_env/venv/lib64/python3.6/site-packages/rasa/core/validator.py", line 69, in verify_intents_in_stories
    domain_intents = self.verify_intents()
  File "/home/user/Documents/dev_env/venv/lib64/python3.6/site-packages/rasa/core/validator.py", line 41, in verify_intents
    for intent in self.domain.intent_properties:
AttributeError: 'str' object has no attribute 'intent_properties'

Validator does not expect strings but domain: Domain, intents: TrainingData, stories: List[StoryStep].

If you are using python3.7 you can use

import logging
import asyncio
from rasa.core.validator import Validator
from rasa.importers.rasa import RasaFileImporter

file_importer = RasaFileImporter.load_from_config(
    'config.yml', 'domain.yml', ['data/nlu.md', 'data/stories.md']
)

domain = asyncio.run(file_importer.get_domain())
nlu_data = asyncio.run(file_importer.get_nlu_data())
story_graph = asyncio.run(file_importer.get_stories())

logfile = 'nlu_model.log'
logging.basicConfig(filename=logfile, level=logging.DEBUG)
validator = Validator(domain, nlu_data, story_graph.story_steps)
validator.verify_all()
1 Like

Thankyou Tanja,

We are using python 3.6. So, i modified the asyncio.run command. But, it fails to fetch the story_steps. Is there any other way to fetch the stories ?? (I tried to create an object of NluDataImporter and try to fetch the stories, but, it failed.)

----- Error on using the above code-----------

Traceback (most recent call last):
  File "validate.py", line 10, in <module>
    domain = asyncio.run(file_importer.get_domain())
AttributeError: module 'asyncio' has no attribute 'run'

------------Updated Code to make it compatible with Python 3.6---------

domain = asyncio.get_event_loop()
domain.run_until_complete(file_importer.get_domain())

nlu_data = asyncio.get_event_loop()
nlu_data.run_until_complete(file_importer.get_nlu_data())

story_graph = asyncio.get_event_loop()
story_graph.run_until_complete(file_importer.get_stories())

logfile = 'nlu_model.log'
logging.basicConfig(filename=logfile, level=logging.DEBUG)
validator = Validator(domain, nlu_data, story_graph.story_steps)
validator.verify_all()

---------------Error with updated code---------------

Traceback (most recent call last):
  File "validate.py", line 21, in <module>
    validator = Validator(domain, nlu_data, story_graph.story_steps)
AttributeError: 'Loop' object has no attribute 'story_steps'

The way you use asyncio is not correct. Here the version which should work with python3.6:

import logging
import asyncio
from rasa.core.validator import Validator
from rasa.importers.rasa import RasaFileImporter

file_importer = RasaFileImporter.load_from_config(
    'config.yml', 'domain.yml', ['data/nlu.md', 'data/stories.md']
)

loop = asyncio.get_event_loop()
domain = loop.run_until_complete(file_importer.get_domain())
nlu_data = loop.run_until_complete(file_importer.get_nlu_data())
story_graph = loop.run_until_complete(file_importer.get_stories())

logfile = 'nlu_model.log'
logging.basicConfig(filename=logfile, level=logging.DEBUG)
validator = Validator(domain, nlu_data, story_graph.story_steps)
validator.verify_all()
1 Like

Oh… Thanks a ton… :slight_smile: