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.utils.spacy_utils

SpacyModel Objects

@dataclasses.dataclass
class SpacyModel()

Wraps SpacyModelProvider 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.

SpacyModelProvider Objects

class SpacyModelProvider(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) -> None

Initializes a SpacyModelProvider.

load_model

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

Try loading the model, catching the OSError if missing.

required_packages

@classmethod
def required_packages(cls) -> 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) -> SpacyModelProvider

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.

SpacyPreprocessor Objects

class SpacyPreprocessor(GraphComponent)

Processes messages using SpaCy for use by SpacyTokenizer and SpacyFeaturizer.

get_default_config

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

Default config for SpacyPreprocessor.

__init__

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

Initializes a SpacyPreprocessor.

required_packages

@classmethod
def required_packages(cls) -> 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) -> SpacyPreprocessor

Creates component for training see parent class for full docstring).

process_training_data

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

Adds SpaCy tokens and features to training data messages.

process

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

Adds SpaCy tokens and features to messages.