notice

This is unreleased documentation for Rasa Open Source Documentation Master/Unreleased version.
For the latest released documentation, see the latest version (2.x).

Version: Master/Unreleased

rasa.nlu.classifiers.sklearn_intent_classifier

SklearnIntentClassifierGraphComponent Objects

class SklearnIntentClassifierGraphComponent(GraphComponent, IntentClassifier2)

Intent classifier using the sklearn framework.

required_components

@classmethod
def required_components(cls) -> List[Type]

Components that should be included in the pipeline before this component.

get_default_config

@staticmethod
def get_default_config() -> Dict[Text, Any]

The component's default config (see parent class for full docstring).

__init__

def __init__(config: Dict[Text, Any], model_storage: ModelStorage, resource: Resource, clf: "sklearn.model_selection.GridSearchCV" = None, le: Optional["sklearn.preprocessing.LabelEncoder"] = None) -> None

Construct a new intent classifier using the sklearn framework.

create

@classmethod
def create(cls, config: Dict[Text, Any], model_storage: ModelStorage, resource: Resource, execution_context: ExecutionContext) -> SklearnIntentClassifierGraphComponent

Creates a new untrained component (see parent class for full docstring).

required_packages

@classmethod
def required_packages(cls) -> List[Text]

Any extra python dependencies required for this component to run.

transform_labels_str2num

def transform_labels_str2num(labels: List[Text]) -> np.ndarray

Transforms a list of strings into numeric label representation.

Arguments:

  • labels: List of labels to convert to numeric representation

transform_labels_num2str

def transform_labels_num2str(y: np.ndarray) -> np.ndarray

Transforms a list of strings into numeric label representation.

Arguments:

  • y: List of labels to convert to numeric representation

train

def train(training_data: TrainingData) -> Resource

Train the intent classifier on a data set.

process

def process(messages: List[Message]) -> List[Message]

Return the most likely intent and its probability for a message.

predict_prob

def predict_prob(X: np.ndarray) -> np.ndarray

Given a bow vector of an input text, predict the intent label.

Return probabilities for all labels.

Arguments:

  • X: bow of input text

Returns:

vector of probabilities containing one entry for each label.

predict

def predict(X: np.ndarray) -> Tuple[np.ndarray, np.ndarray]

Given a bow vector of an input text, predict most probable label.

Return only the most likely label.

Arguments:

  • X: bow of input text

Returns:

tuple of first, the most probable label and second,

persist

def persist() -> None

Persist this model into the passed directory.

load

@classmethod
def load(cls, config: Dict[Text, Any], model_storage: ModelStorage, resource: Resource, execution_context: ExecutionContext, **kwargs: Any, ,) -> SklearnIntentClassifierGraphComponent

Loads trained component (see parent class for full docstring).