model2vec 0.3.5__tar.gz → 0.3.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {model2vec-0.3.5 → model2vec-0.3.6}/PKG-INFO +1 -1
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec/hf_utils.py +23 -26
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec/model.py +22 -1
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec/version.py +1 -1
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec.egg-info/PKG-INFO +1 -1
- {model2vec-0.3.5 → model2vec-0.3.6}/uv.lock +15 -15
- {model2vec-0.3.5 → model2vec-0.3.6}/.github/workflows/ci.yaml +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/.gitignore +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/.pre-commit-config.yaml +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/LICENSE +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/Makefile +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/README.md +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/logo.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/logo_v2.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/model2vec_model_diagram.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/model2vec_model_diagram_transparant_dark.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/model2vec_model_diagram_transparant_light.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/sentences_per_second_vs_average_score.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/speed_vs_accuracy.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/speed_vs_accuracy_v2.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/speed_vs_accuracy_v3.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/speed_vs_accuracy_v4.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/speed_vs_mteb_score.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/speed_vs_mteb_score_v2.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/assets/images/tutorial_ezlo.png +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec/__init__.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec/distill/__init__.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec/distill/distillation.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec/distill/inference.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec/distill/tokenizer.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec/distill/utils.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec/model_card_template.md +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec/utils.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec.egg-info/SOURCES.txt +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec.egg-info/dependency_links.txt +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec.egg-info/requires.txt +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/model2vec.egg-info/top_level.txt +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/pyproject.toml +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/results/README.md +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/scripts/export_to_onnx.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/setup.cfg +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/tests/__init__.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/tests/conftest.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/tests/data/test_tokenizer/special_tokens_map.json +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/tests/data/test_tokenizer/tokenizer.json +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/tests/data/test_tokenizer/tokenizer_config.json +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/tests/test_distillation.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/tests/test_model.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/tests/test_utils.py +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/tutorials/README.md +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/tutorials/recipe_search.ipynb +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/tutorials/semantic_chunking.ipynb +0 -0
- {model2vec-0.3.5 → model2vec-0.3.6}/tutorials/semantic_deduplication.ipynb +0 -0
|
@@ -84,7 +84,7 @@ def _create_model_card(
|
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
def load_pretrained(
|
|
87
|
-
folder_or_repo_path: str | Path, token: str | None = None
|
|
87
|
+
folder_or_repo_path: str | Path, token: str | None = None, from_sentence_transformers: bool = False
|
|
88
88
|
) -> tuple[np.ndarray, Tokenizer, dict[str, Any], dict[str, Any]]:
|
|
89
89
|
"""
|
|
90
90
|
Loads a pretrained model from a folder.
|
|
@@ -93,26 +93,31 @@ def load_pretrained(
|
|
|
93
93
|
- If this is a local path, we will load from the local path.
|
|
94
94
|
- If the local path is not found, we will attempt to load from the huggingface hub.
|
|
95
95
|
:param token: The huggingface token to use.
|
|
96
|
+
:param from_sentence_transformers: Whether to load the model from a sentence transformers model.
|
|
96
97
|
:raises: FileNotFoundError if the folder exists, but the file does not exist locally.
|
|
97
98
|
:return: The embeddings, tokenizer, config, and metadata.
|
|
98
99
|
|
|
99
100
|
"""
|
|
101
|
+
if from_sentence_transformers:
|
|
102
|
+
model_file = "0_StaticEmbedding/model.safetensors"
|
|
103
|
+
tokenizer_file = "0_StaticEmbedding/tokenizer.json"
|
|
104
|
+
config_name = "config_sentence_transformers.json"
|
|
105
|
+
else:
|
|
106
|
+
model_file = "model.safetensors"
|
|
107
|
+
tokenizer_file = "tokenizer.json"
|
|
108
|
+
config_name = "config.json"
|
|
109
|
+
|
|
100
110
|
folder_or_repo_path = Path(folder_or_repo_path)
|
|
101
111
|
if folder_or_repo_path.exists():
|
|
102
|
-
embeddings_path = folder_or_repo_path /
|
|
112
|
+
embeddings_path = folder_or_repo_path / model_file
|
|
103
113
|
if not embeddings_path.exists():
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
embeddings_path = old_embeddings_path
|
|
108
|
-
else:
|
|
109
|
-
raise FileNotFoundError(f"Embeddings file does not exist in {folder_or_repo_path}")
|
|
110
|
-
|
|
111
|
-
config_path = folder_or_repo_path / "config.json"
|
|
114
|
+
raise FileNotFoundError(f"Embeddings file does not exist in {folder_or_repo_path}")
|
|
115
|
+
|
|
116
|
+
config_path = folder_or_repo_path / config_name
|
|
112
117
|
if not config_path.exists():
|
|
113
118
|
raise FileNotFoundError(f"Config file does not exist in {folder_or_repo_path}")
|
|
114
119
|
|
|
115
|
-
tokenizer_path = folder_or_repo_path /
|
|
120
|
+
tokenizer_path = folder_or_repo_path / tokenizer_file
|
|
116
121
|
if not tokenizer_path.exists():
|
|
117
122
|
raise FileNotFoundError(f"Tokenizer file does not exist in {folder_or_repo_path}")
|
|
118
123
|
|
|
@@ -122,18 +127,7 @@ def load_pretrained(
|
|
|
122
127
|
|
|
123
128
|
else:
|
|
124
129
|
logger.info("Folder does not exist locally, attempting to use huggingface hub.")
|
|
125
|
-
|
|
126
|
-
embeddings_path = huggingface_hub.hf_hub_download(
|
|
127
|
-
folder_or_repo_path.as_posix(), "model.safetensors", token=token
|
|
128
|
-
)
|
|
129
|
-
except huggingface_hub.utils.EntryNotFoundError as e:
|
|
130
|
-
try:
|
|
131
|
-
embeddings_path = huggingface_hub.hf_hub_download(
|
|
132
|
-
folder_or_repo_path.as_posix(), "embeddings.safetensors", token=token
|
|
133
|
-
)
|
|
134
|
-
except huggingface_hub.utils.EntryNotFoundError:
|
|
135
|
-
# Raise original exception.
|
|
136
|
-
raise e
|
|
130
|
+
embeddings_path = huggingface_hub.hf_hub_download(folder_or_repo_path.as_posix(), model_file, token=token)
|
|
137
131
|
|
|
138
132
|
try:
|
|
139
133
|
readme_path = huggingface_hub.hf_hub_download(folder_or_repo_path.as_posix(), "README.md", token=token)
|
|
@@ -142,11 +136,14 @@ def load_pretrained(
|
|
|
142
136
|
logger.info("No README found in the model folder. No model card loaded.")
|
|
143
137
|
metadata = {}
|
|
144
138
|
|
|
145
|
-
config_path = huggingface_hub.hf_hub_download(folder_or_repo_path.as_posix(),
|
|
146
|
-
tokenizer_path = huggingface_hub.hf_hub_download(folder_or_repo_path.as_posix(),
|
|
139
|
+
config_path = huggingface_hub.hf_hub_download(folder_or_repo_path.as_posix(), config_name, token=token)
|
|
140
|
+
tokenizer_path = huggingface_hub.hf_hub_download(folder_or_repo_path.as_posix(), tokenizer_file, token=token)
|
|
147
141
|
|
|
148
142
|
opened_tensor_file = cast(SafeOpenProtocol, safetensors.safe_open(embeddings_path, framework="numpy"))
|
|
149
|
-
|
|
143
|
+
if from_sentence_transformers:
|
|
144
|
+
embeddings = opened_tensor_file.get_tensor("embedding.weight")
|
|
145
|
+
else:
|
|
146
|
+
embeddings = opened_tensor_file.get_tensor("embeddings")
|
|
150
147
|
|
|
151
148
|
tokenizer: Tokenizer = Tokenizer.from_file(str(tokenizer_path))
|
|
152
149
|
config = json.load(open(config_path))
|
|
@@ -160,12 +160,33 @@ class StaticModel:
|
|
|
160
160
|
"""
|
|
161
161
|
from model2vec.hf_utils import load_pretrained
|
|
162
162
|
|
|
163
|
-
embeddings, tokenizer, config, metadata = load_pretrained(path, token=token)
|
|
163
|
+
embeddings, tokenizer, config, metadata = load_pretrained(path, token=token, from_sentence_transformers=False)
|
|
164
164
|
|
|
165
165
|
return cls(
|
|
166
166
|
embeddings, tokenizer, config, base_model_name=metadata.get("base_model"), language=metadata.get("language")
|
|
167
167
|
)
|
|
168
168
|
|
|
169
|
+
@classmethod
|
|
170
|
+
def from_sentence_transformers(
|
|
171
|
+
cls: type[StaticModel],
|
|
172
|
+
path: PathLike,
|
|
173
|
+
token: str | None = None,
|
|
174
|
+
) -> StaticModel:
|
|
175
|
+
"""
|
|
176
|
+
Load a StaticModel trained with sentence transformers from a local path or huggingface hub path.
|
|
177
|
+
|
|
178
|
+
NOTE: if you load a private model from the huggingface hub, you need to pass a token.
|
|
179
|
+
|
|
180
|
+
:param path: The path to load your static model from.
|
|
181
|
+
:param token: The huggingface token to use.
|
|
182
|
+
:return: A StaticModel
|
|
183
|
+
"""
|
|
184
|
+
from model2vec.hf_utils import load_pretrained
|
|
185
|
+
|
|
186
|
+
embeddings, tokenizer, config, _ = load_pretrained(path, token=token, from_sentence_transformers=True)
|
|
187
|
+
|
|
188
|
+
return cls(embeddings, tokenizer, config, base_model_name=None, language=None)
|
|
189
|
+
|
|
169
190
|
def encode_as_sequence(
|
|
170
191
|
self,
|
|
171
192
|
sentences: list[str] | str,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version_triple__ = (0, 3,
|
|
1
|
+
__version_triple__ = (0, 3, 6)
|
|
2
2
|
__version__ = ".".join(map(str, __version_triple__))
|
|
@@ -160,7 +160,7 @@ name = "click"
|
|
|
160
160
|
version = "8.1.8"
|
|
161
161
|
source = { registry = "https://pypi.org/simple" }
|
|
162
162
|
dependencies = [
|
|
163
|
-
{ name = "colorama", marker = "
|
|
163
|
+
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
|
164
164
|
]
|
|
165
165
|
sdist = { url = "https://files.pythonhosted.org/packages/b9/2e/0090cbf739cee7d23781ad4b89a9894a41538e4fcf4c31dcdd705b78eb8b/click-8.1.8.tar.gz", hash = "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a", size = 226593 }
|
|
166
166
|
wheels = [
|
|
@@ -536,7 +536,7 @@ wheels = [
|
|
|
536
536
|
|
|
537
537
|
[[package]]
|
|
538
538
|
name = "model2vec"
|
|
539
|
-
version = "0.3.
|
|
539
|
+
version = "0.3.5"
|
|
540
540
|
source = { editable = "." }
|
|
541
541
|
dependencies = [
|
|
542
542
|
{ name = "jinja2" },
|
|
@@ -1627,19 +1627,19 @@ dependencies = [
|
|
|
1627
1627
|
{ name = "jinja2" },
|
|
1628
1628
|
{ name = "networkx", version = "3.2.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },
|
|
1629
1629
|
{ name = "networkx", version = "3.4.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.10'" },
|
|
1630
|
-
{ name = "nvidia-cublas-cu12", marker = "platform_machine == 'x86_64' and
|
|
1631
|
-
{ name = "nvidia-cuda-cupti-cu12", marker = "platform_machine == 'x86_64' and
|
|
1632
|
-
{ name = "nvidia-cuda-nvrtc-cu12", marker = "platform_machine == 'x86_64' and
|
|
1633
|
-
{ name = "nvidia-cuda-runtime-cu12", marker = "platform_machine == 'x86_64' and
|
|
1634
|
-
{ name = "nvidia-cudnn-cu12", marker = "platform_machine == 'x86_64' and
|
|
1635
|
-
{ name = "nvidia-cufft-cu12", marker = "platform_machine == 'x86_64' and
|
|
1636
|
-
{ name = "nvidia-curand-cu12", marker = "platform_machine == 'x86_64' and
|
|
1637
|
-
{ name = "nvidia-cusolver-cu12", marker = "platform_machine == 'x86_64' and
|
|
1638
|
-
{ name = "nvidia-cusparse-cu12", marker = "platform_machine == 'x86_64' and
|
|
1639
|
-
{ name = "nvidia-nccl-cu12", marker = "platform_machine == 'x86_64' and
|
|
1640
|
-
{ name = "nvidia-nvtx-cu12", marker = "platform_machine == 'x86_64' and
|
|
1630
|
+
{ name = "nvidia-cublas-cu12", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
|
|
1631
|
+
{ name = "nvidia-cuda-cupti-cu12", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
|
|
1632
|
+
{ name = "nvidia-cuda-nvrtc-cu12", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
|
|
1633
|
+
{ name = "nvidia-cuda-runtime-cu12", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
|
|
1634
|
+
{ name = "nvidia-cudnn-cu12", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
|
|
1635
|
+
{ name = "nvidia-cufft-cu12", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
|
|
1636
|
+
{ name = "nvidia-curand-cu12", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
|
|
1637
|
+
{ name = "nvidia-cusolver-cu12", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
|
|
1638
|
+
{ name = "nvidia-cusparse-cu12", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
|
|
1639
|
+
{ name = "nvidia-nccl-cu12", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
|
|
1640
|
+
{ name = "nvidia-nvtx-cu12", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
|
|
1641
1641
|
{ name = "sympy" },
|
|
1642
|
-
{ name = "triton", marker = "python_full_version < '3.13' and platform_machine == 'x86_64' and
|
|
1642
|
+
{ name = "triton", marker = "python_full_version < '3.13' and platform_machine == 'x86_64' and sys_platform == 'linux'" },
|
|
1643
1643
|
{ name = "typing-extensions" },
|
|
1644
1644
|
]
|
|
1645
1645
|
wheels = [
|
|
@@ -1666,7 +1666,7 @@ name = "tqdm"
|
|
|
1666
1666
|
version = "4.67.1"
|
|
1667
1667
|
source = { registry = "https://pypi.org/simple" }
|
|
1668
1668
|
dependencies = [
|
|
1669
|
-
{ name = "colorama", marker = "
|
|
1669
|
+
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
|
1670
1670
|
]
|
|
1671
1671
|
sdist = { url = "https://files.pythonhosted.org/packages/a8/4b/29b4ef32e036bb34e4ab51796dd745cdba7ed47ad142a9f4a1eb8e0c744d/tqdm-4.67.1.tar.gz", hash = "sha256:f8aef9c52c08c13a65f30ea34f4e5aac3fd1a34959879d7e59e63027286627f2", size = 169737 }
|
|
1672
1672
|
wheels = [
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{model2vec-0.3.5 → model2vec-0.3.6}/assets/images/model2vec_model_diagram_transparant_dark.png
RENAMED
|
File without changes
|
{model2vec-0.3.5 → model2vec-0.3.6}/assets/images/model2vec_model_diagram_transparant_light.png
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|