allenai / allennlp

An open-source NLP research library, built on PyTorch.
http://www.allennlp.org
Apache License 2.0
11.76k stars 2.25k forks source link

Sample code requested - how to use latest WikiTablesSemanticParser and model #3244

Closed ghost closed 5 years ago

ghost commented 5 years ago

This is in related to #3242 . Opening this case , as #3242 is closed.

Hi @pdasigi : Thanks for latest model . Can you please share sample code how to load it. From old code reference I am not able to load it. New code uses WikiTablesSemanticParserwhich needs some parameters. Also, following also give some error

predictor=Predictor.by_name('wikitables-parser')
predictor()

TypeError: __init__() missing 2 required positional arguments: 'model' and 'dataset_reader'

And following code gives this error:

from allennlp.predictors.predictor import Predictor
predictor = Predictor.from_path(r'C:\Users\sandeep.a.bhutani\Downloads\wikitables-model-2019.07.29.tar.gz')

WARNING:allennlp.common.params:_jsonnet not loaded, treating C:\Users\SANDEE~1.BHU\AppData\Local\Temp\tmpq6yq3xqf\config.json as json
WARNING:allennlp.models.semantic_parsing.wikitables.wikitables_erm_semantic_parser:MML model file for initializing weights is passed, but does not exist. This is fine if you're just decoding.
Traceback (most recent call last):

  File "<ipython-input-74-cfad09551928>", line 1, in <module>
    predictor = Predictor.from_path(r'C:\Users\sandeep.a.bhutani\Downloads\wikitables-model-2019.07.29.tar.gz')

  File "C:\Softwares\Continuum\anaconda3\lib\site-packages\allennlp\predictors\predictor.py", line 258, in from_path
    dataset_reader_to_load=dataset_reader_to_load)

  File "C:\Softwares\Continuum\anaconda3\lib\site-packages\allennlp\predictors\predictor.py", line 276, in from_archive
    raise ConfigurationError(f"No default predictor for model type {model_type}.\n"\

ConfigurationError: 'No default predictor for model type wikitables_erm_parser.\nPlease specify a predictor explicitly.'

Can some sample code be available please, so that latest model can be used (Same way as other samples are listed in https://allennlp.org/models )

pdasigi commented 5 years ago

@SandeepBhutani The issue is that for the Predictor class currently does not specify a default predictor for wikitables_erm_parser, which is the model type I shared with you. It does so only for wikitables_mml_parser (https://github.com/allenai/allennlp/blob/master/allennlp/predictors/predictor.py#L37). However, you can explicitly specify which predictor to use.

Command line: allennlp predict /path/to/model/file /path/to/input --predictor wikitables-parser

Library:

from allennlp.predictors import Predictor
predictor = Predictor.from_path("/path/to/model", predictor_name='wikitables-parser')
output = predictor.predict_json({"question": "what type of character is kili?", "table": "character\ttype\nkili\tdwarf\nlegolas\telf"})
print(output["answer"])
ghost commented 5 years ago

Thanks .. that worked