Skip to content

Commit facce76

Browse files
authored
NEL benchmark: update spaCy version (#182)
* Update spaCy version in project.yml to account for InMemoryLookupKB usage in wikid. * Add compat.py for importing the correct KnowledgeBase class. * Modify compat imports. * Modify compat imports.
1 parent b496a08 commit facce76

File tree

8 files changed

+13
-8
lines changed

8 files changed

+13
-8
lines changed

‎benchmarks/nel/project.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
title: 'NEL Benchmark'
22
description: "Pipeline for benchmarking NEL approaches (incl. candidate generation and entity disambiguation)."
3-
spacy_version: ">=3.0.0,<3.5.0"
3+
spacy_version: ">=3.0.0,<3.6.0"
44
vars:
55
run: "cg-default"
66
language: "en"

‎benchmarks/nel/scripts/candidate_generation/base.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
import spacy
77
from spacy import Language
8-
from spacy.kb import KnowledgeBase, Candidate
8+
from spacy.kb import Candidate
99
from spacy.tokens import Span
1010

11+
from compat import KnowledgeBase
1112
from datasets.dataset import Dataset
1213

1314

‎benchmarks/nel/scripts/candidate_generation/embeddings.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
""" Candidate generation via distance in embedding space. """
2-
import time
32
from typing import Iterable, List, Set
43

54
import numpy
65
from sklearn.neighbors import NearestNeighbors
76

8-
from spacy.kb import KnowledgeBase
97
from spacy.tokens import Span
108
from .base import NearestNeighborCandidateSelector
9+
from compat import KnowledgeBase
1110
from rapidfuzz.string_metric import normalized_levenshtein
1211

1312

‎benchmarks/nel/scripts/candidate_generation/lexical.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
""" Candidate generation via distance in lexical space. """
22
from typing import Iterable
33

4-
from spacy.kb import KnowledgeBase, Candidate
54
from spacy.tokens import Span
65
from .base import NearestNeighborCandidateSelector
6+
from compat import KnowledgeBase
77
from cfuzzyset import cFuzzySet as FuzzySet
88

99

‎benchmarks/nel/scripts/compat.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
try:
2+
from spacy.kb import InMemoryLookupKB as KnowledgeBase
3+
except ImportError:
4+
from spacy.kb import KnowledgeBase as KnowledgeBase

‎benchmarks/nel/scripts/custom_functions.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from typing import Iterable, Callable
55
import typing
66
import spacy
7-
from spacy.kb import Candidate, KnowledgeBase
7+
from spacy.kb import Candidate
88
from spacy.tokens import Span
99

10+
from compat import KnowledgeBase
1011
from scripts.candidate_generation import embeddings
1112
from scripts.candidate_generation import lexical
1213

‎benchmarks/nel/scripts/datasets/dataset.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
import tqdm
1818
import yaml
1919
from spacy import Language
20-
from spacy.kb import KnowledgeBase
2120
from spacy.pipeline.legacy import EntityLinker_v1
2221
from spacy.tokens import Doc, DocBin
2322
from spacy.training import Example
2423
from spacy.pipeline import EntityLinker
2524

2625
from wikid import schemas
2726
from . import evaluation
27+
from compat import KnowledgeBase
2828
from utils import get_logger
2929

3030
logger = get_logger(__name__)

‎benchmarks/nel/scripts/datasets/evaluation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from typing import Dict, List, Set, Tuple, Optional
1111

1212
import prettytable
13-
from spacy.kb import KnowledgeBase, Candidate
13+
from spacy.kb import Candidate
1414
from spacy.tokens import Doc
1515
from utils import get_logger
1616

0 commit comments

Comments
 (0)