pytext.models.decoders package

Submodules

pytext.models.decoders.decoder_base module

class pytext.models.decoders.decoder_base.DecoderBase(config: pytext.config.pytext_config.ConfigBase)[source]

Bases: pytext.models.module.Module

Base class for all decoder modules.

Parameters:config (ConfigBase) – Configuration object.
in_dim

int – Dimension of input Tensor passed to the decoder.

out_dim

int – Dimension of output Tensor produced by the decoder.

Config

alias of pytext.config.component.ComponentMeta.__new__.<locals>.Config

forward(*input)[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.

get_decoder()[source]

Returns the decoder module.

get_in_dim() → int[source]

Returns the dimension of the input Tensor that the decoder accepts.

get_out_dim() → int[source]

Returns the dimension of the input Tensor that the decoder emits.

pytext.models.decoders.intent_slot_model_decoder module

class pytext.models.decoders.intent_slot_model_decoder.IntentSlotModelDecoder(config: pytext.models.decoders.intent_slot_model_decoder.IntentSlotModelDecoder.Config, in_dim_doc: int, in_dim_word: int, out_dim_doc: int, out_dim_word: int)[source]

Bases: pytext.models.decoders.decoder_base.DecoderBase

IntentSlotModelDecoder implements the decoder layer for intent-slot models. Intent-slot models jointly predict intent and slots from an utterance. At the core these models learn to jointly perform document classification and word tagging tasks.

IntentSlotModelDecoder accepts arguments for decoding both document
classification and word tagging tasks, namely, in_dim_doc and in_dim_word.
Parameters:
  • config (type) – Configuration object of type IntentSlotModelDecoder.Config.
  • in_dim_doc (type) – Dimension of input Tensor for projecting document
  • representation.
  • in_dim_word (type) – Dimension of input Tensor for projecting word
  • representation.
  • out_dim_doc (type) – Dimension of projected output Tensor for document
  • classification.
  • out_dim_word (type) – Dimension of projected output Tensor for word tagging.
use_doc_probs_in_word

bool – Whether to use intent probabilities for

predicting slots.
doc_decoder

type – Document/intent decoder module.

word_decoder

type – Word/slot decoder module.

Config[source]

alias of IntentSlotModelDecoder.Config

forward(x_d: torch.Tensor, x_w: torch.Tensor) → List[torch.Tensor][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.

get_decoder() → List[torch.nn.modules.module.Module][source]

Returns the document and word decoder modules.

pytext.models.decoders.mlp_decoder module

class pytext.models.decoders.mlp_decoder.MLPDecoder(config: pytext.models.decoders.mlp_decoder.MLPDecoder.Config, in_dim: int, out_dim: int = 0)[source]

Bases: pytext.models.decoders.decoder_base.DecoderBase

MLPDecoder implements a fully connected network and uses ReLU as the activation function. The module projects an input tensor to out_dim.

Parameters:
  • config (Config) – Configuration object of type MLPDecoder.Config.
  • in_dim (int) – Dimension of input Tensor passed to MLP.
  • out_dim (int) – Dimension of output Tensor produced by MLP. Defaults to 0.
mlp

type – Module that implements the MLP.

out_dim

type – Dimension of the output of this module.

hidden_dims

List[int] – Dimensions of the outputs of hidden layers.

Config[source]

alias of MLPDecoder.Config

forward(*input) → torch.Tensor[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.

get_decoder() → List[torch.nn.modules.module.Module][source]

Returns the MLP module that is used as a decoder.

Module contents

class pytext.models.decoders.DecoderBase(config: pytext.config.pytext_config.ConfigBase)[source]

Bases: pytext.models.module.Module

Base class for all decoder modules.

Parameters:config (ConfigBase) – Configuration object.
in_dim

int – Dimension of input Tensor passed to the decoder.

out_dim

int – Dimension of output Tensor produced by the decoder.

Config

alias of pytext.config.component.ComponentMeta.__new__.<locals>.Config

forward(*input)[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.

get_decoder()[source]

Returns the decoder module.

get_in_dim() → int[source]

Returns the dimension of the input Tensor that the decoder accepts.

get_out_dim() → int[source]

Returns the dimension of the input Tensor that the decoder emits.

class pytext.models.decoders.MLPDecoder(config: pytext.models.decoders.mlp_decoder.MLPDecoder.Config, in_dim: int, out_dim: int = 0)[source]

Bases: pytext.models.decoders.decoder_base.DecoderBase

MLPDecoder implements a fully connected network and uses ReLU as the activation function. The module projects an input tensor to out_dim.

Parameters:
  • config (Config) – Configuration object of type MLPDecoder.Config.
  • in_dim (int) – Dimension of input Tensor passed to MLP.
  • out_dim (int) – Dimension of output Tensor produced by MLP. Defaults to 0.
mlp

type – Module that implements the MLP.

out_dim

type – Dimension of the output of this module.

hidden_dims

List[int] – Dimensions of the outputs of hidden layers.

Config[source]

alias of MLPDecoder.Config

forward(*input) → torch.Tensor[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.

get_decoder() → List[torch.nn.modules.module.Module][source]

Returns the MLP module that is used as a decoder.

class pytext.models.decoders.IntentSlotModelDecoder(config: pytext.models.decoders.intent_slot_model_decoder.IntentSlotModelDecoder.Config, in_dim_doc: int, in_dim_word: int, out_dim_doc: int, out_dim_word: int)[source]

Bases: pytext.models.decoders.decoder_base.DecoderBase

IntentSlotModelDecoder implements the decoder layer for intent-slot models. Intent-slot models jointly predict intent and slots from an utterance. At the core these models learn to jointly perform document classification and word tagging tasks.

IntentSlotModelDecoder accepts arguments for decoding both document
classification and word tagging tasks, namely, in_dim_doc and in_dim_word.
Parameters:
  • config (type) – Configuration object of type IntentSlotModelDecoder.Config.
  • in_dim_doc (type) – Dimension of input Tensor for projecting document
  • representation.
  • in_dim_word (type) – Dimension of input Tensor for projecting word
  • representation.
  • out_dim_doc (type) – Dimension of projected output Tensor for document
  • classification.
  • out_dim_word (type) – Dimension of projected output Tensor for word tagging.
use_doc_probs_in_word

bool – Whether to use intent probabilities for

predicting slots.
doc_decoder

type – Document/intent decoder module.

word_decoder

type – Word/slot decoder module.

Config[source]

alias of IntentSlotModelDecoder.Config

forward(x_d: torch.Tensor, x_w: torch.Tensor) → List[torch.Tensor][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.

get_decoder() → List[torch.nn.modules.module.Module][source]

Returns the document and word decoder modules.