Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
80 lines (70 loc) · 2.27 KB
/
Copy path__init__.py
File metadata and controls
80 lines (70 loc) · 2.27 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""GLiNER2 training and torch-free training-data utilities.
Trainer symbols are loaded on first access. This keeps ``import gliner2`` and
``import gliner2.training`` usable without torch, transformers, or PEFT.
"""
from __future__ import annotations
import importlib
from gliner2.training.data import (
ChoiceField,
Classification,
DataFormat,
DataLoader_Factory,
DataValidationError,
InputExample,
Relation,
Structure,
TrainDataInput,
TrainingDataset,
create_classification_example,
create_entity_example,
create_relation_example,
create_structure_example,
)
_LAZY = {
"ManagedTrainingPlan": ("gliner2.training.managed", "ManagedTrainingPlan"),
"ManagedTraining": ("gliner2.training.managed", "ManagedTraining"),
"TrainingSession": ("gliner2.training.session", "TrainingSession"),
"ExtractorTrainer": ("gliner2.training.trainer", "ExtractorTrainer"),
"GLiNER2Trainer": ("gliner2.training.trainer", "GLiNER2Trainer"),
"TrainingConfig": ("gliner2.training.config", "TrainingConfig"),
"TrainingMetrics": ("gliner2.training.trainer", "TrainingMetrics"),
"ExtractorDataset": ("gliner2.training.trainer", "ExtractorDataset"),
"ExtractorCollator": ("gliner2.training.trainer", "ExtractorCollator"),
"train_gliner2": ("gliner2.training.trainer", "train_gliner2"),
}
__all__ = [
"ManagedTrainingPlan",
"ManagedTraining",
"TrainingSession",
"ChoiceField",
"Classification",
"DataFormat",
"DataLoader_Factory",
"DataValidationError",
"InputExample",
"Relation",
"Structure",
"TrainDataInput",
"TrainingDataset",
"ExtractorTrainer",
"GLiNER2Trainer",
"TrainingConfig",
"TrainingMetrics",
"ExtractorDataset",
"ExtractorCollator",
"create_classification_example",
"create_entity_example",
"create_relation_example",
"create_structure_example",
"train_gliner2",
]
def __getattr__(name: str):
try:
module_name, attribute = _LAZY[name]
except KeyError:
raise AttributeError(f"module 'gliner2.training' has no attribute {name!r}") from None
value = getattr(importlib.import_module(module_name), attribute)
globals()[name] = value
return value
def __dir__():
return sorted(set(globals()) | set(_LAZY))