Skip to content

Commit

Permalink
skip relations when another relation with same arguments was already …
Browse files Browse the repository at this point in the history
…encoded
  • Loading branch information
ArneBinder committed Nov 13, 2024
1 parent cf287c4 commit f9fcd91
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/pie_modules/taskmodules/pointer_network_for_end2end_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,18 +454,28 @@ def encode_annotations(

# encode relations
all_relation_arguments = set()
relation_arguments2label: Dict[Tuple[Annotation, ...], str] = dict()
relation_encodings = dict()
for rel in layers[self.relation_layer_name]:
if not isinstance(rel, BinaryRelation):
raise Exception(f"expected BinaryRelation, but got: {rel}")
if rel.label in self.labels_per_layer[self.relation_layer_name]:
if (rel.head, rel.tail) in relation_arguments2label:
previous_label = relation_arguments2label[(rel.head, rel.tail)]
if previous_label != rel.label:
logger.warning(
f"relation {rel.head} -> {rel.tail} already exists, but has another label: "
f"{previous_label} (previous label: {rel.label}). Skipping."
)
continue
encoded_relation = self.relation_encoder_decoder.encode(
annotation=rel, metadata=metadata
)
if encoded_relation is None:
raise Exception(f"failed to encode relation: {rel}")
relation_encodings[rel] = encoded_relation
all_relation_arguments.update([rel.head, rel.tail])
relation_arguments2label[(rel.head, rel.tail)] = rel.label

# encode spans that are not arguments of any relation
no_relation_spans = [
Expand Down

0 comments on commit f9fcd91

Please sign in to comment.