mindmeld.models.nn_utils.layers module

class mindmeld.models.nn_utils.layers.CnnLayer(emb_dim: int, kernel_sizes: List[int], num_kernels: List[int])[source]

Bases: torch.nn.modules.module.Module

A pytorch wrapper layer for 2D Convolutions

forward(padded_token_embs: Tensor3d[float]) → Tensor2d[float][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.

class mindmeld.models.nn_utils.layers.EmbeddingLayer(num_tokens: int, emb_dim: int, padding_idx: int = None, embedding_weights: Dict[int, Union[List, numpy.ndarray]] = None, update_embeddings: bool = True, embeddings_dropout: float = 0.5, coefficients: List[float] = None, update_coefficients: bool = True)[source]

Bases: torch.nn.modules.module.Module

A pytorch wrapper layer for embeddings that takes input a batched sequence of ids and outputs embeddings corresponding to those ids

forward(padded_token_ids: Tensor2d[int]) → Tensor3d[float][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.

class mindmeld.models.nn_utils.layers.LstmLayer(emb_dim: int, hidden_dim: int, num_layers: int, lstm_dropout: float, bidirectional: bool)[source]

Bases: torch.nn.modules.module.Module

A pytorch wrapper layer for BiLSTMs

forward(padded_token_embs: Tensor3d[float], lengths: Tensor1d[int]) → Tensor3d[float][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.

class mindmeld.models.nn_utils.layers.PoolingLayer(pooling_type: str)[source]

Bases: torch.nn.modules.module.Module

A pooling layer for Tensor3d objects that pools along the last dimension. Assumes that padding if any exists on the right side of inputs (i.e. not in the beginning of inputs)

forward(padded_token_embs: Tensor3d[float], lengths: Tensor1d[int] = None) → Tensor2d[float][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.

class mindmeld.models.nn_utils.layers.SplittingAndPoolingLayer(pooling_type: str, number_of_terminal_tokens: int)[source]

Bases: torch.nn.modules.module.Module

Pooling class that first splits a sequence of representations into subgroups of representations based on lengths of subgroups inputted, and pools each subgroup separately.

forward(padded_token_embs: Tensor3d[float], span_lengths: List[Tensor1d[int]], discard_terminals: bool = None)[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.