Skip to content

Commit

Permalink
Merge branch 'develop' into feat/add_label
Browse files Browse the repository at this point in the history
  • Loading branch information
svlandeg committed Sep 5, 2023
2 parents a080510 + 99adb49 commit 7d03f3e
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 137 deletions.
4 changes: 2 additions & 2 deletions spacy_llm/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from .textcat import TextCatTask, make_textcat_task

_LATEST_TASKS = (
"spacy.NER.v2",
"spacy.NER.v3",
"spacy.REL.v1",
"spacy.Sentiment.v1",
"spacy.SpanCat.v2",
"spacy.SpanCat.v3",
"spacy.Summarization.v1",
"spacy.TextCat.v3",
)
Expand Down
5 changes: 1 addition & 4 deletions spacy_llm/tasks/spancat/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from ...util import split_labels
from ..span import parse_responses as parse_span_responses
from ..span import parse_responses_cot as parse_span_responses_cot
from ..span.task import SpanTaskLabelCheck
from ..span.util import check_label_consistency as check_labels
from ..span.util import check_label_consistency_cot as check_labels_cot
from .task import DEFAULT_SPANCAT_TEMPLATE_V1, DEFAULT_SPANCAT_TEMPLATE_V2
Expand Down Expand Up @@ -145,7 +144,6 @@ def make_spancat_task_v3(
case_sensitive_matching: bool = False,
spans_key: str = "sc",
scorer: Optional[Scorer] = None,
check_label_consistency: Optional[SpanTaskLabelCheck[SpanCatTask]] = None,
):
"""SpanCat.v3 task factory for SpanCat with chain-of-thought prompting.
Expand All @@ -168,7 +166,6 @@ def make_spancat_task_v3(
case_sensitive_matching (bool): Whether to search without case sensitivity.
spans_key (str): Key of the `Doc.spans` dict to save under.
scorer (Optional[Scorer]): Scorer function.
check_label_consistency (SpanTaskLabelCheck): Callable to check label consistency.
"""
labels_list = split_labels(labels)
raw_examples = examples() if callable(examples) else examples
Expand All @@ -191,5 +188,5 @@ def make_spancat_task_v3(
spans_key=spans_key,
scorer=scorer or score,
description=description,
check_label_consistency=check_label_consistency or check_labels_cot,
check_label_consistency=check_labels_cot,
)
6 changes: 0 additions & 6 deletions spacy_llm/tests/tasks/examples/ner.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
"is_entity": true,
"label": "LOC",
"reason": "is a location"
},
{
"text": "hill",
"is_entity": true,
"label": "DESTINATION",
"reason": "is a destination"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion spacy_llm/tests/tasks/examples/ner.jsonl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"text":"Jack and Jill went up the hill.","spans":[{"text":"Jack","is_entity":true,"label":"PER","reason":"is the name of a person"},{"text":"Jill","is_entity":true,"label":"PER","reason":"is the name of a person"},{"text":"went up","is_entity":false,"label":"==NONE==","reason":"is a verb"},{"text":"hill","is_entity":true,"label":"LOC","reason":"is a location"},{"text":"hill","is_entity":true,"label":"DESTINATION","reason":"is a destination"}]}
{"text":"Jack and Jill went up the hill.","spans":[{"text":"Jack","is_entity":true,"label":"PER","reason":"is the name of a person"},{"text":"Jill","is_entity":true,"label":"PER","reason":"is the name of a person"},{"text":"went up","is_entity":false,"label":"==NONE==","reason":"is a verb"},{"text":"hill","is_entity":true,"label":"LOC","reason":"is a location"}]}
4 changes: 0 additions & 4 deletions spacy_llm/tests/tasks/examples/ner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,3 @@
is_entity: true
label: LOC
reason: is a location
- text: hill
is_entity: true
label: DESTINATION
reason: is a destination
16 changes: 8 additions & 8 deletions spacy_llm/tests/tasks/legacy/test_ner.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def test_ner_zero_shot_task(text, response, gold_ents):
labels = "PER,ORG,LOC"
llm_ner = make_ner_task_v2(labels=labels)
# Prepare doc
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc_in = nlp.make_doc(text)
# Pass to the parser
# Note: parser() returns a list so we get what's inside
Expand Down Expand Up @@ -384,7 +384,7 @@ def test_ner_labels(response, normalizer, gold_ents):
labels = "PER,ORG,LOC"
llm_ner = make_ner_task_v2(labels=labels, normalizer=normalizer)
# Prepare doc
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc_in = nlp.make_doc(text)
# Pass to the parser
# Note: parser() returns a list
Expand Down Expand Up @@ -433,7 +433,7 @@ def test_ner_alignment(response, alignment_mode, gold_ents):
labels = "PER,ORG,LOC"
llm_ner = make_ner_task_v2(labels=labels, alignment_mode=alignment_mode) # type: ignore
# Prepare doc
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc_in = nlp.make_doc(text)
# Pass to the parser
# Note: parser() returns a list
Expand Down Expand Up @@ -484,7 +484,7 @@ def test_ner_matching(response, case_sensitive, single_match, gold_ents):
labels=labels, case_sensitive_matching=case_sensitive, single_match=single_match
)
# Prepare doc
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc_in = nlp.make_doc(text)
# Pass to the parser
# Note: parser() returns a list
Expand All @@ -500,7 +500,7 @@ def test_jinja_template_rendering_without_examples():
with annoying newlines and spaces at the edge of the text.
"""
labels = "PER,ORG,LOC"
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc = nlp.make_doc("Alice and Bob went to the supermarket")

llm_ner = make_ner_task_v2(labels=labels, examples=None)
Expand Down Expand Up @@ -542,7 +542,7 @@ def test_jinja_template_rendering_with_examples(examples_path):
with annoying newlines and spaces at the edge of the text.
"""
labels = "PER,ORG,LOC"
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc = nlp.make_doc("Alice and Bob went to the supermarket")

examples = fewshot_reader(examples_path)
Expand Down Expand Up @@ -601,7 +601,7 @@ def test_jinja_template_rendering_with_label_definitions():
with annoying newlines and spaces at the edge of the text.
"""
labels = "PER,ORG,LOC"
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc = nlp.make_doc("Alice and Bob went to the supermarket")
llm_ner = make_ner_task_v2(
labels=labels,
Expand Down Expand Up @@ -660,7 +660,7 @@ def test_external_template_actually_loads():
template_path = str(TEMPLATES_DIR / "ner.jinja2")
template = file_reader(template_path)
labels = "PER,ORG,LOC"
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc = nlp.make_doc("Alice and Bob went to the supermarket")

llm_ner = make_ner_task_v2(labels=labels, template=template)
Expand Down
12 changes: 6 additions & 6 deletions spacy_llm/tests/tasks/legacy/test_spancat.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def test_spancat_zero_shot_task(text, response, gold_spans):
labels = "PER,ORG,LOC"
llm_spancat = make_spancat_task_v2(labels=labels)
# Prepare doc
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc_in = nlp.make_doc(text)
# Pass to the parser
# Note: parser() returns a list so we get what's inside
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_spancat_labels(response, normalizer, gold_spans):
labels = "PER,ORG,LOC"
llm_spancat = make_spancat_task_v2(labels=labels, normalizer=normalizer)
# Prepare doc
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc_in = nlp.make_doc(text)
# Pass to the parser
# Note: parser() returns a list
Expand Down Expand Up @@ -305,7 +305,7 @@ def test_spancat_alignment(response, alignment_mode, gold_spans):
labels = "PER,ORG,LOC"
llm_spancat = make_spancat_task_v2(labels=labels, alignment_mode=alignment_mode) # type: ignore
# Prepare doc
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc_in = nlp.make_doc(text)
# Pass to the parser
# Note: parser() returns a list
Expand Down Expand Up @@ -356,7 +356,7 @@ def test_spancat_matching(response, case_sensitive, single_match, gold_spans):
labels=labels, case_sensitive_matching=case_sensitive, single_match=single_match
)
# Prepare doc
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc_in = nlp.make_doc(text)
# Pass to the parser
# Note: parser() returns a list
Expand All @@ -372,7 +372,7 @@ def test_jinja_template_rendering_without_examples():
with annoying newlines and spaces at the edge of the text.
"""
labels = "PER,ORG,LOC"
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc = nlp.make_doc("Alice and Bob went to the supermarket")

llm_spancat = make_spancat_task_v2(labels=labels, examples=None)
Expand Down Expand Up @@ -415,7 +415,7 @@ def test_jinja_template_rendering_with_examples(examples_path):
with annoying newlines and spaces at the edge of the text.
"""
labels = "PER,ORG,LOC"
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc = nlp.make_doc("Alice and Bob went to the supermarket")

examples = fewshot_reader(examples_path)
Expand Down
6 changes: 3 additions & 3 deletions spacy_llm/tests/tasks/test_lemma.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def test_jinja_template_rendering_without_examples():
We apply the .strip() method for each prompt so that we don't have to deal
with annoying newlines and spaces at the edge of the text.
"""
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
text = "Alice and Bob went to the supermarket"
doc = nlp.make_doc(text)

Expand Down Expand Up @@ -240,7 +240,7 @@ def test_jinja_template_rendering_with_examples(examples_path):
We apply the .strip() method for each prompt so that we don't have to deal
with annoying newlines and spaces at the edge of the text.
"""
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
text = "Alice and Bob went to the supermarket."
doc = nlp.make_doc(text)

Expand Down Expand Up @@ -333,7 +333,7 @@ def test_external_template_actually_loads():
template_path = str(TEMPLATES_DIR / "lemma.jinja2")
template = file_reader(template_path)
text = "Alice and Bob went to the supermarket"
nlp = spacy.blank("xx")
nlp = spacy.blank("en")
doc = nlp.make_doc(text)

lemma_task = make_lemma_task(template=template)
Expand Down
Loading

0 comments on commit 7d03f3e

Please sign in to comment.