mindmeld package

class mindmeld.Application(import_name, request_class=None, responder_class=None, text_preparation_pipeline=None, async_mode=False)[source]

Bases: object

The conversational application.

import_name

str -- The name of the application package.

app_path

str -- The application path.

app_manager

ApplicationManager -- The application manager.

request_class

Request -- Any class that inherits from Request.

responder_class

DialogueResponder -- Any class that inherits from the DialogueResponder.

text_preparation_pipeline

TextPreparationPipeline -- The application text preparation pipeline, if any.

async_mode

bool -- True if the application is async, False otherwise.

add_dialogue_rule(name, handler, **kwargs)[source]

Adds a dialogue rule for the dialogue manager.

Parameters:
  • name (str) -- The name of the dialogue state
  • handler (callable) -- The dialogue state handler function
  • kwargs (dict) -- A list of options which specify the dialogue rule
add_middleware(middleware)[source]

Adds middleware for the dialogue manager

Parameters:middleware (callable) -- A dialogue manager middleware function
auto_fill(name=None, *, form, **kwargs)[source]

Creates a flow to fill missing entities

cli()[source]

Initialize the application's command line interface.

custom_action(action=None, actions=None, async_mode=False, merge=True, config=None, **kwargs)[source]

Adds a custom action sequence handler for the dialogue manager.

Whenever the user hits this state, we invoke the sequence of custom action(s) and returns
the appropriate responder.
Parameters:
  • action (str) -- The name of a custom action.
  • actions (list) -- A list of names of custom actions.
  • async_mode (bool) -- Whether we should invoke this custom action asynchronously.
  • merge (bool) -- Whether we should merge the Responder with fields from the response, otherwise we will overwrite the fields (frame, directives) accordingly.
  • config (dict) -- The custom action config, if different from the application's.
dialogue_flow(**kwargs)[source]

Creates a dialogue flow for the application

handle(**kwargs)[source]

A decorator that is used to register dialogue state rules

lazy_init(nlp=None)[source]

Initialize the application manager, spin up the server and compile the dialogue rules.

middleware(*args)[source]

A decorator that is used to register dialogue handler middleware

register_func(name=None)[source]

Registers custom functions for mindmeld app

run(**kwargs)[source]

Runs the application on a local development server.

question_answerer

The application's Question Answerer, which is initialized as part of the application manager.

class mindmeld.Conversation(app=None, app_path=None, nlp=None, context=None, default_params=None, force_sync=False, verbose=False)[source]

Bases: object

The conversation object is a very basic MindMeld client.

It can be useful for testing out dialogue flows in python.

Example

>>> convo = Conversation(app_path='path/to/my/app')
>>> convo.say('Hello')
['Hello. I can help you find store hours. How can I help?']
>>> convo.say('Is the store on elm open?')
['The 23 Elm Street Kwik-E-Mart is open from 7:00 to 19:00.']
history

list -- The history of the conversation. Starts with the most recent message.

context

dict -- The context of the conversation, containing user context.

default_params

Params -- The default params to use with each turn. These defaults will be overridden by params passed for each turn.

params

FrozenParams -- The params returned by the most recent turn.

force_sync

bool -- Force synchronous return for say() and process() even when app is in async mode.

verbose

bool, optional -- If True, returns class probabilities along with class prediction.

process(text, params=None, force_sync=False)[source]

Send a message in the conversation. The message will be processed by the app based on the current state of the conversation and returns the response.

Parameters:
  • text (str) -- The text of a message.
  • params (dict) -- The params to use with this message, overriding any defaults which may have been set.
  • force_sync (bool, optional) -- Force synchronous response even when app is in async mode.
Returns:

The dictionary response.

Return type:

(dict)

reset()[source]

Reset the history, frame and params of the Conversation object.

say(text, params=None, force_sync=False)[source]

Send a message in the conversation. The message will be processed by the app based on the current state of the conversation and returns the extracted messages from the directives.

Parameters:
  • text (str) -- The text of a message.
  • params (dict) -- The params to use with this message, overriding any defaults which may have been set.
  • force_sync (bool, optional) -- Force synchronous response even when app is in async mode.
Returns:

A text representation of the dialogue responses.

Return type:

(list)

class mindmeld.DialogueResponder(frame=None, params=None, history=None, slots=None, request=None, dialogue_state=None, directives=None, form=None)[source]

Bases: object

The dialogue responder helps generate directives and fill slots in the system-generated natural language responses.

class DirectiveNames

Bases: object

The list of directive names.

LIST = 'list'
LISTEN = 'listen'
REPLY = 'reply'
RESET = 'reset'
SLEEP = 'sleep'
SPEAK = 'speak'
SUGGESTIONS = 'suggestions'
class DirectiveTypes

Bases: object

The list of directive types.

ACTION = 'action'
VIEW = 'view'
act(name, payload=None)[source]

Adds an arbitrary directive of type 'action'.

Parameters:
  • name (str) -- The name of the directive.
  • payload (dict, optional) -- The payload for the action.
direct(name, dtype, payload=None)[source]

Adds an arbitrary directive.

Parameters:
  • name (str) -- The name of the directive.
  • dtype (str) -- The type of the directive.
  • payload (dict, optional) -- The payload for the view.
display(name, payload=None)[source]

Adds an arbitrary directive of type 'view'.

Parameters:
  • name (str) -- The name of the directive.
  • payload (dict, optional) -- The payload for the view.
exit_flow()[source]

Exit the current flow by clearing the target dialogue state.

list(items)[source]

Adds a 'list' view directive.

Parameters:items (list) -- The list of dictionary objects.
listen()[source]

Adds a 'listen' directive.

prompt(text)[source]

Alias for reply(). Deprecated.

Parameters:text (str) -- The text of the reply.
reply(text)[source]

Adds a 'reply' directive.

Parameters:text (str) -- The text of the reply.
reset()[source]

Adds a 'reset' directive.

respond(directive)[source]

Adds an arbitrary directive.

Parameters:directive (dict) -- A directive.
sleep(delay=0)[source]

Adds a 'sleep' directive.

Parameters:delay (int) -- The amount of milliseconds to wait before putting the client to sleep.
speak(text)[source]

Adds a 'speak' directive.

Parameters:text (str) -- The text to speak aloud.
suggest(suggestions)[source]

Adds a 'suggestions' directive.

Parameters:suggestions (list) -- A list of suggestions.
history
params
request
class mindmeld.NaturalLanguageProcessor(app_path, resource_loader=None, config=None, progress_bar=None)[source]

Bases: mindmeld.components.nlp.Processor

The natural language processor is the MindMeld component responsible for understanding the user input using a hierarchy of natural language processing models.

domain_classifier

DomainClassifier -- The domain classifier for this application.

extract_nlp_masked_components_list(allow_nlp_components_list=None, deny_nlp_components_list=None)[source]

This function validates a user inputted list of allowed nlp components against the NLP hierarchy and construct a hierarchy dictionary as follows: {domain: {intent: {}} if the validation of list of allowed nlp components has passed.

Parameters:
  • allow_nlp_components_list (list) -- A list of allow NLP components in the format "domain.intent.entity.role".
  • deny_nlp_components_list (list) -- A list of deny NLP components in the format "domain.intent.entity.role".
Returns:

A dictionary of NLP hierarchy.

Return type:

(dict)

inspect(markup, domain=None, intent=None, dynamic_resource=None)[source]

Inspect the marked up query and print the table of features and weights.

Parameters:
  • markup (str) -- The marked up query string.
  • domain (str) -- The gold value for domain classification.
  • intent (str) -- The gold value for intent classification.
  • dynamic_resource (dict, optional) -- A dynamic resource to aid NLP inference.
static print_inspect_stats(stats)[source]

Prints formatted output matrix

process(query_text, allowed_nlp_classes=None, allowed_intents=None, allow_nlp=None, deny_nlp=None, locale=None, language=None, time_zone=None, timestamp=None, dynamic_resource=None, verbose=False)[source]

Processes the given query using the full hierarchy of natural language processing models trained for this application.

Parameters:
  • query_text (str, tuple) -- The raw user text input, or a list of the n-best query transcripts from ASR.
  • allowed_nlp_classes (dict, optional) -- A dictionary of the NLP hierarchy that is selected for NLP analysis. An example: {'smart_home': {'close_door': {}}} where smart_home is the domain and close_door is the intent.
  • allowed_intents (list, optional) -- A list of allowed intents to use for the NLP processing.
  • allow_nlp (list, optional) -- A list of allow NLP components to use for the NLP processing.
  • deny_nlp (list, optional) -- A list of denied NLP components to use for the NLP processing.
  • locale (str, optional) -- The locale representing the ISO 639-1 language code and ISO3166 alpha 2 country code separated by an underscore character.
  • language (str, optional) -- Language as specified using a 639-1/2 code. This parameter is ignored deprecated this is an application level parameter.
  • time_zone (str, optional) -- The name of an IANA time zone, such as 'America/Los_Angeles', or 'Asia/Kolkata' See the [tz database](https://www.iana.org/time-zones) for more information.
  • timestamp (long, optional) -- A unix time stamp for the request (in seconds).
  • dynamic_resource (dict, optional) -- A dynamic resource to aid NLP inference.
  • verbose (bool, optional) -- If True, returns class probabilities along with class prediction.
Returns:

A processed query object that contains the prediction results from applying the full hierarchy of natural language processing models to the input query.

Return type:

(ProcessedQuery)

process_query(query, allowed_nlp_classes=None, dynamic_resource=None, verbose=False)[source]

Processes the given query using the full hierarchy of natural language processing models trained for this application.

Parameters:
  • query (Query, tuple) -- The user input query, or a list of the n-best transcripts query objects.
  • allowed_nlp_classes (dict, optional) -- A dictionary of the NLP hierarchy that is selected for NLP analysis. An example: {'smart_home': {'close_door': {}}} where smart_home is the domain and close_door is the intent. If allowed_nlp_classes is None, we just use the normal model predict functionality.
  • dynamic_resource (dict, optional) -- A dynamic resource to aid NLP inference.
  • verbose (bool, optional) -- If True, returns class probabilities along with class prediction.
Returns:

A processed query object that contains the prediction results from applying the full hierarchy of natural language processing models to the input query.

Return type:

(ProcessedQuery)

unload()[source]
domains

The domains supported by this application.

class mindmeld.QuestionAnswerer[source]

Bases: object

Backwards compatible QuestionAnswerer class

old usages (allowed but will soon be deprecated)
# loading KB directly through class method >>> QuestionAnswerer.load_kb(...) # instantiating a QA object from QuestionAnswerer instead of QuestionAnswererFactory >>> question_answerer = QuestionAnswerer(app_path, resource_loader, es_host, config)
new usages
>>> question_answerer = QuestionAnswererFactory.create_question_answerer(**kwargs)
# Use the QA object's methods to load KB and get search results, instead of class methods
>>> question_answerer.load_kb(...)
>>> question_answerer.get(...) # .get(...) and .build_search(...)
classmethod load_kb(app_namespace, index_name, data_file, es_host=None, es_client=None, connect_timeout=2, clean=False, app_path=None, config=None, **kwargs)[source]

Implemented to maintain backward compatibility. Should be removed in future versions.

Parameters:
  • app_namespace (str) -- The namespace of the app. Used to prevent collisions between the indices of this app and those of other apps.
  • index_name (str) -- The name of the new index to be created.
  • data_file (str) -- The path to the data file containing the documents to be imported into the knowledge base index. It could be either json or jsonl file.
  • es_host (str) -- The Elasticsearch host server.
  • es_client (Elasticsearch) -- The Elasticsearch client.
  • connect_timeout (int, optional) -- The amount of time for a connection to the Elasticsearch host.
  • clean (bool) -- Set to true if you want to delete an existing index and reindex it
  • app_path (str) -- The path to the directory containing the app's data
  • config (dict) -- The QA config if passed directly rather than loaded from the app config
DEPRECATION_MESSAGE = "Calling QuestionAnswerer class directly will be deprecated in future versions. To instantiate a QA instance, use the QuestionAnswererFactory by calling 'qa = QuestionAnswererFactory.create_question_answerer(**kwargs)'. An instantiated QA can then be used as 'qa.load_kb(...)', 'qa.get(...)', etc. See https://www.mindmeld.com/docs/userguide/kb.html for details about the various functionalities available with different question-answerers."
mindmeld.configure_logs(**kwargs)[source]

Helper method for easily configuring logs from the python shell.

Parameters:level (TYPE, optional) -- A logging level recognized by python's logging module.

Subpackages