Nasty.Statistics.ModelRegistry (Nasty v0.3.0)
View SourceA registry for managing and caching statistical models.
The ModelRegistry is a GenServer that maintains an ETS table for efficient model lookup and caching. Models are stored with their metadata and can be retrieved by language, task type, and version.
Usage
# Register a model
ModelRegistry.register(:en, :pos_tagging, "v1", model, metadata)
# Lookup a model
{:ok, model, metadata} = ModelRegistry.lookup(:en, :pos_tagging, "v1")
# List all registered models
models = ModelRegistry.list()
# Clear all models
ModelRegistry.clear()Model Metadata
Metadata is a map that can include:
:version- Model version string:model_type- Type of model (e.g., "hmm_pos_tagger"):trained_on- Corpus used for training:training_date- Date of training:training_size- Number of training samples:test_accuracy- Accuracy on test set:test_f1- F1 score on test set:vocab_size- Vocabulary size:num_tags- Number of tags:file_size_bytes- Model file size:sha256- SHA256 checksum:hyperparameters- Map of hyperparameters
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears all models from the registry.
Lists all registered models.
Lists models for a specific language and task.
Looks up a model by language, task, and version.
Registers a model with its metadata.
Starts the ModelRegistry GenServer.
Removes a specific model from the registry.
Types
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clear() :: :ok
Clears all models from the registry.
Examples
iex> ModelRegistry.clear()
:ok
Lists all registered models.
Returns a list of tuples: {language, task, version, metadata}.
The actual model data is not included in the list to keep it lightweight.
Examples
iex> ModelRegistry.list()
[
{:en, :pos_tagging, "v1", %{test_accuracy: 0.947}},
{:en, :pos_tagging, "v2", %{test_accuracy: 0.952}}
]
Lists models for a specific language and task.
Returns a list of tuples: {version, metadata}.
Examples
iex> ModelRegistry.list_versions(:en, :pos_tagging)
[
{"v1", %{test_accuracy: 0.947}},
{"v2", %{test_accuracy: 0.952}}
]
Looks up a model by language, task, and version.
Returns {:ok, model, metadata} if found, {:error, :not_found} otherwise.
Examples
iex> ModelRegistry.lookup(:en, :pos_tagging, "v1")
{:ok, model, %{test_accuracy: 0.947}}
iex> ModelRegistry.lookup(:en, :ner, "v1")
{:error, :not_found}
Registers a model with its metadata.
Parameters
language- Language code (e.g.,:en,:es)task- Task type (e.g.,:pos_tagging,:ner)version- Model version string (e.g., "v1", "v2")model- The model struct or datametadata- Map of metadata about the model
Examples
iex> ModelRegistry.register(:en, :pos_tagging, "v1", model, %{
...> test_accuracy: 0.947,
...> trained_on: "UD_English-EWT v2.13"
...> })
:ok
Starts the ModelRegistry GenServer.
Removes a specific model from the registry.
Examples
iex> ModelRegistry.unregister(:en, :pos_tagging, "v1")
:ok