Padatious

An efficient and agile neural network intent parser

IntentContainer

class padatious.IntentContainer(cache_dir)[source]

Creates an IntentContainer object used to load and match intents

Parameters:

cache_dir (str) – Place to put all saved neural networks

add_entity(name, lines, reload_cache=False, must_train=True)[source]

Adds an entity that matches the given lines.

Example

self.add_intent(‘weather’, [‘will it rain on {weekday}?’]) self.add_entity(‘weekday’, [‘monday’, ‘tuesday’, ‘wednesday’]) # …

Parameters:
  • name (str) – The name of the entity

  • lines (list<str>) – Lines of example extracted entities

  • reload_cache (bool) – Whether to refresh all of cache

add_intent(name, lines, reload_cache=False, must_train=True)[source]

Creates a new intent, optionally checking the cache first

Parameters:
  • name (str) – The associated name of the intent

  • lines (list<str>) – All the sentences that should activate the intent

  • reload_cache – Whether to ignore cached intent if exists

apply_training_args(data)[source]
calc_intent(query)[source]

Tests all the intents against the query and returns match data of the best intent

Parameters:

query (str) – Input sentence to test against intents

Returns:

Best intent match

Return type:

MatchData

calc_intents(query)[source]

Tests all the intents against the query and returns data on how well each one matched against the query

Parameters:

query (str) – Input sentence to test against intents

Returns:

List of intent matches

Return type:

list<MatchData>

See calc_intent() for a description of the returned MatchData

clear()[source]
get_training_args()[source]
instantiate_from_disk()[source]

Instantiates the necessary (internal) data structures when loading persisted model from disk. This is done via injecting entities and intents back from cached file versions.

load_entity(name, file_name, reload_cache=False, must_train=True)[source]

Loads an entity, optionally checking the cache first

Parameters:
  • name (str) – The associated name of the entity

  • file_name (str) – The location of the entity file

  • reload_cache (bool) – Whether to refresh all of cache

load_file(*args, **kwargs)[source]

Legacy. Use load_intent instead

load_intent(name, file_name, reload_cache=False, must_train=True)[source]

Loads an intent, optionally checking the cache first

Parameters:
  • name (str) – The associated name of the intent

  • file_name (str) – The location of the intent file

  • reload_cache (bool) – Whether to refresh all of cache

remove_entity(name)[source]

Unload an entity

remove_intent(name)[source]

Unload an intent

train(debug=True, force=False, single_thread=False, timeout=20)[source]

Trains all the loaded intents that need to be updated If a cache file exists with the same hash as the intent file, the intent will not be trained and just loaded from file

Parameters:
  • debug (bool) – Whether to print a message to stdout each time a new intent is trained

  • force (bool) – Whether to force training if already finished

  • single_thread (bool) – Whether to force running in a single thread

  • timeout (float) – Seconds before cancelling training

Returns:

True if training succeeded without timeout

Return type:

bool

train_subprocess(*args, **kwargs)[source]

Trains in a subprocess which provides a timeout guarantees everything shuts down properly

Parameters:

<train> (See) –

Returns:

True for success, False if timed out

Return type:

bool

MatchData

class padatious.MatchData(name, sent, matches=None, conf=0.0)[source]

A set of data describing how a query fits into an intent

name

Name of matched intent

Type:

str

sent

The query after entity extraction

Type:

str

conf

Confidence (from 0.0 to 1.0)

Type:

float

matches

Key is the name of the entity and value is the extracted part of the sentence

Type:

dict of str -> str

static handle_apostrophes(old_sentence)[source]

Attempts to handle utterances with apostrophes in them