mwptoolkit.module.Encoder.graph_based_encoder

class mwptoolkit.module.Encoder.graph_based_encoder.GraphBasedEncoder(embedding_size, hidden_size, rnn_cell_type, bidirectional, num_layers=2, dropout_ratio=0.5)[source]

Bases: Module

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(input_embedding, input_lengths, batch_graph, hidden=None)[source]
Parameters
  • input_embedding (torch.Tensor) – input variable, shape [sequence_length, batch_size, embedding_size].

  • input_lengths (torch.Tensor) – length of input sequence, shape: [batch_size].

  • batch_graph (torch.Tensor) – graph input variable, shape [batch_size, 5, sequence_length, sequence_length].

Returns

pade_outputs, encoded variable, shape [sequence_length, batch_size, hidden_size]. problem_output, vector representation of problem, shape [batch_size, hidden_size].

Return type

tuple(torch.Tensor, torch.Tensor)

training: bool
class mwptoolkit.module.Encoder.graph_based_encoder.GraphBasedMultiEncoder(input1_size, input2_size, embed_model, embedding1_size, embedding2_size, hidden_size, n_layers=2, hop_size=2, dropout=0.5)[source]

Bases: Module

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(input1_var, input2_var, input_length, parse_graph, hidden=None)[source]
training: bool
class mwptoolkit.module.Encoder.graph_based_encoder.GraphEncoder(vocab_size, embedding_size, hidden_size, sample_size, sample_layer, bidirectional, dropout_ratio)[source]

Bases: Module

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(fw_adj_info, bw_adj_info, feature_info, batch_nodes)[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.

training: bool
class mwptoolkit.module.Encoder.graph_based_encoder.NumEncoder(node_dim, hop_size=2)[source]

Bases: Module

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(encoder_outputs, num_encoder_outputs, num_pos_pad, num_order_pad)[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.

training: bool
mwptoolkit.module.Encoder.graph_based_encoder.replace_masked_values(tensor, mask, replace_with)[source]