scibert icon indicating copy to clipboard operation
scibert copied to clipboard

How to get predictions for realtion extraction task using SciBERT

Open krzyszto9 opened this issue 6 years ago • 4 comments

I tried to get predictions in that way: allennlp predict out-1/model.tar.gz text.txt --include-package scibert

but i get error saying allennlp.common.checks.ConfigurationError: 'No default predictor for model type text_classifier.\nPlease specify a predictor explicitly.'

Is there any way to get predictions for trained model / what allennlp predictor should i use?

krzyszto9 avatar Jul 01 '19 14:07 krzyszto9

can you try adding the argument --use-dataset-reader to your command line?

ibeltagy avatar Jul 03 '19 19:07 ibeltagy

Getting same issue, with and without the --use-dataset-reader argument. Using google colab for training as detailed here. Trying to run the predict command as follows:

!echo '{"text":"the hip bone is connected to the leg bone."}\n' > dummydata.txt
!python -m allennlp.run predict --include-package scibert --use-dataset-reader modeltest0/model.tar.gz dummydata.txt

Which produces the following traceback:

2019-08-15 19:10:37,221 - INFO - allennlp.nn.initializers -    text_field_embedder.token_embedder_bert.bert_model.pooler.dense.weight
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/content/scibert/src/allennlp/allennlp/run.py", line 21, in <module>
    run()
  File "/content/scibert/src/allennlp/allennlp/run.py", line 18, in run
    main(prog="allennlp")
  File "/content/scibert/src/allennlp/allennlp/commands/__init__.py", line 101, in main
    args.func(args)
  File "/content/scibert/src/allennlp/allennlp/commands/predict.py", line 187, in _predict
    predictor = _get_predictor(args)
  File "/content/scibert/src/allennlp/allennlp/commands/predict.py", line 101, in _get_predictor
    return Predictor.from_archive(archive, args.predictor)
  File "/content/scibert/src/allennlp/allennlp/predictors/predictor.py", line 157, in from_archive
    raise ConfigurationError(f"No default predictor for model type {model_type}.\n"\
allennlp.common.checks.ConfigurationError: 'No default predictor for model type bert_text_classifier.\nPlease specify a predictor explicitly.'
2019-08-15 19:10:37,659 - INFO - allennlp.models.archival - removing temporary unarchived model dir at /tmp/tmpygi3zk4o

dmarx avatar Aug 15 '19 19:08 dmarx

Looks like you need to add a dummy predictor for it to work, something like:

@Predictor.register('dummy_predictor')
class DummyPredictor(Predictor):
    pass

then in the command line add --predictor dummy_predictor

ibeltagy avatar Oct 30 '19 17:10 ibeltagy

Thanks for your reply on this issue. I had deleted my comment because I think I solved the problem by explicitly specifying the predictor with --predictor text_classifier in the command line.

mmorine avatar Oct 30 '19 18:10 mmorine