Understanding

The understanding domain groups all thing related to the understanding of user intents.

Interpreter

Interpreter allow pytlas to categorize user intents and to extract slots from raw text. Whatever interpreter you decide to use, it will need training data to be able to understand what’s the user intent behind an input sentence.

Intent

An intent represents a user intention.

For example, when I say what’s the weather like?, my intent is something as get weather. When I say please tell me what’s the weather like today, it maps to the same intent get weather.

Slot

A slot is like a parameter value for a function. It represents an entity in the context of an intent.

So when I say what’s the weather like in Paris?, my intent is get weather and the slot city should be Paris.

Implementing a custom interpreter

If you wish to implement your own interpreter, you must at least extends from pytlas.interpreters.Interpreter and implement those methods.

Note

When creating SlotValue instance to represent a slot, always remember to sets a value in a meaningfull python representation. See Retrieving slots to see what’s expected by developers.

Interpreter.fit(data: dict) → None

Fit the interpreter with given data.

Parameters:data (dict) – Training data
Interpreter.parse(msg: str, scopes: List[str] = None) → List[pytlas.understanding.intent.Intent]

Parses the given raw message and returns parsed intents.

Parameters:
  • msg (str) – Message to parse
  • scopes (list of str) – Optional list of scopes used to restrict parsed intents
Returns:

Parsed intents

Return type:

list of Intent

Interpreter.parse_slot(intent: str, slot: str, msg: str) → List[pytlas.understanding.slot.SlotValue]

Parses the given raw message to extract a slot matching given criterias.

Parameters:
  • intent (str) – Name of the current intent
  • slot (str) – Name of the current slot to extract
  • msg (str) – Raw message to parse
Returns:

Slot values extracted

Return type:

list of SlotValue

Trainings store

All training data are registered on a TrainingsStore instance, mostly using the training decorator.

class pytlas.understanding.TrainingsStore(data: dict = None)

Contains training data.

all(lang: str) → Dict[str, str]

Retrieve all training data in the given language.

It will evaluate all register functions for the given language.

Parameters:lang (str) – Language to get
Returns:Dictionary with package name as key and training DSL string as value
Return type:dict
get(package: str, lang: str) → str

Retrieve training data for a particular package in the given language.

It will evaluate all register functions for the given language.

Parameters:
  • package (str) – Pacjage
  • lang (str) – Language to get
Returns:

Training data

Return type:

str

register(lang: str, func: Callable, package: str = None) → None

Register training data written using the chatl DSL language into the system.

Parameters:
  • lang (str) – Language for which the training has been made for
  • func (func) – Function to call to return training data written using the chatl DSL
  • package (str) – Optional package name (usually __package__), if not given pytlas will try to determine it based on the call stack