Nasty.Statistics.ModelLoader (Nasty v0.3.0)
View SourceLoads statistical models from the filesystem and registers them.
ModelLoader discovers models in the priv/models/ directory and loads them
on demand. Models are organized by language and task:
priv/models/
en/
pos_hmm_v1.model
pos_hmm_v1.meta.json
pos_hmm_v2.model
pos_hmm_v2.meta.jsonModel files use the naming convention: {task}_{model_type}_{version}.model
Metadata files use: {task}_{model_type}_{version}.meta.json
Usage
# Load a specific model
{:ok, model} = ModelLoader.load_model(:en, :pos_tagging, "v1")
# Load latest version
{:ok, model} = ModelLoader.load_latest(:en, :pos_tagging)
# Discover all available models
models = ModelLoader.discover_models()
Summary
Functions
Discovers all available models in the models directory.
Gets the path to a model file.
Loads the latest version of a model for the given language and task.
Loads a model from the filesystem and registers it in the ModelRegistry.
Functions
Discovers all available models in the models directory.
Returns a list of tuples: {language, task, version, model_path, metadata_path}.
Examples
iex> ModelLoader.discover_models()
[
{:en, :pos_tagging, "v1", "priv/models/en/pos_hmm_v1.model", "priv/models/en/pos_hmm_v1.meta.json"}
]
Gets the path to a model file.
Returns {:ok, path} if the model file exists, {:error, :not_found} otherwise.
Examples
iex> ModelLoader.get_model_path(:en, :pos_tagging, "v1")
{:ok, "/path/to/priv/models/en/pos_hmm_v1.model"}
Loads the latest version of a model for the given language and task.
Returns {:ok, model} if successful, {:error, reason} otherwise.
Examples
iex> ModelLoader.load_latest(:en, :pos_tagging)
{:ok, %Nasty.Statistics.POSTagging.HMMTagger{...}}
Loads a model from the filesystem and registers it in the ModelRegistry.
Returns {:ok, model} if successful, {:error, reason} otherwise.
Examples
iex> ModelLoader.load_model(:en, :pos_tagging, "v1")
{:ok, %Nasty.Statistics.POSTagging.HMMTagger{...}}
iex> ModelLoader.load_model(:en, :nonexistent, "v1")
{:error, :not_found}