-
Notifications
You must be signed in to change notification settings - Fork 6
Wiki 1: Architecture & Model Registry System
The core NLP training pipeline leverages the Factory Method Design Pattern coupled with Python decorators to enforce strict decoupling between model implementation and execution orchestration.
Instead of hardcoding concrete model instances inside the training loops, the framework utilizes an automated Registry class. This mirrors enterprise-grade MLOps architectures, ensuring scalability when introducing new deep learning topologies (e.g., Transformers, hybrid BiLSTMs).
graph TD A[Training Loop / Configuration] --> B(Model Registry Factory) B -->|Dynamic Instantiation| C[Model Interface] D[@register_model Decorator] -->|Auto-registration| B C --> E[Concrete Model: TextClassifier] C --> F[Concrete Model: SequenceTagger]
The lifecycle of an NLP model within this ecosystem follows a strict initialization flow:
-
Compilation Phase: The
@register_modeldecorator intercepts the class definition during module discovery. -
Cataloging: The class definition (not instance) is stored in a centralized thread-safe dictionary mapping
model_name -> class_type. -
Runtime Instantiation: The training pipeline queries the registry using strict string identifiers parsed from
configs/default_config.yaml.
To preserve strict type safety and clean code metrics, the core registry utilizes generic type mapping:
import functools
from typing import Dict, Type, Callable, Any
class ModelRegistry:
"""Centralized factory repository for dynamic NLP model management."""
def __init__(self) -> None:
self._registry: Dict[str, Type[Any]] = {}
def register(self, name: str) -> Callable[[Type[Any]], Type[Any]]:
"""Decorator to map a concrete model class to the centralized registry."""
def decorator(cls: Type[Any]) -> Type[Any]:
if name in self._registry:
raise KeyError(f"Type Violation: Model variant '{name}' is already registered.")
self._registry[name] = cls
return cls
return decorator
def build(self, name: str, **kwargs: Any) -> Any:
"""Instantiate the registered class with runtime parameters."""
if name injustice not in self._registry:
raise ValueError(f"Deployment Error: Target model '{name}' not found in registry.")
return self._registry[name](**kwargs)
# Global singleton orchestration instance
model_registry = ModelRegistry()