-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path__init__.py
39 lines (33 loc) · 962 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
__version__ = "1.0.1"
from .model import GLiREL
from typing import Optional, Union, List
import torch
__all__ = ["GLiREL"]
# https://github.com/tomaarsen/SpanMarkerNER/blob/main/span_marker/__init__.py
# Set up for spaCy
try:
from spacy.language import Language
except ImportError:
pass
else:
DEFAULT_SPACY_CONFIG = {
"model": "jackboyla/glirel-large-v0",
"batch_size": 1,
"device": None,
"threshold": 0.3,
}
@Language.factory(
"glirel",
assigns=["doc._.relations"],
default_config=DEFAULT_SPACY_CONFIG,
)
def _spacy_glirel_factory(
nlp: Language,
name: str,
model: str,
batch_size: int,
device: Optional[Union[str, torch.device]],
threshold: float,
) -> "SpacyGLiRELWrapper":
from glirel.spacy_integration import SpacyGLiRELWrapper
return SpacyGLiRELWrapper(model, batch_size=batch_size, device=device)