Skip to content

Commit

Permalink
add_negative_coref_relations does not return docs without relations
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneBinder committed Sep 15, 2024
1 parent b8d9939 commit 1d73f8a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
7 changes: 3 additions & 4 deletions src/pie_modules/document/processing/text_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,9 @@ def add_negative_coref_relations(
for rel in positive_rels:
new_rels2new_docs[rel].binary_coref_relations.append(rel)

# TODO: implement down sampling
# TODO: implement downsampling
for rel in negative_rels:
new_rels2new_docs[rel].binary_coref_relations.append(rel)

# docs_with_rels = [doc for doc in new_docs if len(doc.binary_coref_relations) > 0]
# return docs_with_rels
return new_docs
docs_with_rels = [doc for doc in new_docs if len(doc.binary_coref_relations) > 0]
return docs_with_rels
20 changes: 3 additions & 17 deletions tests/document/processing/test_text_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def positive_and_negative_documents(positive_documents):


def test_construct_negative_documents(positive_and_negative_documents):
assert len(positive_and_negative_documents) == 16
assert len(positive_and_negative_documents) == 8
TEXTS = [
"Entity A works at B.",
"And she founded C.",
Expand All @@ -229,7 +229,6 @@ def test_construct_negative_documents(positive_and_negative_documents):
]

assert all_rels_and_scores == [
(("And she founded C.", "And she founded C."), []),
(
("And she founded C.", "Bob loves his cat."),
[(0.0, ("coref", (("PERSON", "she"), ("PERSON", "Bob"))))],
Expand All @@ -241,12 +240,10 @@ def test_construct_negative_documents(positive_and_negative_documents):
(0.0, ("coref", (("COMPANY", "C"), ("COMPANY", "B")))),
],
),
(("And she founded C.", "She sleeps a lot."), []),
(
("Bob loves his cat.", "And she founded C."),
[(0.0, ("coref", (("PERSON", "Bob"), ("PERSON", "she"))))],
),
(("Bob loves his cat.", "Bob loves his cat."), []),
(
("Bob loves his cat.", "Entity A works at B."),
[(0.0, ("coref", (("PERSON", "Bob"), ("PERSON", "Entity A"))))],
Expand All @@ -266,15 +263,10 @@ def test_construct_negative_documents(positive_and_negative_documents):
("Entity A works at B.", "Bob loves his cat."),
[(0.0, ("coref", (("PERSON", "Entity A"), ("PERSON", "Bob"))))],
),
(("Entity A works at B.", "Entity A works at B."), []),
(("Entity A works at B.", "She sleeps a lot."), []),
(("She sleeps a lot.", "And she founded C."), []),
(
("She sleeps a lot.", "Bob loves his cat."),
[(1.0, ("coref", (("ANIMAL", "She"), ("ANIMAL", "his cat"))))],
),
(("She sleeps a lot.", "Entity A works at B."), []),
(("She sleeps a lot.", "She sleeps a lot."), []),
]


Expand All @@ -289,14 +281,8 @@ def test_construct_text_document_from_text_pair_coref_document(positive_and_nega
)
for doc in positive_and_negative_documents
]
assert len(docs) == 16
assert len(docs) == 8
doc = docs[0]
assert doc.text == "And she founded C."
assert doc.labeled_spans.resolve() == [("PERSON", "she"), ("COMPANY", "C")]
assert doc.binary_relations.resolve() == []
assert [rel.score for rel in doc.binary_relations] == []

doc = docs[1]
assert doc.text == "And she founded C.<s><s>Bob loves his cat."
assert doc.labeled_spans.resolve() == [
("PERSON", "she"),
Expand All @@ -309,7 +295,7 @@ def test_construct_text_document_from_text_pair_coref_document(positive_and_nega
]
assert [rel.score for rel in doc.binary_relations] == [1.0]

doc = docs[7]
doc = docs[4]
assert doc.text == "Bob loves his cat.<s><s>She sleeps a lot."
assert doc.labeled_spans.resolve() == [
("PERSON", "Bob"),
Expand Down

0 comments on commit 1d73f8a

Please sign in to comment.