Skip to content

coref

allennlp_models.coref.predictors.coref

[SOURCE]


CorefPredictor#

@Predictor.register("coreference_resolution")
class CorefPredictor(Predictor):
 | def __init__(
 |     self,
 |     model: Model,
 |     dataset_reader: DatasetReader,
 |     language: str = "en_core_web_sm"
 | ) -> None

Predictor for the CoreferenceResolver model.

Registered as a Predictor with name "coreference_resolution".

predict#

class CorefPredictor(Predictor):
 | ...
 | def predict(self, document: str) -> JsonDict

Predict the coreference clusters in the given document.

{
"document": [tokenized document text]
"clusters":
  [
    [
      [start_index, end_index],
      [start_index, end_index]
    ],
    [
      [start_index, end_index],
      [start_index, end_index],
      [start_index, end_index],
    ],
    ....
  ]
}

Parameters

  • document : str
    A string representation of a document.

Returns

  • A dictionary representation of the predicted coreference clusters.

predict_tokenized#

class CorefPredictor(Predictor):
 | ...
 | def predict_tokenized(self, tokenized_document: List[str]) -> JsonDict

Predict the coreference clusters in the given document.

Parameters

  • tokenized_document : List[str]
    A list of words representation of a tokenized document.

Returns

  • A dictionary representation of the predicted coreference clusters.

predictions_to_labeled_instances#

class CorefPredictor(Predictor):
 | ...
 | @overrides
 | def predictions_to_labeled_instances(
 |     self,
 |     instance: Instance,
 |     outputs: Dict[str, numpy.ndarray]
 | ) -> List[Instance]

Takes each predicted cluster and makes it into a labeled Instance with only that cluster labeled, so we can compute gradients of the loss on the model's prediction of that cluster. This lets us run interpretation methods using those gradients. See superclass docstring for more info.

replace_corefs#

class CorefPredictor(Predictor):
 | ...
 | @staticmethod
 | def replace_corefs(
 |     document: Doc,
 |     clusters: List[List[List[int]]]
 | ) -> str

Uses a list of coreference clusters to convert a spacy document into a string, where each coreference is replaced by its main mention.

coref_resolved#

class CorefPredictor(Predictor):
 | ...
 | def coref_resolved(self, document: str) -> str

Produce a document where each coreference is replaced by its main mention

Parameters

  • document : str
    A string representation of a document.

Returns

  • A string with each coreference replaced by its main mention