Skip to main content

A packaged version of the sentence-transformers/all-MiniLM-L6-v2 model for complete offline PyTorch use.

Project description

gt-all-minilm-l6-v2

A complete, offline-first Python packaging of the Hugging Face sentence-transformers/all-MiniLM-L6-v2 model.

This package bundles the model's metadata, tokenizers, and weights (in standard model.safetensors format, ~90MB) directly inside the Python distribution. It is specifically designed for secure, air-gapped, or network-constrained offline environments where packages can only be installed via pip install, and downloading assets from the Hugging Face Hub at runtime is impossible.


Key Features

  • Offline-First: No network requests are made at runtime. The model weights (model.safetensors) and configs are packaged directly into the library's wheel.
  • Official Integration: Directly integrates with the sentence-transformers library for robust, standard loading.
  • Convenient Export: Exposes a simple API and CLI to easily export the raw model and tokenizer files to any external directory.
  • Minimal CLI: Zero-fuss CLI command gt-all-minilm-l6-v2 to get the internal model directory or export components.

Installation

Installation in Online Environment (Building from Source)

Clone the repository and install dependencies, then build and install the package:

# 1. Clone the repository
git clone https://github.com/your-org/gt-all-minilm-l6-v2.git
cd gt-all-minilm-l6-v2

# 2. Download the model weights and assets locally
python scripts/download_model.py

# 3. Build the wheel
pip install build
python -m build

# 4. Install the package
pip install dist/gt_all_minilm_l6_v2-0.1.0-py3-none-any.whl

Installation in Offline Environment

Once the .whl file is built in an internet-enabled environment, copy the .whl file to your offline/air-gapped environment and install it using standard pip:

pip install gt_all_minilm_l6_v2-0.1.0-py3-none-any.whl

Python API Usage

The package exposes three main functions under the gt_all_minilm_l6_v2 namespace.

1. Loading the Model

Load the model as a standard SentenceTransformer instance:

import gt_all_minilm_l6_v2

# Load the packaged model (automatically uses GPU if available)
model = gt_all_minilm_l6_v2.load_model()

# Generate sentence embeddings offline
sentences = ["This is an offline sentence embedding", "Another text to embed"]
embeddings = model.encode(sentences)

print("Embedding dimensions:", embeddings.shape)  # Output: (2, 384)

2. Locating the Bundled Model Files

Get the absolute path to the local directory where the model files are located inside your Python installation (site-packages):

import gt_all_minilm_l6_v2

model_path = gt_all_minilm_l6_v2.get_model_path()
print("Model directory:", model_path)

3. Exporting Model Components

Export the raw model, tokenizer, and config files to an external directory. This is extremely useful if you need to load the model from disk in other frameworks (like Hugging Face transformers or C++ deployments) without referencing the Python package.

import gt_all_minilm_l6_v2

# Export all components to a local folder
export_path = gt_all_minilm_l6_v2.export_model("./my-local-model-directory")
print("Model exported to:", export_path)

Command-Line Interface (CLI)

The package exposes a command-line utility gt-all-minilm-l6-v2 with two subcommands.

path

Print the absolute path to the bundled model files within the Python environment:

gt-all-minilm-l6-v2 path

Example Output: /home/user/venv/lib/python3.10/site-packages/gt_all_minilm_l6_v2/model

export

Export the bundled model components to a specified external folder:

gt-all-minilm-l6-v2 export ./my_offline_model

Guaranteeing Offline Success

To verify that the model is running entirely from local files and does not attempt to contact Hugging Face Hub, set the standard environment variables to disable network calls:

import os
os.environ["HF_HUB_OFFLINE"] = "1"
os.environ["TRANSFORMERS_OFFLINE"] = "1"

import gt_all_minilm_l6_v2
model = gt_all_minilm_l6_v2.load_model()

License

This project is licensed under the MIT License - see the LICENSE file for details. The model weights are distributed under their respective Apache 2.0 license by the Sentence Transformers team.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gt_all_minilm_l6_v2-0.1.0.tar.gz (83.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gt_all_minilm_l6_v2-0.1.0-py3-none-any.whl (83.5 MB view details)

Uploaded Python 3

File details

Details for the file gt_all_minilm_l6_v2-0.1.0.tar.gz.

File metadata

  • Download URL: gt_all_minilm_l6_v2-0.1.0.tar.gz
  • Upload date:
  • Size: 83.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for gt_all_minilm_l6_v2-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8c7e7a84a8df4356b353eb6606c0ef602e776c41ef7f53dd6cc24e30402139b9
MD5 89830d39b8f296ef8afe6702270c4ed9
BLAKE2b-256 6cf46783c08846566a7cc161427eb62c3fd8187705aa3cccd484a9e12b10966a

See more details on using hashes here.

File details

Details for the file gt_all_minilm_l6_v2-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gt_all_minilm_l6_v2-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9a0018dff090c14865aa0996a89997e34aeadf10e400e766cb961230c58fa54
MD5 2276692614428b0175283d75817eef3c
BLAKE2b-256 1312337765c63a9ad86e329668e156142e9755f5830eb26fd3ab540a7deab0bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page