forked from explosion/thinc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
29 lines (24 loc) · 1.25 KB
/
config.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
import catalogue
import confection
from confection import Config, ConfigValidationError, Promise, VARIABLE_RE
from .types import Decorator
class registry(confection.registry):
# fmt: off
optimizers: Decorator = catalogue.create("thinc", "optimizers", entry_points=True)
schedules: Decorator = catalogue.create("thinc", "schedules", entry_points=True)
layers: Decorator = catalogue.create("thinc", "layers", entry_points=True)
losses: Decorator = catalogue.create("thinc", "losses", entry_points=True)
initializers: Decorator = catalogue.create("thinc", "initializers", entry_points=True)
datasets: Decorator = catalogue.create("thinc", "datasets", entry_points=True)
ops: Decorator = catalogue.create("thinc", "ops", entry_points=True)
# fmt: on
@classmethod
def create(cls, registry_name: str, entry_points: bool = False) -> None:
"""Create a new custom registry."""
if hasattr(cls, registry_name):
raise ValueError(f"Registry '{registry_name}' already exists")
reg: Decorator = catalogue.create(
"thinc", registry_name, entry_points=entry_points
)
setattr(cls, registry_name, reg)
__all__ = ["Config", "registry", "ConfigValidationError", "Promise", "VARIABLE_RE"]