allennlp.models.srl_util

allennlp.models.srl_util.convert_bio_tags_to_conll_format(labels: List[str])[source]

Converts BIO formatted SRL tags to the format required for evaluation with the official CONLL 2005 perl script. Spans are represented by bracketed labels, with the labels of words inside spans being the same as those outside spans. Beginning spans always have a opening bracket and a closing asterisk (e.g. “(ARG-1*” ) and closing spans always have a closing bracket (e.g. “)” ). This applies even for length 1 spans, (e.g “(ARG-0)”).

A full example of the conversion performed:

[B-ARG-1, I-ARG-1, I-ARG-1, I-ARG-1, I-ARG-1, O] [ “(ARG-1*”, “*”, “*”, “*”, “)”, “”]

Parameters
labelsList[str], required.

A list of BIO tags to convert to the CONLL span based format.

Returns
A list of labels in the CONLL span based format.
allennlp.models.srl_util.write_bio_formatted_tags_to_file(prediction_file: <class 'TextIO'>, gold_file: <class 'TextIO'>, verb_index: Union[int, NoneType], sentence: List[str], prediction: List[str], gold_labels: List[str])[source]

Prints predicate argument predictions and gold labels for a single verbal predicate in a sentence to two provided file references.

The CoNLL SRL format is described in the shared task data README .

This function expects IOB2-formatted tags, where the B- tag is used in the beginning of every chunk (i.e. all chunks start with the B- tag).

Parameters
prediction_fileTextIO, required.

A file reference to print predictions to.

gold_fileTextIO, required.

A file reference to print gold labels to.

verb_indexOptional[int], required.

The index of the verbal predicate in the sentence which the gold labels are the arguments for, or None if the sentence contains no verbal predicate.

sentenceList[str], required.

The word tokens.

predictionList[str], required.

The predicted BIO labels.

gold_labelsList[str], required.

The gold BIO labels.

allennlp.models.srl_util.write_conll_formatted_tags_to_file(prediction_file: <class 'TextIO'>, gold_file: <class 'TextIO'>, verb_index: Union[int, NoneType], sentence: List[str], conll_formatted_predictions: List[str], conll_formatted_gold_labels: List[str])[source]

Prints predicate argument predictions and gold labels for a single verbal predicate in a sentence to two provided file references.

The CoNLL SRL format is described in the shared task data README .

This function expects IOB2-formatted tags, where the B- tag is used in the beginning of every chunk (i.e. all chunks start with the B- tag).

Parameters
prediction_fileTextIO, required.

A file reference to print predictions to.

gold_fileTextIO, required.

A file reference to print gold labels to.

verb_indexOptional[int], required.

The index of the verbal predicate in the sentence which the gold labels are the arguments for, or None if the sentence contains no verbal predicate.

sentenceList[str], required.

The word tokens.

conll_formatted_predictionsList[str], required.

The predicted CoNLL-formatted labels.

conll_formatted_gold_labelsList[str], required.

The gold CoNLL-formatted labels.