Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prediction with only one input sentence fails #6

Open
TonalidadeHidrica opened this issue Jul 22, 2019 · 1 comment
Open

Prediction with only one input sentence fails #6

TonalidadeHidrica opened this issue Jul 22, 2019 · 1 comment

Comments

@TonalidadeHidrica
Copy link

At the prediction step, if the input file contains only one sentence, it results in an error. For example, after all the preprocess was applied to the AMR 2.0 (LDC2017T10) data (following the steps in README.md), there will be a preprocessed test data file test.preproc in data/AMR/amr_2.0/ directory. However, if I removed all the "paragraphs" (that is, a pair of "comments" (including id, snt, and tags etc.) and AMR graph) except for the first paragraph from the file, and then apply the "6. Prediction" phase, the program shows the following error:

Traceback (most recent call last):
  File ".../anaconda/envs/stog/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File ".../anaconda/envs/stog/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File ".../stog/stog/commands/predict.py", line 252, in <module>
    _predict(args)
  File ".../stog/stog/commands/predict.py", line 208, in _predict
    manager.run()
  File ".../stog/stog/commands/predict.py", line 182, in run
    for model_input_instance, result in zip(batch, self._predict_instances(batch)):
  File ".../stog/stog/commands/predict.py", line 143, in _predict_instances
    results = [self._predictor.predict_instance(batch_data[0])]
  File ".../stog/stog/predictors/predictor.py", line 46, in predict_instance
    outputs = self._model.forward_on_instance(instance)
  File ".../stog/stog/models/model.py", line 117, in forward_on_instance
    raise NotImplementedError
NotImplementedError

This error occurs whenever input file with only one AMR paragraph was given to --input-file option of stog.commands.predict module. Also, if the input file contains more than two paragraphs, this error doesn't seem to be happening.

@bjascob
Copy link

bjascob commented Mar 27, 2020

For some reason, thre's an if statment in stog/commands/predict.py::_predict_instances() (about line 141) that sends the code on a different path if your batch_data size is 1 (ie.. only one sentence). The stog model doesn't have that code implemented. I'm not sure if there is still a valid reason for this but it appear to work if you comment-out the if/else.

Here's the revised function....

def _predict_instances(self, batch_data: List[Instance]) -> Iterator[str]:
    # removed - doesn't work for single instance of batch data.
    #if len(batch_data) == 1:
    #    results = [self._predictor.predict_instance(batch_data[0])]
    #else:
    results = self._predictor.predict_batch_instance(batch_data)
    for output in results:
        yield self._predictor.dump_line(output)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants