allenai/sequential_sentence_classification

prediction steps

Opened this issue · 3 comments

It will be very helpful, if you let know how to use trained model to predict on new data. There is prediction.py , how there is no description or steps to be followed to run this.
Thanks.

Was facing the same problem...

You can create a scripts/predict.sh bash file as below, and then sh scripts/predict.sh it. That would be running the code in the sequential_sentence_classification/predictor.py file.

allennlp predict \
    /path/to/model.tar.gz \
    data/CSAbstruct/test.jsonl \
    --include-package sequential_sentence_classification \
    --predictor SeqClassificationPredictor

/path/to/model.tar.gz is the directory pointing to the trained model (i.e., trained by the script in scripts/train.sh).

Tried but getting error

Traceback (most recent call last):
File "/usr/local/bin/allennlp", line 33, in
sys.exit(load_entry_point('allennlp', 'console_scripts', 'allennlp')())
File "/content/sequential_sentence_classification/src/allennlp/allennlp/run.py", line 18, in run
main(prog="allennlp")
File "/content/sequential_sentence_classification/src/allennlp/allennlp/commands/init.py", line 102, in main
args.func(args)
File "/content/sequential_sentence_classification/src/allennlp/allennlp/commands/predict.py", line 227, in _predict
manager.run()
File "/content/sequential_sentence_classification/src/allennlp/allennlp/commands/predict.py", line 206, in run
for model_input_json, result in zip(batch_json, self._predict_json(batch_json)):
File "/content/sequential_sentence_classification/src/allennlp/allennlp/commands/predict.py", line 151, in _predict_json
results = [self._predictor.predict_json(batch_data[0])]
File "./sequential_sentence_classification/predictor.py", line 20, in predict_json
instance = self._dataset_reader.text_to_instance(abstract_id=0, sentences=sentences_loop)
TypeError: text_to_instance() got an unexpected keyword argument 'abstract_id'
2020-10-06 10:54:17,560 - INFO - allennlp.models.archival - removing temporary unarchived model dir at /tmp/tmpejdh216v

It also helped me to modify the predict_json method to suit my data (and remove the abstract_id=0 argument) and it also helped me to look at <install path>/allennlp/commands/predict.py to figure out how prediction loops are run on the data and command line arguments and such.