mindmeld.components package¶
This module contains the components of the MindMeld platform
-
class
mindmeld.components.
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: Returns: The dictionary response.
Return type: (dict)
-
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: Returns: A text representation of the dialogue responses.
Return type: (list)
-
-
class
mindmeld.components.
CustomAction
(name: str, config: dict, merge: bool = True)[source]¶ Bases:
object
- This class allows the client to send Request and Responder to another server and return the
- the directives and frame in the response.
-
invoke
(request, responder, async_mode=False)[source]¶ Invoke the custom action with Request and Responder and return True if the action is executed successfully, False otherwise. Upon successful execution, we update the Frame and Directives of the Responder object.
Parameters: - request (Request) --
- responder (DialogueResponder) --
- async_mode (bool) --
Returns: (bool)
-
invoke_async
(request, responder)[source]¶ Asynchronously invoke the custom action with Request and Responder and return True if the action is executed successfully, False otherwise. Upon successful execution, we update the Frame and Directives of the Responder object.
Parameters: - request (Request) --
- responder (DialogueResponder) --
Returns: (bool)
-
class
mindmeld.components.
CustomActionSequence
(actions, config, merge=True)[source]¶ Bases:
object
This class implements a sequence of custom actions
-
class
mindmeld.components.
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'¶
-
-
list
(items)[source]¶ Adds a 'list' view directive.
Parameters: items (list) -- The list of dictionary objects.
-
prompt
(text)[source]¶ Alias for reply(). Deprecated.
Parameters: text (str) -- The text of the reply.
-
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.
-
suggest
(suggestions)[source]¶ Adds a 'suggestions' directive.
Parameters: suggestions (list) -- A list of suggestions.
-
history
¶
-
params
¶
-
request
¶
-
class
-
class
mindmeld.components.
DialogueManager
(responder_class=None, async_mode=False)[source]¶ Bases:
object
-
add_dialogue_rule
(name, handler, **kwargs)[source]¶ Adds a dialogue state rule for the dialogue manager.
Parameters:
-
add_middleware
(middleware)[source]¶ Adds middleware for the dialogue manager. Middleware will be called for each message before the dialogue state handler. Middleware registered first will be called first.
Parameters: middleware (callable) -- A dialogue manager middleware function.
-
apply_handler
(request, responder, target_dialogue_state=None)[source]¶ Applies the dialogue state handler for the most complex matching rule.
Parameters: - request (Request) -- The request object.
- responder (DialogueResponder) -- The responder object.
- target_dialogue_state (str, optional) -- The target dialogue state.
Returns: A DialogueResponder containing the dialogue state and directives.
Return type: (DialogueResponder)
-
static
reprocess
(target_dialogue_state=None)[source]¶ Forces the dialogue manager to back out of the flow based on the initial target dialogue state setting and reselect a handler, following a new target dialogue state
Parameters: target_dialogue_state (str, optional) -- a dialogue_state name to push system into
-
logger
= <Logger mindmeld.components.dialogue.DialogueManager (WARNING)>¶
-
-
class
mindmeld.components.
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: 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:
-
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. Ifallowed_nlp_classes
isNone
, 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)
-
domains
¶ The domains supported by this application.
-
-
class
mindmeld.components.
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."¶
-
class
mindmeld.components.
QuestionAnswererFactory
[source]¶ Bases:
object
Factory class for creating QuestionAnswerers
- usage
>>> question_answerer = QuestionAnswererFactory.create_question_answerer(**kwargs) >>> question_answerer.load_kb(...) >>> question_answerer.get(...) # .get(...) or .build_search(...)
-
classmethod
create_question_answerer
(app_path=None, config=None, app_namespace=None, **kwargs)[source]¶ Parameters: - app_path (str, optional) -- The path to the directory containing the app's data. If provided, used to obtain default 'app_namespace' and QA configurations
- app_namespace (str, optional) -- The namespace of the app. Used to prevent collisions between the indices of this app and those of other apps.
- config (dict, optional) -- The QA config if passed directly rather than loaded from the app config
-
class
mindmeld.components.
EntityResolver
[source]¶ Bases:
object
Class for backwards compatibility
- deprecated usage
>>> entity_resolver = EntityResolver( app_path, resource_loader, entity_type )
- new usage
>>> entity_resolver = EntityResolverFactory.create_resolver( app_path, entity_type ) # or ... >>> entity_resolver = EntityResolverFactory.create_resolver( app_path, entity_type, resource_loader=resource_loader )
-
class
mindmeld.components.
EntityResolverFactory
[source]¶ Bases:
object
-
classmethod
create_resolver
(app_path, entity_type, config=None, resource_loader=None, **kwargs)[source]¶ - Identifies appropriate entity resolver based on input config and
- returns it.
Parameters: - app_path (str) -- The application path.
- entity_type (str) -- The entity type associated with this entity resolver.
- resource_loader (ResourceLoader) -- An object which can load resources for the resolver.
- er_config (dict) -- A classifier config
- es_host (str) -- The Elasticsearch host server.
- es_client (Elasticsearch) -- The Elasticsearch client.
-
classmethod
-
class
mindmeld.components.
Request
(*, domain=None, intent=None, entities=NOTHING, history=NOTHING, text=None, frame=immutables.Map({}), params=FrozenParams(allowed_intents=(), allow_nlp=(), deny_nlp=(), target_dialogue_state=None, time_zone=None, timestamp=None, language=None, locale=None, dynamic_resource=immutables.Map({})), context=immutables.Map({}), confidences=immutables.Map({}), nbest_transcripts_text=NOTHING, nbest_transcripts_entities=NOTHING, nbest_aligned_entities=NOTHING, form=NOTHING)[source]¶ Bases:
object
The Request is an object passed in through the Dialogue Manager and contains all the information provided by the application client for the dialogue handler to act on. Note: the Request object is read-only since it represents the client state, which should not be mutated.
-
domains
¶ str -- Domain of the current query.
-
intent
¶ str -- Intent of the current query.
-
entities
¶ list of dicts -- A list of entities in the current query.
-
history
¶ list of dicts -- List of previous and current responder objects (de-serialized) up to the current conversation.
-
text
¶ str -- The query text.
-
frame
¶ Immutables Map of stored data across multiple dialogue turns.
-
params
¶ Params -- An object that modifies how MindMeld process the current turn.
-
context
¶ dict -- Immutables Map containing front-end client state that is passed to the application from the client in the request.
-
confidences
¶ dict -- Immutables Map of keys
domains
,intents
,entities
androles
containing confidence probabilities across all labels for each classifier.
-
nbest_transcripts_text
¶ tuple -- List of alternate n-best transcripts from an ASR system
-
nbest_transcripts_entities
¶ tuple -- List of lists of extracted entities for each of the n-best transcripts.
-
nbest_aligned_entities
¶ tuple -- List of lists of aligned entities for each of the n-best transcripts.
-
-
mindmeld.components.
invoke_custom_action_async
(name, config, request, responder, merge=True)[source]¶
Submodules¶
- mindmeld.components.classifier module
- mindmeld.components.client module
- mindmeld.components.custom_action module
- mindmeld.components.dialogue module
- mindmeld.components.domain_classifier module
- mindmeld.components.entity_recognizer module
- mindmeld.components.entity_resolver module
- mindmeld.components.intent_classifier module
- mindmeld.components.nlp module
- mindmeld.components.parser module
- mindmeld.components.question_answerer module
- mindmeld.components.request module
- mindmeld.components.role_classifier module
- mindmeld.components.schemas module
- mindmeld.components.translators module