claf.model.semantic_parsing package

Submodules

class claf.model.semantic_parsing.mixin.WikiSQL[source]

Bases: object

WikiSQL Mixin Class

with official evaluation

  • Args:

    token_embedder: ‘TokenEmbedder’

AGG_OPS = ['None', 'MAX', 'MIN', 'COUNT', 'SUM', 'AVG']
COND_OPS = ['EQL', 'GT', 'LT']
decode_pointer(tokenized_question, cond_value_logits)[source]
generate_queries(output_dict)[source]
make_metrics(predictions)[source]

aggregator, select_column, conditions accuracy

make_predictions(output_dict)[source]
merge_tokens(tok_list, raw_tok_str)[source]
predict(**kwargs)
print_examples(index, inputs, predictions)[source]

Print evaluation examples

  • Args:

    index: data index inputs: mini-batch inputs predictions: prediction dictionary consisting of

    • key: ‘id’ (question id)

    • value: consisting of dictionary

      table_id, query (agg, sel, conds)

  • Returns:

    print(Context, Question, Answers and Predict)

class claf.model.semantic_parsing.sqlnet.AggPredictor(embed_dim, model_dim, rnn_num_layer, dropout, agg_count)[source]

Bases: torch.nn.modules.module.Module

forward(question_embed, question_mask)[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 claf.model.semantic_parsing.sqlnet.CondsColPredictor(embed_dim, model_dim, rnn_num_layer, dropout, column_attention=None)[source]

Bases: torch.nn.modules.module.Module

forward(question_embed, question_mask, column_embed, column_name_mask, column_mask)[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 claf.model.semantic_parsing.sqlnet.CondsNumPredictor(embed_dim, model_dim, rnn_num_layer, dropout, column_maxlen)[source]

Bases: torch.nn.modules.module.Module

forward(question_embed, question_mask, column_embed, column_name_mask, column_mask)[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 claf.model.semantic_parsing.sqlnet.CondsOpPredictor(embed_dim, model_dim, rnn_num_layer, dropout, op_count, column_maxlen, column_attention=None)[source]

Bases: torch.nn.modules.module.Module

forward(question_embed, question_mask, column_embed, column_name_mask, col_idx)[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 claf.model.semantic_parsing.sqlnet.CondsPredictor(embed_dim, model_dim, rnn_num_layer, dropout, conds_op_count, column_maxlen, token_maxlen, column_attention=None)[source]

Bases: torch.nn.modules.module.Module

forward(question_embed, question_mask, column_embed, column_name_mask, column_mask, col_idx, conds_val_pos)[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 claf.model.semantic_parsing.sqlnet.CondsValuePointer(embed_dim, model_dim, rnn_num_layer, dropout, column_maxlen, token_maxlen)[source]

Bases: torch.nn.modules.module.Module

concat_start_and_end_zero_padding(question_embed, mask)[source]
decode_then_output(encoded_used_column, encoded_question, question_mask, decoder_input, decoder_hidden=None)[source]
forward(question_embed, question_mask, column_embed, column_name_mask, col_idx, conds_val_pos)[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 claf.model.semantic_parsing.sqlnet.SQLNet(token_embedder, column_attention=None, model_dim=100, rnn_num_layer=2, dropout=0.3, column_maxlen=4, token_maxlen=200, conds_column_loss_alpha=3)[source]

Bases: claf.model.semantic_parsing.mixin.WikiSQL, claf.model.base.ModelWithTokenEmbedder

Nature Language to SQL Query Model. Semantic Parsing, NL2SQL

Implementation of model presented in SQLNet: Generating Structured Queries From Natural Language

Without Reinforcement Learning

(https://arxiv.org/abs/1711.04436)

  • Args:

    token_embedder: ‘WikiSQLTokenEmbedder’, Used to embed the ‘column’ and ‘question’.

  • Kwargs:
    column_attention: highlight that column attention is a special instance of

    the generic attention mechanism to compute the attention map on a question conditioned on the column names.

    model_dim: the number of model dimension rnn_num_layer: the number of recurrent layers (all of rnn) column_maxlen: an upper-bound N on the number of columns to choose token_maxlen: conds value slot - pointer network an upper-bound N on the number of token conds_column_loss_alpha: balance the positive data versus negative data

forward(features, labels=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.

class claf.model.semantic_parsing.sqlnet.SelPredictor(embed_dim, model_dim, rnn_num_layer, dropout, column_attention=None)[source]

Bases: torch.nn.modules.module.Module

forward(question_embed, question_mask, column_embed, column_name_mask, column_mask)[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.

claf.model.semantic_parsing.utils.convert_position_to_decoder_input(conds_val_pos, token_maxlen=200)[source]
claf.model.semantic_parsing.utils.encode_column(column_embed, column_name_mask, rnn_module)[source]
claf.model.semantic_parsing.utils.filter_used_column(encoded_columns, col_idx, padding_count=4)[source]
claf.model.semantic_parsing.utils.get_column_lengths(column_embed, column_name_mask)[source]

Module contents

class claf.model.semantic_parsing.SQLNet(token_embedder, column_attention=None, model_dim=100, rnn_num_layer=2, dropout=0.3, column_maxlen=4, token_maxlen=200, conds_column_loss_alpha=3)[source]

Bases: claf.model.semantic_parsing.mixin.WikiSQL, claf.model.base.ModelWithTokenEmbedder

Nature Language to SQL Query Model. Semantic Parsing, NL2SQL

Implementation of model presented in SQLNet: Generating Structured Queries From Natural Language

Without Reinforcement Learning

(https://arxiv.org/abs/1711.04436)

  • Args:

    token_embedder: ‘WikiSQLTokenEmbedder’, Used to embed the ‘column’ and ‘question’.

  • Kwargs:
    column_attention: highlight that column attention is a special instance of

    the generic attention mechanism to compute the attention map on a question conditioned on the column names.

    model_dim: the number of model dimension rnn_num_layer: the number of recurrent layers (all of rnn) column_maxlen: an upper-bound N on the number of columns to choose token_maxlen: conds value slot - pointer network an upper-bound N on the number of token conds_column_loss_alpha: balance the positive data versus negative data

forward(features, labels=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.