LsrPostprocessor

class LsrPostprocessor(rel2id: dict, rel_info: dict, pred_threshold: float = 0.3)[source]

This class processes LsrModelOutput to a readable format.

Parameters
  • rel2id (dict) – Relation to id mapping.

  • rel_info (dict) – Relation to description mapping.

  • pred_threshold (float, optional, defaults to 0.3) – Threshold for relation prediction to be returned.

__call__(prediction, data)[source]
Parameters
  • prediction (torch.FloatTensor) – Prediction of LsrModelOutput.

  • data – DocRED-like data that was used as input in preprocessing step.

Returns

List of dictionary that includes the document, the entity clusters found in the document, and the predicted relations between the entity clusters.

static from_file_paths(rel2id_path: str, rel_info_path: str, pred_threshold: float = 0.3)[source]

Constructs LsrPostprocessor from relevant DocRED files.

Parameters
  • rel2id_path (str) – Path to relation to id mapping file.

  • rel_info_path (str) – Path to relation info file. This is a mapping from relation to relation description.

  • pred_threshold (float, optional, defaults to 0.3) – Threshold for relation prediction to be returned.

Returns

postprocessor (LsrPostprocessor)