Nasty.Statistics.ModelDownloader (Nasty v0.3.0)
View SourceDownloads pre-trained statistical models from GitHub releases.
This module provides functionality to download models hosted on GitHub releases, verify their integrity using SHA256 checksums, and install them locally.
Usage
# Download a specific model
ModelDownloader.download("en-pos-v1", output_dir: "priv/models/en")
# Download with automatic prompt
ModelDownloader.download_if_missing(:en, :pos_tagging, "v1")Model Repository
Models are expected to be hosted at: https://github.com/USER/REPO/releases/download/models-VERSION/MODEL_ID
Each model should have:
- MODEL_ID.model - The model file
- MODEL_ID.meta.json - Metadata
- MODEL_ID.sha256 - SHA256 checksum
Future Implementation
This module is currently a stub for future GitHub integration. To implement:
- Add HTTP client dependency (e.g., req or httpoison)
- Implement actual download logic
- Add progress reporting
- Add retry logic and error handling
- Configure repository URLs
Summary
Functions
Downloads a model by ID from GitHub releases.
Downloads a model if it's not already available locally.
Lists all available models in the remote repository.
Verifies the SHA256 checksum of a downloaded model.
Types
Functions
Downloads a model by ID from GitHub releases.
Options
:output_dir- Directory to save the model (default: "priv/models"):repo- GitHub repository (default: from config):force- Force download even if file exists (default: false):verify_checksum- Verify SHA256 (default: true)
Returns
{:ok, path}- Successfully downloaded to path{:error, reason}- Download failed
Examples
iex> ModelDownloader.download("en-pos-v1")
{:error, :not_implemented}
@spec download_if_missing(atom(), atom(), String.t(), options()) :: {:ok, :already_exists | :downloaded} | {:error, term()}
Downloads a model if it's not already available locally.
Checks if the model exists in priv/models/ and downloads it if missing.
Examples
iex> ModelDownloader.download_if_missing(:en, :pos_tagging, "v1")
{:error, :not_implemented}
Lists all available models in the remote repository.
Fetches the list of downloadable models from GitHub releases.
Returns
{:ok, models}- List of available model IDs{:error, reason}- Failed to fetch list
Examples
iex> ModelDownloader.list_available()
{:error, :not_implemented}
Verifies the SHA256 checksum of a downloaded model.
Examples
iex> ModelDownloader.verify_checksum("path/to/model.model", "abc123...")
{:error, :not_implemented}