pytext.models.ensembles package¶
Submodules¶
pytext.models.ensembles.bagging_doc_ensemble module¶
-
class
pytext.models.ensembles.bagging_doc_ensemble.
BaggingDocEnsembleModel
(config: pytext.models.ensembles.ensemble.EnsembleModel.Config, models: List[pytext.models.model.Model], *args, **kwargs)[source]¶ Bases:
pytext.models.ensembles.ensemble.EnsembleModel
Ensemble class that uses bagging for ensembling document classification models.
pytext.models.ensembles.bagging_intent_slot_ensemble module¶
-
class
pytext.models.ensembles.bagging_intent_slot_ensemble.
BaggingIntentSlotEnsembleModel
(config: pytext.models.ensembles.bagging_intent_slot_ensemble.BaggingIntentSlotEnsembleModel.Config, models: List[pytext.models.model.Model], *args, **kwargs)[source]¶ Bases:
pytext.models.ensembles.ensemble.EnsembleModel
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
¶ Whether to use CRF for word tagging task.
Type: bool
-
output_layer
¶ Output layer of intent-slot model responsible for computing loss and predictions.
Type: IntentSlotOutputLayer
-
forward
(*args, **kwargs) → Tuple[torch.Tensor, 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
-
load_state_dict
(state_dict: Dict[str, torch.Tensor], strict: bool = True)[source]¶ Copies parameters and buffers from
state_dict
into this module and its descendants. Ifstrict
isTrue
, then the keys ofstate_dict
must exactly match the keys returned by this module’sstate_dict()
function.Parameters: - state_dict (dict) – a dict containing parameters and persistent buffers.
- strict (bool, optional) – whether to strictly enforce that the keys
in
state_dict
match the keys returned by this module’sstate_dict()
function. Default:True
Returns: - missing_keys is a list of str containing the missing keys
- unexpected_keys is a list of str containing the unexpected keys
Return type: NamedTuple
withmissing_keys
andunexpected_keys
fields
pytext.models.ensembles.ensemble module¶
-
class
pytext.models.ensembles.ensemble.
EnsembleModel
(config: pytext.models.ensembles.ensemble.EnsembleModel.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
¶ Responsible for computing loss and predictions.
Type: OutputLayerBase
-
models
¶ ModuleList container for sub-model objects.
Type: nn.ModuleList]
-
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.EnsembleModel.Config, tensorizers: Dict[str, pytext.data.tensorizers.Tensorizer], *args, **kwargs)[source]¶ Factory method to construct an instance of Ensemble or one its derived classes from the module’s config object and tensorizers It creates sub-models in the ensemble using the sub-model’s configuration.
Parameters: - config (Config) – Configuration object specifying all the parameters of Ensemble.
- tensorizers (Dict[str, Tensorizer]) – Tensorizer specifying all the parameters of the input features to the model.
Returns: An instance of Ensemble.
Return type: type
Module contents¶
-
class
pytext.models.ensembles.
BaggingDocEnsembleModel
(config: pytext.models.ensembles.ensemble.EnsembleModel.Config, models: List[pytext.models.model.Model], *args, **kwargs)[source]¶ Bases:
pytext.models.ensembles.ensemble.EnsembleModel
Ensemble class that uses bagging for ensembling document classification models.
-
class
pytext.models.ensembles.
BaggingIntentSlotEnsembleModel
(config: pytext.models.ensembles.bagging_intent_slot_ensemble.BaggingIntentSlotEnsembleModel.Config, models: List[pytext.models.model.Model], *args, **kwargs)[source]¶ Bases:
pytext.models.ensembles.ensemble.EnsembleModel
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
¶ Whether to use CRF for word tagging task.
Type: bool
-
output_layer
¶ Output layer of intent-slot model responsible for computing loss and predictions.
Type: IntentSlotOutputLayer
-
forward
(*args, **kwargs) → Tuple[torch.Tensor, 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
-
load_state_dict
(state_dict: Dict[str, torch.Tensor], strict: bool = True)[source]¶ Copies parameters and buffers from
state_dict
into this module and its descendants. Ifstrict
isTrue
, then the keys ofstate_dict
must exactly match the keys returned by this module’sstate_dict()
function.Parameters: - state_dict (dict) – a dict containing parameters and persistent buffers.
- strict (bool, optional) – whether to strictly enforce that the keys
in
state_dict
match the keys returned by this module’sstate_dict()
function. Default:True
Returns: - missing_keys is a list of str containing the missing keys
- unexpected_keys is a list of str containing the unexpected keys
Return type: NamedTuple
withmissing_keys
andunexpected_keys
fields
-
class
pytext.models.ensembles.
EnsembleModel
(config: pytext.models.ensembles.ensemble.EnsembleModel.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
¶ Responsible for computing loss and predictions.
Type: OutputLayerBase
-
models
¶ ModuleList container for sub-model objects.
Type: nn.ModuleList]
-
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.EnsembleModel.Config, tensorizers: Dict[str, pytext.data.tensorizers.Tensorizer], *args, **kwargs)[source]¶ Factory method to construct an instance of Ensemble or one its derived classes from the module’s config object and tensorizers It creates sub-models in the ensemble using the sub-model’s configuration.
Parameters: - config (Config) – Configuration object specifying all the parameters of Ensemble.
- tensorizers (Dict[str, Tensorizer]) – Tensorizer specifying all the parameters of the input features to the model.
Returns: An instance of Ensemble.
Return type: type