Version: 3.x

rasa.nlu.utils.spacy_utils

SpacyModel Objects

@dataclasses.dataclass
class SpacyModel()

Wraps SpacyNLP output to make it fingerprintable.

fingerprint

def fingerprint() -> Text

Fingerprints the model name.

Use a static fingerprint as we assume this only changes if the model name changes and want to avoid investigating the model in greater detail for now.

Returns:

Fingerprint for model.

SpacyNLP Objects

@DefaultV1Recipe.register(
[
DefaultV1Recipe.ComponentType.MODEL_LOADER,
DefaultV1Recipe.ComponentType.MESSAGE_FEATURIZER,
],
is_trainable=False,
model_from="SpacyNLP",
)
class SpacyNLP(GraphComponent)

Component which provides the common loaded SpaCy model to others.

This is used to avoid loading the SpaCy model multiple times. Instead the Spacy model is only loaded once and then shared by depending components.

__init__

def __init__(model: SpacyModel, config: Dict[Text, Any]) -> None

Initializes a SpacyNLP.

get_default_config

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

Default config.

load_model

@staticmethod
def load_model(spacy_model_name: Text) -> SpacyModel

Try loading the model, catching the OSError if missing.

required_packages

@staticmethod
def required_packages() -> List[Text]

Lists required dependencies (see parent class for full docstring).

create

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

Creates component (see parent class for full docstring).

ensure_proper_language_model

@staticmethod
def ensure_proper_language_model(nlp: Optional[Language]) -> None

Checks if the SpaCy language model is properly loaded.

Raises an exception if the model is invalid.

provide

def provide() -> SpacyModel

Provides the loaded SpaCy model.

process_training_data

def process_training_data(training_data: TrainingData,
model: SpacyModel) -> TrainingData

Adds SpaCy tokens and features to training data messages.

process

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

Adds SpaCy tokens and features to messages.