pytext.models.ensembles package

Submodules

pytext.models.ensembles.bagging_doc_ensemble module

class pytext.models.ensembles.bagging_doc_ensemble.BaggingDocEnsemble(config: pytext.models.ensembles.ensemble.Ensemble.Config, models: List[pytext.models.model.Model], *args, **kwargs)[source]

Bases: pytext.models.ensembles.ensemble.Ensemble

Ensemble class that uses bagging for ensembling document classification models.

Config[source]

alias of BaggingDocEnsemble.Config

forward(*args, **kwargs) → torch.Tensor[source]

Call forward() method of each document classification sub-model by passing all arguments and named arguments to the sub-models, collect the logits from them and average their values.

Returns:Logits from the ensemble.
Return type:torch.Tensor

pytext.models.ensembles.bagging_intent_slot_ensemble module

class pytext.models.ensembles.bagging_intent_slot_ensemble.BaggingIntentSlotEnsemble(config: pytext.models.ensembles.bagging_intent_slot_ensemble.BaggingIntentSlotEnsemble.Config, models: List[pytext.models.model.Model], *args, **kwargs)[source]

Bases: pytext.models.ensembles.ensemble.Ensemble

Ensemble class that uses bagging for ensembling intent-slot models.

Parameters:
  • config (Config) – Configuration object specifying all the parameters of BaggingIntentSlotEnsemble.
  • models (List[Model]) – List of intent-slot model objects.
use_crf

bool – Whether to use CRF for word tagging task.

output_layer

IntentSlotOutputLayer – Output layer of intent-slot model responsible for computing loss and predictions.

Config[source]

alias of BaggingIntentSlotEnsemble.Config

forward(*args, **kwargs) → torch.Tensor[source]

Call forward() method of each intent-slot sub-model by passing all arguments and named arguments to the sub-models, collect the logits from them and average their values.

Returns:Logits from the ensemble.
Return type:torch.Tensor
merge_sub_models() → None[source]

Merges all sub-models’ transition matrices when using CRF. Otherwise does nothing.

pytext.models.ensembles.ensemble module

class pytext.models.ensembles.ensemble.Ensemble(config: pytext.models.ensembles.ensemble.Ensemble.Config, models: List[pytext.models.model.Model], *args, **kwargs)[source]

Bases: pytext.models.model.Model

Base class for ensemble models.

Parameters:
  • config (Config) – Configuration object specifying all the parameters of Ensemble.
  • models (List[Model]) – List of sub-model objects.
output_layer

OutputLayerBase – Responsible for computing loss and predictions.

models

nn.ModuleList] – ModuleList container for sub-model objects.

Config[source]

alias of Ensemble.Config

forward(*args, **kwargs)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

classmethod from_config(config: pytext.models.ensembles.ensemble.Ensemble.Config, feat_config: pytext.config.field_config.FeatureConfig, *args, **kwargs)[source]

Factory method to construct an instance of Ensemble or one its derived classes from the module’s config object and the field’s metadata object. It creates sub-models in the ensemble using the sub-model’s configuration.

Parameters:
  • config (Config) – Configuration object specifying all the parameters of Ensemble.
  • feat_config (FeatureConfig) – Configuration object specifying all the parameters of the input features to the model.
Returns:

An instance of Ensemble.

Return type:

type

merge_sub_models()[source]
save_modules(base_path: str = '', suffix: str = '') → None[source]

Saves the modules of all sub_models in the Ensemble.

Parameters:
  • base_path (str) – Path of base directory. Defaults to “”.
  • suffix (str) – Suffix to add to the file name to save. Defaults to “”.

Module contents

class pytext.models.ensembles.BaggingDocEnsemble(config: pytext.models.ensembles.ensemble.Ensemble.Config, models: List[pytext.models.model.Model], *args, **kwargs)[source]

Bases: pytext.models.ensembles.ensemble.Ensemble

Ensemble class that uses bagging for ensembling document classification models.

Config[source]

alias of BaggingDocEnsemble.Config

forward(*args, **kwargs) → torch.Tensor[source]

Call forward() method of each document classification sub-model by passing all arguments and named arguments to the sub-models, collect the logits from them and average their values.

Returns:Logits from the ensemble.
Return type:torch.Tensor
class pytext.models.ensembles.BaggingIntentSlotEnsemble(config: pytext.models.ensembles.bagging_intent_slot_ensemble.BaggingIntentSlotEnsemble.Config, models: List[pytext.models.model.Model], *args, **kwargs)[source]

Bases: pytext.models.ensembles.ensemble.Ensemble

Ensemble class that uses bagging for ensembling intent-slot models.

Parameters:
  • config (Config) – Configuration object specifying all the parameters of BaggingIntentSlotEnsemble.
  • models (List[Model]) – List of intent-slot model objects.
use_crf

bool – Whether to use CRF for word tagging task.

output_layer

IntentSlotOutputLayer – Output layer of intent-slot model responsible for computing loss and predictions.

Config[source]

alias of BaggingIntentSlotEnsemble.Config

forward(*args, **kwargs) → torch.Tensor[source]

Call forward() method of each intent-slot sub-model by passing all arguments and named arguments to the sub-models, collect the logits from them and average their values.

Returns:Logits from the ensemble.
Return type:torch.Tensor
merge_sub_models() → None[source]

Merges all sub-models’ transition matrices when using CRF. Otherwise does nothing.