Search code examples
pythonallennlp

AllenNLP Semantic Role Labeler - Argument Annotations


for the AllenNLP Semantic Role Labeling implementation, how do the Argument annotations get applied like what is shown in the demo? When I run the code from my local implementation I see the verbs and description, but not the annotations? I must be missing an additional step or logic that needs to be applied to support that part of the output.

What is showing up in the Demo App

Sentence: At noon, a man exited the park on the N side. 

exited: [ARGM-TMP: At noon] , [ARG0: a man] [V: exited] [ARG1: the park] [ARGM-DIR: on the N side] .

My Code:

from allennlp.predictors.predictor import Predictor

download = "https://storage.googleapis.com/allennlp-public-models/bert-base-srl-2020.09.03.tar.gz"
# predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/bert-base-srl-2020.11.19.tar.gz")
predictor = Predictor.from_path(download)

text = "At noon, a man exited the park on the N side. "

tree = predictor.predict(sentence=text)
value = predictor.dump_line(tree)
value

The output from my code for the same sentence:

'{"verbs": [{"verb": "exited", "description": "At noon , a man exited the park on the N side .", "tags": ["O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O"]}], "words": ["At", "noon", ",", "a", "man", "exited", "the", "park", "on", "the", "N", "side", "."]}

Solution

  • After posting on github, found out from the AllenNLP folks that it is a version issue. I needed to be using allennlp=1.3.0 and the latest model. Now it works as expected.

    This should be fixed in the latest allennlp 1.3 release. Also, the latest archive file is structured-prediction-srl-bert.2020.12.15.tar.gz.
    

    https://github.com/allenai/allennlp/issues/4876