Penelope v0.2.3 Penelope.NLP.IntentClassifier

The intent classifier transforms a natural language utterance into a named intent and a set of named parameters. It uses an ML classifier to infer the intent name and an entity recognizer to extract named entities as parameters. These components are both represented as ML pipelines.

The intent classifier also maintains a tokenizer pipeline for converting utterances into a list of tokens. This pipeline is executed first, and its results are run through the classifier/recognizer pipelines.

Classification results are returned as a tuple of , where intent is the name of the classified intent, and parameters is a name->value map. Intent names, parameter names and parameter values are all strings.

Example: pipeline = %{

tokenizer: [{:ptb_tokenizer, []}],
classifier: [{:count_vectorizer, []}, {:svm_classifier, [c: 2.0]}],
recognizer: [{:crf_tagger, []}],

} x = [

"you have four pears",
"these one hundred apples"

] y = [

{"intent_2", ["o", "o", "b_num", "b_fruit"]},
{"intent_3", ["o", "b_num", "i_num", "b_fruit"]}

] classifier = Penelope.NLP.IntentClassifier.fit(%{}, x, y, pipeline)

{intent, params} = Penelope.NLP.IntentClassifier.predict_intent(

classifier,
%{},
"you have three pears"

)

Link to this section Summary

Functions

imports parameters from a serialized model

exports a runtime model to a serializable data structure

fits the tokenizer, classifier, and recognizer models

predicts an intent and its parameters from an utterance string

Link to this section Types

Link to this type model()
model() :: %{tokenizer: [{atom(), any()}], classifier: [{atom(), any()}], recognizer: [{atom(), any()}]}

Link to this section Functions

Link to this function compile(params)
compile(params :: map()) :: model()

imports parameters from a serialized model

Link to this function export(model)
export(model :: model()) :: map()

exports a runtime model to a serializable data structure

Link to this function fit(context, x, y, pipelines)
fit(context :: map(), x :: [utterance :: String.t()], y :: [{intent :: String.t(), tags :: [String.t()]}], pipelines :: [tokenizer: [{String.t() | atom(), any()}], classifier: [{String.t() | atom(), any()}], recognizer: [{String.t() | atom(), any()}]]) :: model()

fits the tokenizer, classifier, and recognizer models

Link to this function predict_intent(model, context, x)
predict_intent(model :: model(), context :: map(), x :: [utterance :: String.t()]) :: {intent :: String.t(), params :: %{optional(name :: String.t()) => value :: String.t()}}

predicts an intent and its parameters from an utterance string