deeppavlov.core.common

Registration and classes initialization functionality, class method decorators.

class deeppavlov.core.common.chainer.Chainer(in_x: Optional[Union[str, list]] = None, out_params: Optional[Union[str, list]] = None, in_y: Optional[Union[str, list]] = None, *args, **kwargs)[source]

Builds a component pipeline from heterogeneous components (Rule-based/ML/DL). It allows to train and infer models in a pipeline as a whole.

pipe

list of components and their input and output variable names for inference

train_pipe

list of components and their input and output variable names for training and evaluation

in_x

names of inputs for pipeline inference mode

out_params

names of pipeline inference outputs

in_y

names of additional inputs for pipeline training and evaluation modes

forward_map

list of all variables in chainer’s memory after running every component in self.pipe

train_map

list of all variables in chainer’s memory after running every component in train_pipe.pipe

main

reference to the main component

Parameters
  • in_x – names of inputs for pipeline inference mode

  • out_params – names of pipeline inference outputs

  • in_y – names of additional inputs for pipeline training and evaluation modes

__call__(*args)[source]

Call self as a function.

batched_call(*args: Reversible, batch_size: int = 16) Union[list, Tuple[list, ...]][source]

Partitions data into mini-batches and applies __call__() to each batch.

Parameters
  • args – input data, each element of the data corresponds to a single model inputs sequence.

  • batch_size – the size of a batch.

Returns

the model output as if the data was passed to the __call__() method.

class deeppavlov.core.common.base.Element(component: Union[Component, function], x: Optional[Union[str, list]] = None, out: Optional[Union[str, list]] = None, y: Optional[Union[str, list]] = None, main: bool = False)[source]

DeepPavlov model pipeline element.

__init__(component: Union[Component, function], x: Optional[Union[str, list]] = None, out: Optional[Union[str, list]] = None, y: Optional[Union[str, list]] = None, main: bool = False) None[source]
Parameters
  • component – Pipeline component object.

  • x – Names of the component inference inputs. Output from other pipeline elements with such names will be fed to the input of this component.

  • out – Names of the component inference outputs. Component outputs can be fed to other pipeline elements using this names.

  • y – Names of additional inputs (targets) for component training and evaluation.

  • main – Set True if this is the main component. Main component is trained during model training process.

class deeppavlov.core.common.base.Model(x: Optional[Union[str, list]] = None, out: Optional[Union[str, list]] = None, y: Optional[Union[str, list]] = None, pipe: Optional[List[Element]] = None)[source]

Builds a component pipeline to train and infer models.

__init__(x: Optional[Union[str, list]] = None, out: Optional[Union[str, list]] = None, y: Optional[Union[str, list]] = None, pipe: Optional[List[Element]] = None) None[source]
Parameters
  • x – Names of pipeline inference inputs.

  • out – Names of pipeline inference outputs.

  • y – Names of additional inputs (targets) for pipeline training and evaluation.

  • pipe – List of pipeline elements.

deeppavlov.core.common.metrics_registry.fn_from_str(name: str) Callable[[...], Any][source]

Returns a function object with the name given in string.

deeppavlov.core.common.metrics_registry.get_metric_by_name(name: str) Callable[[...], Any][source]

Returns a metric callable with a corresponding name.

deeppavlov.core.common.metrics_registry.register_metric(metric_name: str) Callable[[...], Any][source]

Decorator for metric registration.

deeppavlov.core.common.params.from_params(params: Dict, mode: str = 'infer', **kwargs) Union[Component, function][source]

Builds and returns the Component from corresponding dictionary of parameters.

deeppavlov.core.common.registry.cls_from_str(name: str) type[source]

Returns a class object with the name given as a string.

deeppavlov.core.common.registry.get_model(name: str) type[source]

Returns a registered class object with the name given in the string.

deeppavlov.core.common.registry.list_models() list[source]

Returns a list of names of registered classes.

deeppavlov.core.common.registry.register(name: Optional[str] = None) type[source]

Register classes that could be initialized from JSON configuration file. If name is not passed, the class name is converted to snake-case.

deeppavlov.core.common.registry.short_name(cls: type) str[source]

Returns just a class name (without package and module specification).