mirror of
https://github.com/explosion/spaCy.git
synced 2025-06-30 01:43:21 +03:00
Fix test.
This commit is contained in:
parent
ba91d0d1d9
commit
ace5655fe1
|
@ -1217,39 +1217,35 @@ def test_nel_candidate_processing():
|
||||||
"""
|
"""
|
||||||
train_data = [
|
train_data = [
|
||||||
(
|
(
|
||||||
"The sky over New York is blue.",
|
"The sky is blue.",
|
||||||
{
|
{
|
||||||
"sent_starts": [1, 0, 0, 0, 0, 0, 0, 0],
|
"sent_starts": [1, 0, 0, 0, 0],
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"They visited New York.",
|
"They visited New York.",
|
||||||
{
|
{
|
||||||
"sent_starts": [1, 0, 0, 0, 0],
|
"sent_starts": [1, 0, 0, 0, 0],
|
||||||
|
"entities": [(13, 21, "GPE")],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
("", {}),
|
||||||
|
(
|
||||||
|
"New York is a city.",
|
||||||
|
{
|
||||||
|
"sent_starts": [1, 0, 0, 0, 0, 0],
|
||||||
|
"entities": [(0, 8, "GPE")],
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
# (
|
|
||||||
# "",
|
|
||||||
# {}
|
|
||||||
# ),
|
|
||||||
# (
|
|
||||||
# "New York is a city.",
|
|
||||||
# {
|
|
||||||
# "sent_starts": [1, 0, 0, 0, 0, 0],
|
|
||||||
# }
|
|
||||||
# ),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
nlp = English()
|
nlp = English()
|
||||||
# Add a custom rule-based component to mimick NER
|
nlp.add_pipe("sentencizer")
|
||||||
ruler = nlp.add_pipe("entity_ruler", last=True)
|
|
||||||
ruler.add_patterns([{"label": "GPE", "pattern": [{"LOWER": "new york"}]}]) # type: ignore
|
|
||||||
|
|
||||||
vector_length = 3
|
vector_length = 3
|
||||||
train_examples = []
|
train_examples = []
|
||||||
for text, annotation in train_data:
|
for text, annotation in train_data:
|
||||||
doc = nlp(text)
|
train_examples.append(Example.from_dict(nlp(text), annotation))
|
||||||
train_examples.append(Example.from_dict(doc, annotation))
|
|
||||||
|
|
||||||
def create_kb(vocab):
|
def create_kb(vocab):
|
||||||
# create artificial KB
|
# create artificial KB
|
||||||
|
@ -1266,8 +1262,9 @@ def test_nel_candidate_processing():
|
||||||
losses = {}
|
losses = {}
|
||||||
nlp.update(train_examples, sgd=optimizer, losses=losses)
|
nlp.update(train_examples, sgd=optimizer, losses=losses)
|
||||||
|
|
||||||
# adding additional components that are required for the entity_linker
|
# Add a custom rule-based component to mimick NER
|
||||||
nlp.add_pipe("sentencizer", first=True)
|
ruler = nlp.add_pipe("entity_ruler", before="entity_linker")
|
||||||
|
ruler.add_patterns([{"label": "GPE", "pattern": [{"LOWER": "new york"}]}]) # type: ignore
|
||||||
|
|
||||||
# this will run the pipeline on the examples and shouldn't crash
|
# this will run the pipeline on the examples and shouldn't crash
|
||||||
nlp.evaluate(train_examples)
|
nlp.evaluate(train_examples)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user