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:
-
add_middleware
(middleware)[source]¶ Adds middleware for the dialogue manager
Parameters: middleware (callable) -- A dialogue manager middleware function
-
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.
-
lazy_init
(nlp=None)[source]¶ Initialize the application manager, spin up the server and compile the dialogue rules.
-
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: 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.
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.
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.
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¶
- mindmeld.active_learning package
- mindmeld.bot package
- mindmeld.components package
- 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
- Submodules
- mindmeld.converter package
- mindmeld.models package
- Subpackages
- Submodules
- mindmeld.models.containers module
- mindmeld.models.embedder_models module
- mindmeld.models.evaluation module
- mindmeld.models.helpers module
- mindmeld.models.labels module
- mindmeld.models.model module
- mindmeld.models.model_factory module
- mindmeld.models.tagger_models module
- mindmeld.models.text_models module
- mindmeld.text_preparation package
Submodules¶
- mindmeld.app module
- mindmeld.app_manager module
- mindmeld.augmentation module
- mindmeld.auto_annotator module
- mindmeld.core module
- mindmeld.exceptions module
- mindmeld.gazetteer module
- mindmeld.markup module
- mindmeld.path module
- mindmeld.query_cache module
- mindmeld.query_factory module
- mindmeld.resource_loader module
- mindmeld.ser module
- mindmeld.server module
- mindmeld.system_entity_recognizer module