salesforce / TabularSemanticParsing

Translating natural language questions to a structured query language
https://arxiv.org/abs/2012.12627
BSD 3-Clause "New" or "Revised" License
221 stars 52 forks source link

TypeError when training on Spider #1

Closed kalleknast closed 3 years ago

kalleknast commented 3 years ago

Training on the spider data set fails with TypeError: '<' not supported between instances of 'NoneType' and 'int'.

The only modification made is using a smaller batch size, 8 instead of 16, to avoid memory issues. I have not tried to debug vectorizers.py.

Training on WikiSQL worked fine.

The full error:

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/hjalmar/Python/TabularSemanticParsing/src/experiments.py", line 407, in <module>
    run_experiment(args)
  File "/home/hjalmar/Python/TabularSemanticParsing/src/experiments.py", line 392, in run_experiment
    train(sp)
  File "/home/hjalmar/Python/TabularSemanticParsing/src/experiments.py", line 63, in train
    sp.run_train(train_data, dev_data)
  File "/home/hjalmar/Python/TabularSemanticParsing/src/common/learn_framework.py", line 207, in run_train
    formatted_batch = self.format_batch(mini_batch)
  File "/home/hjalmar/Python/TabularSemanticParsing/src/semantic_parser/learn_framework.py", line 425, in format_batch
    vec.vectorize_field_ptr_out(exp.program_singleton_field_tokens,
  File "/home/hjalmar/Python/TabularSemanticParsing/src/data_processor/vectorizers.py", line 102, in vectorize_field_ptr_out
    if schema_pos < num_included_nodes:
TypeError: '<' not supported between instances of 'NoneType' and 'int'
civp commented 3 years ago

In the method format_batch, gt_tables are not defined for Spider, so some essential tables are dropped. In another word, the schema_graph is not complete. That is why you got a None for schema_pos.

I am also trying to solve this problem.

1160300911 commented 3 years ago

Hi, I also encountered this problem. Is there any solution now? Thx.

duyvuleo commented 3 years ago

Same to me.

whuFSN commented 3 years ago

On line 360 in src/semantic_parser/learn_framework.py, exp.gt_table_names_listis None, so the ground truth tables gt_tables is an empty list. When dropping tables, ground truth tables will be dropped, which leads the schema_pos is None.

So change line 362~363

else:
    gt_tables = []

to

else:
    gt_table_names = [token for token, t in
     zip(exp.program_singleton_field_tokens, exp.program_singleton_field_token_types) if t == 0]
    gt_tables = set([schema_graph.get_table_id(t_name) for t_name in gt_table_names])
kalleknast commented 3 years ago

On line 360 in src/semantic_parser/learn_framework.py, exp.gt_table_names_listis None, so the ground truth tables gt_tables is an empty list. When dropping tables, ground truth tables will be dropped, which leads the schema_pos is None.

So change line 362~363

else:
    gt_tables = []

to

else:
    gt_table_names = [token for token, t in
     zip(exp.program_singleton_field_tokens, exp.program_singleton_field_token_types) if t == 0]
    gt_tables = set([schema_graph.get_table_id(t_name) for t_name in gt_table_names])

This fix seems to work. I could train for 6003 iterations before running into a probably unrelated torch/cudnn issue.

Will you (whuFSN) make a PR?

todpole3 commented 3 years ago

I updated the code and the issue is gone.

Many thanks to @whuFSN, great catch and fix.