model2vec 0.9.0__tar.gz → 0.11.0__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.11.0/.github/workflows/ci.yaml +127 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/.pre-commit-config.yaml +7 -3
- model2vec-0.11.0/CONTRIBUTING.md +79 -0
- model2vec-0.11.0/Makefile +50 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/PKG-INFO +32 -55
- {model2vec-0.9.0 → model2vec-0.11.0}/README.md +23 -50
- model2vec-0.11.0/assets/images/speed_vs_mteb_plot.svg +2430 -0
- model2vec-0.11.0/docs/internals.md +72 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/distill/__init__.py +2 -2
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/distill/distillation.py +177 -53
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/distill/inference.py +50 -11
- model2vec-0.11.0/model2vec/inference/README.md +104 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/inference/evaluation.py +3 -2
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/inference/mlp.py +3 -1
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/inference/model.py +34 -64
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/model.py +270 -224
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/modelcards/model_card_template.md +1 -1
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/modelcards/modelcards.py +3 -1
- model2vec-0.11.0/model2vec/modelcards/onnx_classifier_template.md +58 -0
- model2vec-0.11.0/model2vec/modelcards/onnx_model_card_template.md +58 -0
- model2vec-0.11.0/model2vec/onnx.py +343 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/persistence/datamodels.py +9 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/persistence/persistence.py +35 -10
- model2vec-0.11.0/model2vec/persistence/utils.py +10 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/tokenizer/tokenizer.py +29 -5
- model2vec-0.11.0/model2vec/train/README.md +307 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/train/__init__.py +7 -1
- model2vec-0.11.0/model2vec/train/base.py +616 -0
- model2vec-0.11.0/model2vec/train/classifier.py +512 -0
- model2vec-0.11.0/model2vec/train/dataset.py +369 -0
- model2vec-0.11.0/model2vec/train/pairs.py +357 -0
- model2vec-0.11.0/model2vec/train/similarity.py +257 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/train/trainer.py +30 -29
- model2vec-0.11.0/model2vec/train/utils.py +131 -0
- model2vec-0.11.0/model2vec/types.py +28 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/utils.py +1 -35
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/version.py +1 -1
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/vocabulary_quantization.py +7 -2
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec.egg-info/PKG-INFO +32 -55
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec.egg-info/SOURCES.txt +18 -6
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec.egg-info/requires.txt +8 -4
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec.egg-info/scm_file_list.json +80 -68
- model2vec-0.11.0/model2vec.egg-info/scm_version.json +8 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/pyproject.toml +7 -6
- model2vec-0.11.0/results/README.md +155 -0
- model2vec-0.11.0/results/make_speed_vs_mteb_plot.py +252 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/conftest.py +35 -4
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/integration/data/Alibaba-NLP___gte-modernbert-base_baseline.json +12 -12
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/integration/data/baai___bge-base-en-v1.5_baseline.json +7 -7
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/integration/data/google___embeddinggemma-300m_baseline.json +10 -10
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/integration/data/intfloat___multilingual-e5-base_baseline.json +11 -11
- model2vec-0.11.0/tests/integration/data/pretrained/minishlab___potion-base-32m_baseline.json +74 -0
- model2vec-0.11.0/tests/integration/data/pretrained/minishlab___potion-base-8m_baseline.json +74 -0
- model2vec-0.11.0/tests/integration/data/pretrained/minishlab___potion-multilingual-128m_baseline.json +178 -0
- model2vec-0.11.0/tests/integration/data/pretrained/minishlab___potion-retrieval-32m_baseline.json +74 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/integration/data/sentence-transformers___all-MiniLM-L6-v2_baseline.json +19 -19
- model2vec-0.11.0/tests/integration/pretrained_model_metrics.py +102 -0
- model2vec-0.11.0/tests/integration/test_onnx_export.py +80 -0
- model2vec-0.11.0/tests/integration/test_pretrained_model_regression.py +160 -0
- model2vec-0.11.0/tests/integration/update_pretrained_baseline.py +41 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/test_distillation.py +190 -31
- model2vec-0.11.0/tests/test_export_to_onnx.py +374 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/test_inference.py +76 -6
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/test_model.py +200 -38
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/test_persistence.py +38 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/test_quantization.py +36 -0
- model2vec-0.11.0/tests/test_trainable.py +1835 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/test_utils.py +1 -1
- {model2vec-0.9.0 → model2vec-0.11.0}/uv.lock +213 -17
- model2vec-0.9.0/.github/workflows/ci.yaml +0 -59
- model2vec-0.9.0/Makefile +0 -29
- model2vec-0.9.0/assets/images/speed_vs_mteb_plot.png +0 -0
- model2vec-0.9.0/model2vec/inference/README.md +0 -31
- model2vec-0.9.0/model2vec/train/README.md +0 -145
- model2vec-0.9.0/model2vec/train/base.py +0 -415
- model2vec-0.9.0/model2vec/train/classifier.py +0 -296
- model2vec-0.9.0/model2vec/train/dataset.py +0 -39
- model2vec-0.9.0/model2vec/train/similarity.py +0 -132
- model2vec-0.9.0/model2vec/train/utils.py +0 -135
- model2vec-0.9.0/model2vec.egg-info/scm_version.json +0 -8
- model2vec-0.9.0/results/README.md +0 -171
- model2vec-0.9.0/results/make_speed_vs_mteb_plot.py +0 -186
- model2vec-0.9.0/scripts/export_to_onnx.py +0 -205
- model2vec-0.9.0/tests/test_trainable.py +0 -512
- model2vec-0.9.0/tutorials/README.md +0 -16
- model2vec-0.9.0/tutorials/recipe_search.ipynb +0 -500
- model2vec-0.9.0/tutorials/semantic_chunking.ipynb +0 -268
- model2vec-0.9.0/tutorials/train_classifier.ipynb +0 -806
- {model2vec-0.9.0 → model2vec-0.11.0}/.github/workflows/release.yaml +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/.gitignore +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/CITATION.cff +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/LICENSE +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/assets/images/logo_v2.png +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/assets/images/model2vec_logo.png +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/assets/images/speed_vs_mteb_score_v3.png +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/assets/images/training_speed_vs_score.png +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/assets/images/tutorial_ezlo.png +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/docs/README.md +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/__init__.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/distill/utils.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/inference/__init__.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/modelcards/__init__.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/modelcards/classifier_template.md +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/persistence/__init__.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/persistence/hf.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/py.typed +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/quantization.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/tokenizer/__init__.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec/train/regression.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec.egg-info/dependency_links.txt +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/model2vec.egg-info/top_level.txt +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/setup.cfg +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/__init__.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/data/test_tokenizer/special_tokens_map.json +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/data/test_tokenizer/tokenizer.json +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/data/test_tokenizer/tokenizer_config.json +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/integration/__init__.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/integration/distill_metrics.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/integration/test_distill_regression.py +0 -0
- {model2vec-0.9.0 → model2vec-0.11.0}/tests/integration/update_distill_baseline.py +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
name: Run tests and upload coverage
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
changes:
|
|
11
|
+
name: Detect code changes
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
outputs:
|
|
14
|
+
code: ${{ steps.filter.outputs.code }}
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
17
|
+
with:
|
|
18
|
+
fetch-depth: 0
|
|
19
|
+
|
|
20
|
+
- name: Check for changes outside non-code files
|
|
21
|
+
id: filter
|
|
22
|
+
shell: bash
|
|
23
|
+
env:
|
|
24
|
+
EVENT_NAME: ${{ github.event_name }}
|
|
25
|
+
PR_BASE: ${{ github.event.pull_request.base.sha }}
|
|
26
|
+
PR_HEAD: ${{ github.event.pull_request.head.sha }}
|
|
27
|
+
PUSH_BEFORE: ${{ github.event.before }}
|
|
28
|
+
PUSH_AFTER: ${{ github.event.after }}
|
|
29
|
+
run: |
|
|
30
|
+
if [[ "$EVENT_NAME" == "pull_request" ]]; then
|
|
31
|
+
range="$PR_BASE...$PR_HEAD"
|
|
32
|
+
elif [[ -z "$PUSH_BEFORE" || "$PUSH_BEFORE" =~ ^0+$ ]]; then
|
|
33
|
+
echo "code=true" >> "$GITHUB_OUTPUT"
|
|
34
|
+
exit 0
|
|
35
|
+
else
|
|
36
|
+
range="$PUSH_BEFORE..$PUSH_AFTER"
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
if ! files=$(git diff --no-renames --name-only "$range"); then
|
|
40
|
+
echo "code=true" >> "$GITHUB_OUTPUT"
|
|
41
|
+
exit 0
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
code=false
|
|
45
|
+
while IFS= read -r file; do
|
|
46
|
+
case "$file" in
|
|
47
|
+
"") ;;
|
|
48
|
+
model2vec/modelcards/*) code=true ;;
|
|
49
|
+
*.md|assets/*|docs/*|results/*|LICENSE|CITATION.cff) ;;
|
|
50
|
+
*) code=true ;;
|
|
51
|
+
esac
|
|
52
|
+
done <<< "$files"
|
|
53
|
+
|
|
54
|
+
echo "code=$code" >> "$GITHUB_OUTPUT"
|
|
55
|
+
|
|
56
|
+
test:
|
|
57
|
+
name: Run tests with pytest
|
|
58
|
+
needs: changes
|
|
59
|
+
if: needs.changes.outputs.code == 'true'
|
|
60
|
+
runs-on: ${{ matrix.os }}
|
|
61
|
+
strategy:
|
|
62
|
+
fail-fast: false
|
|
63
|
+
matrix:
|
|
64
|
+
os: ["ubuntu-latest", "windows-latest"]
|
|
65
|
+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
66
|
+
|
|
67
|
+
steps:
|
|
68
|
+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
|
|
69
|
+
|
|
70
|
+
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
|
|
71
|
+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
|
|
72
|
+
with:
|
|
73
|
+
python-version: ${{ matrix.python-version }}
|
|
74
|
+
allow-prereleases: true
|
|
75
|
+
|
|
76
|
+
- name: Install uv
|
|
77
|
+
uses: astral-sh/setup-uv@d0d8abe699bfb85fec6de9f7adb5ae17292296ff
|
|
78
|
+
|
|
79
|
+
- name: Create virtual environment
|
|
80
|
+
run: uv venv .venv
|
|
81
|
+
|
|
82
|
+
- name: Add venv to PATH (Linux/macOS)
|
|
83
|
+
if: runner.os != 'Windows'
|
|
84
|
+
run: |
|
|
85
|
+
echo "VIRTUAL_ENV=.venv" >> $GITHUB_ENV
|
|
86
|
+
echo "$PWD/.venv/bin" >> $GITHUB_PATH
|
|
87
|
+
|
|
88
|
+
- name: Add venv to PATH (Windows)
|
|
89
|
+
if: runner.os == 'Windows'
|
|
90
|
+
shell: pwsh
|
|
91
|
+
run: |
|
|
92
|
+
"VIRTUAL_ENV=.venv" >> $env:GITHUB_ENV
|
|
93
|
+
"$pwd\.venv\Scripts" >> $env:GITHUB_PATH
|
|
94
|
+
|
|
95
|
+
- name: Install dependencies
|
|
96
|
+
run: make install-no-pre-commit
|
|
97
|
+
|
|
98
|
+
- name: Run tests under coverage
|
|
99
|
+
shell: bash
|
|
100
|
+
run: |
|
|
101
|
+
coverage run --source=model2vec -m pytest --ignore=tests/integration
|
|
102
|
+
coverage report
|
|
103
|
+
|
|
104
|
+
- name: Upload results to Codecov
|
|
105
|
+
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238
|
|
106
|
+
with:
|
|
107
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
108
|
+
|
|
109
|
+
tests-passed:
|
|
110
|
+
name: Tests passed
|
|
111
|
+
needs: [changes, test]
|
|
112
|
+
if: always()
|
|
113
|
+
runs-on: ubuntu-latest
|
|
114
|
+
steps:
|
|
115
|
+
- name: Check test results
|
|
116
|
+
shell: bash
|
|
117
|
+
env:
|
|
118
|
+
CHANGES_RESULT: ${{ needs.changes.result }}
|
|
119
|
+
TEST_RESULT: ${{ needs.test.result }}
|
|
120
|
+
run: |
|
|
121
|
+
echo "changes: $CHANGES_RESULT, test: $TEST_RESULT"
|
|
122
|
+
if [[ "$CHANGES_RESULT" != "success" ]]; then
|
|
123
|
+
exit 1
|
|
124
|
+
fi
|
|
125
|
+
if [[ "$TEST_RESULT" != "success" && "$TEST_RESULT" != "skipped" ]]; then
|
|
126
|
+
exit 1
|
|
127
|
+
fi
|
|
@@ -30,8 +30,12 @@ repos:
|
|
|
30
30
|
- id: ruff-check
|
|
31
31
|
args: [--fix]
|
|
32
32
|
- id: ruff-format
|
|
33
|
-
- repo:
|
|
34
|
-
rev: v1.15.0
|
|
33
|
+
- repo: local
|
|
35
34
|
hooks:
|
|
36
35
|
- id: mypy
|
|
37
|
-
|
|
36
|
+
name: mypy
|
|
37
|
+
entry: uv run --frozen mypy
|
|
38
|
+
language: system
|
|
39
|
+
types: [python]
|
|
40
|
+
pass_filenames: false
|
|
41
|
+
args: [model2vec/]
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Contributing to model2vec
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in model2vec. This document explains how contributions work and what we expect.
|
|
4
|
+
|
|
5
|
+
## tl;dr
|
|
6
|
+
|
|
7
|
+
- **Every PR must link to an existing issue.** Open an issue to discuss before writing code, then link it from your PR (e.g. `Closes #123`).
|
|
8
|
+
- **AI-generated PRs** will be closed without review if they weren't discussed beforehand.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Discuss before building
|
|
13
|
+
|
|
14
|
+
Our libraries are small and focused by design. We care a lot about keeping it that way. Before you invest time writing code, please open an issue describing:
|
|
15
|
+
|
|
16
|
+
- What problem you're solving
|
|
17
|
+
- Why it belongs in model2vec (as opposed to a wrapper or separate tool)
|
|
18
|
+
- What API or behaviour change it would involve, if any
|
|
19
|
+
- A minimal (code) example of how it would work
|
|
20
|
+
|
|
21
|
+
This applies to small PRs (e.g. bug fixes and documentation updates) as well. A quick issue lets us confirm the fix is wanted and aligned with how we'd want to solve it, so you don't waste time on a PR we'd need to reject or rework.
|
|
22
|
+
|
|
23
|
+
**PRs without a linked issue will be closed.**
|
|
24
|
+
|
|
25
|
+
## What we generally welcome
|
|
26
|
+
|
|
27
|
+
- Bug fixes (with a linked issue and a test that reproduces the issue)
|
|
28
|
+
- Documentation improvements and example fixes (with a linked issue)
|
|
29
|
+
|
|
30
|
+
## What we generally won't accept
|
|
31
|
+
|
|
32
|
+
- Large new features that haven't been discussed
|
|
33
|
+
- Features that significantly expand the scope of the library
|
|
34
|
+
- Dependency additions
|
|
35
|
+
- AI-generated code dumps with no context or discussion
|
|
36
|
+
|
|
37
|
+
## Opening a good issue
|
|
38
|
+
|
|
39
|
+
If you found a bug, include:
|
|
40
|
+
- model2vec version
|
|
41
|
+
- Python version
|
|
42
|
+
- A minimal reproducible example
|
|
43
|
+
- What you expected vs. what happened
|
|
44
|
+
|
|
45
|
+
If you want a feature, include the things listed under "Discuss before building" above.
|
|
46
|
+
|
|
47
|
+
## Pull request checklist
|
|
48
|
+
|
|
49
|
+
Before opening a PR:
|
|
50
|
+
|
|
51
|
+
- [ ] Link to an existing issue (e.g. `Closes #123`). PRs without one will be closed
|
|
52
|
+
- [ ] Run `make test` and confirm all tests pass
|
|
53
|
+
- [ ] Run `make lint` and `make typecheck`
|
|
54
|
+
- [ ] Run `make fix` to auto-fix any lint issues
|
|
55
|
+
- [ ] If you added behaviour, add or update tests
|
|
56
|
+
- [ ] If you changed a public API, update the docstrings
|
|
57
|
+
- [ ] Keep the diff focused (one logical change per PR)
|
|
58
|
+
|
|
59
|
+
You can also run `make pre-commit` to run all checks at once.
|
|
60
|
+
|
|
61
|
+
## Code style
|
|
62
|
+
|
|
63
|
+
- We use `ruff` for formatting and linting
|
|
64
|
+
- We use `mypy` for type checking and expect all new code to be fully typed
|
|
65
|
+
- Keep things simple; we prefer readable over clever
|
|
66
|
+
|
|
67
|
+
## A note on AI-assisted contributions
|
|
68
|
+
|
|
69
|
+
We don't have a blanket policy against AI tools (we also use them ourselves). But we do expect:
|
|
70
|
+
|
|
71
|
+
1. **You understand what you're submitting.** If you ran an agent against the repo and opened a PR with the output, you should be able to explain what it does.
|
|
72
|
+
2. **The contribution was discussed first.** An AI generating code for an agreed-on, well-scoped issue is fine. An AI inventing features and opening a PR is not.
|
|
73
|
+
3. **Tests and quality are your responsibility.** "The AI wrote it" is not a substitute for correctness.
|
|
74
|
+
|
|
75
|
+
PRs that appear to be unreviewed AI output (large scope, multiple unrelated files touched, no prior discussion, new deps) will be closed with a pointer to this document.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
Questions? Open an issue.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
.PHONY: help install install-no-pre-commit install-base test test-integration test-integration-update test-integration-pretrained-update lint typecheck fix pre-commit
|
|
2
|
+
|
|
3
|
+
help:
|
|
4
|
+
@echo "Available targets:"
|
|
5
|
+
@echo " install Install all dependencies and pre-commit hooks"
|
|
6
|
+
@echo " install-no-pre-commit Install all dependencies without pre-commit hooks"
|
|
7
|
+
@echo " install-base Install only the dev dependencies"
|
|
8
|
+
@echo " test Run unit tests with coverage (excludes integration tests)"
|
|
9
|
+
@echo " test-integration Run integration tests"
|
|
10
|
+
@echo " test-integration-update Regenerate the distill integration baseline"
|
|
11
|
+
@echo " test-integration-pretrained-update Regenerate the pretrained integration baseline"
|
|
12
|
+
@echo " lint Run ruff and pydoclint"
|
|
13
|
+
@echo " typecheck Run mypy"
|
|
14
|
+
@echo " fix Auto-fix lint issues and format code"
|
|
15
|
+
@echo " pre-commit Run all pre-commit hooks"
|
|
16
|
+
|
|
17
|
+
install: install-no-pre-commit
|
|
18
|
+
uv run pre-commit install
|
|
19
|
+
|
|
20
|
+
install-no-pre-commit:
|
|
21
|
+
uv sync --all-extras
|
|
22
|
+
|
|
23
|
+
install-base:
|
|
24
|
+
uv sync --extra dev
|
|
25
|
+
|
|
26
|
+
lint:
|
|
27
|
+
uv run ruff check model2vec/ tests/
|
|
28
|
+
uv run pydoclint model2vec/
|
|
29
|
+
|
|
30
|
+
typecheck:
|
|
31
|
+
uv run mypy model2vec/
|
|
32
|
+
|
|
33
|
+
fix:
|
|
34
|
+
uv run ruff check --fix model2vec/ tests/
|
|
35
|
+
uv run ruff format model2vec/ tests/
|
|
36
|
+
|
|
37
|
+
pre-commit:
|
|
38
|
+
uv run pre-commit run --all-files
|
|
39
|
+
|
|
40
|
+
test:
|
|
41
|
+
uv run pytest --cov=model2vec --cov-report=term-missing --ignore=tests/integration $(VERBOSITY)
|
|
42
|
+
|
|
43
|
+
test-integration:
|
|
44
|
+
uv run pytest tests/integration $(VERBOSITY)
|
|
45
|
+
|
|
46
|
+
test-integration-update:
|
|
47
|
+
uv run python -m tests.integration.update_distill_baseline
|
|
48
|
+
|
|
49
|
+
test-integration-pretrained-update:
|
|
50
|
+
uv run python -m tests.integration.update_pretrained_baseline
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: model2vec
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0
|
|
4
4
|
Summary: Fast State-of-the-Art Static Embeddings
|
|
5
5
|
Author-email: Stéphan Tulkens <stephantul@gmail.com>, Thomas van Dongen <thomasvdongen@proton.me>
|
|
6
6
|
License: MIT License
|
|
@@ -43,11 +43,12 @@ Classifier: Natural Language :: English
|
|
|
43
43
|
Requires-Python: >=3.10
|
|
44
44
|
Description-Content-Type: text/markdown
|
|
45
45
|
Requires-Dist: jinja2
|
|
46
|
-
Requires-Dist: joblib
|
|
47
46
|
Requires-Dist: numpy
|
|
48
47
|
Requires-Dist: safetensors
|
|
49
|
-
Requires-Dist: tokenizers
|
|
48
|
+
Requires-Dist: tokenizers<1.0.0,>=0.22
|
|
50
49
|
Requires-Dist: tqdm
|
|
50
|
+
Requires-Dist: huggingface-hub>=1.0.0
|
|
51
|
+
Requires-Dist: model2vec-rs<0.6.0,>=0.5.1
|
|
51
52
|
Provides-Extra: dev
|
|
52
53
|
Requires-Dist: ipython; extra == "dev"
|
|
53
54
|
Requires-Dist: mypy; extra == "dev"
|
|
@@ -59,13 +60,16 @@ Requires-Dist: setuptools; extra == "dev"
|
|
|
59
60
|
Provides-Extra: distill
|
|
60
61
|
Requires-Dist: torch; extra == "distill"
|
|
61
62
|
Requires-Dist: transformers<5.4.0; extra == "distill"
|
|
62
|
-
Requires-Dist:
|
|
63
|
-
Requires-Dist: skeletoken<0.5.0,>=0.4.1; extra == "distill"
|
|
63
|
+
Requires-Dist: skeletoken<0.7.0,>=0.6.0; extra == "distill"
|
|
64
64
|
Provides-Extra: onnx
|
|
65
65
|
Requires-Dist: onnx; extra == "onnx"
|
|
66
66
|
Requires-Dist: torch; extra == "onnx"
|
|
67
|
+
Requires-Dist: onnxruntime; extra == "onnx"
|
|
68
|
+
Requires-Dist: onnxscript; extra == "onnx"
|
|
69
|
+
Requires-Dist: skeletoken<0.7.0,>=0.6.0; extra == "onnx"
|
|
67
70
|
Provides-Extra: train
|
|
68
71
|
Requires-Dist: torch; extra == "train"
|
|
72
|
+
Requires-Dist: datasets>=4.0.0; extra == "train"
|
|
69
73
|
Provides-Extra: quantization
|
|
70
74
|
Requires-Dist: scikit-learn; extra == "quantization"
|
|
71
75
|
Provides-Extra: integration
|
|
@@ -82,15 +86,6 @@ Requires-Dist: skops; extra == "tests"
|
|
|
82
86
|
|
|
83
87
|
|
|
84
88
|
|
|
85
|
-
<div align="center">
|
|
86
|
-
<h2>
|
|
87
|
-
<a href="https://huggingface.co/minishlab"><strong>🤗 Models</strong></a> |
|
|
88
|
-
<a href="https://minish.ai/packages/model2vec/introduction"><strong>📖 Docs</strong></a> |
|
|
89
|
-
<a href="https://github.com/MinishLab/model2vec/blob/main/results/README.md"><strong>🏆 Results</strong></a> |
|
|
90
|
-
<a href="https://github.com/MinishLab/model2vec/tree/main/tutorials"><strong>📚 Tutorials</strong></a> |
|
|
91
|
-
<a href="https://minish.ai/blog"><strong>🌐 Blog</strong></a>
|
|
92
|
-
</div>
|
|
93
|
-
|
|
94
89
|
<div align="center">
|
|
95
90
|
<h2>
|
|
96
91
|
<a href="https://pypi.org/project/model2vec/"><img src="https://img.shields.io/pypi/v/model2vec?color=%23007ec6&label=pypi%20package" alt="Package version"></a>
|
|
@@ -107,24 +102,17 @@ Requires-Dist: skops; extra == "tests"
|
|
|
107
102
|
<a href="https://github.com/MinishLab/model2vec/blob/main/LICENSE">
|
|
108
103
|
<img src="https://img.shields.io/badge/license-MIT-green" alt="License - MIT">
|
|
109
104
|
</a>
|
|
110
|
-
|
|
111
|
-
<img src="https://img.shields.io/github/stars/minishlab/model2vec.svg" alt=Stars">
|
|
112
|
-
</a>
|
|
113
|
-
</h2>
|
|
114
|
-
</div>
|
|
105
|
+
</h2>
|
|
115
106
|
|
|
116
107
|
|
|
117
108
|
|
|
109
|
+
[Quickstart](#quickstart) • [Main Features](#main-features) • [Model List](#model-list) • [Results](#results)
|
|
110
|
+
</div>
|
|
118
111
|
|
|
119
112
|
|
|
120
|
-
Model2Vec is a technique to turn any sentence transformer into a small, fast static embedding model. Model2Vec reduces model size by a factor up to 50 and makes models up to 500 times faster, with a small drop in performance. Our [best model](https://huggingface.co/minishlab/potion-base-32M) is the most performant static embedding model in the world. See our [results](results/README.md), read our [docs](https://minish.ai/packages/model2vec/introduction), or dive in to see how it works.
|
|
121
113
|
|
|
122
|
-
|
|
123
|
-
<h3>
|
|
114
|
+
Model2Vec is a technique to turn any sentence transformer into a small, fast static embedding model. Model2Vec reduces model size by a factor up to 50 and makes models up to 30000 times faster, with a small drop in performance. Our [best model](https://huggingface.co/minishlab/blink-8M) is the most performant static embedding model in the world. See our [results](results/README.md), read our [docs](https://minish.ai/packages/model2vec/introduction), or dive in to see how it works.
|
|
124
115
|
|
|
125
|
-
[Quickstart](#quickstart) • [Updates & Announcements](#updates--announcements) • [Main Features](#main-features) • [Model List](#model-list)
|
|
126
|
-
</h3>
|
|
127
|
-
</div>
|
|
128
116
|
|
|
129
117
|
## Quickstart
|
|
130
118
|
|
|
@@ -134,12 +122,12 @@ Install the lightweight base package with:
|
|
|
134
122
|
pip install model2vec
|
|
135
123
|
```
|
|
136
124
|
|
|
137
|
-
You can start using Model2Vec by loading one of our [flagship models from the HuggingFace hub](https://huggingface.co/collections/minishlab/
|
|
125
|
+
You can start using Model2Vec by loading one of our [flagship models from the HuggingFace hub](https://huggingface.co/collections/minishlab/blink). These models are pre-trained and ready to use. The following code snippet shows how to load a model and make embeddings, which you can use for any task, such as text classification, retrieval, clustering, or building a RAG system:
|
|
138
126
|
```python
|
|
139
127
|
from model2vec import StaticModel
|
|
140
128
|
|
|
141
|
-
# Load a model from the HuggingFace hub (in this case the
|
|
142
|
-
model = StaticModel.from_pretrained("minishlab/
|
|
129
|
+
# Load a model from the HuggingFace hub (in this case the blink-8M model)
|
|
130
|
+
model = StaticModel.from_pretrained("minishlab/blink-8M")
|
|
143
131
|
|
|
144
132
|
# Make embeddings
|
|
145
133
|
embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
@@ -147,7 +135,7 @@ embeddings = model.encode(["It's dangerous to go alone!", "It's a secret to ever
|
|
|
147
135
|
# Make sequences of token embeddings
|
|
148
136
|
token_embeddings = model.encode_as_sequence(["It's dangerous to go alone!", "It's a secret to everybody."])
|
|
149
137
|
```
|
|
150
|
-
For advanced usage, see our [inference docs](https://minish.ai/packages/model2vec/inference). Instead of using one of our models, you can also distill your own Model2Vec model from a Sentence Transformer model. First, install the `
|
|
138
|
+
For advanced usage, see our [inference docs](https://minish.ai/packages/model2vec/inference). Instead of using one of our models, you can also distill your own Model2Vec model from a Sentence Transformer model. First, install the `distill` extra with:
|
|
151
139
|
|
|
152
140
|
```bash
|
|
153
141
|
pip install model2vec[distill]
|
|
@@ -166,7 +154,7 @@ m2v_model = distill(model_name="BAAI/bge-base-en-v1.5")
|
|
|
166
154
|
m2v_model.save_pretrained("m2v_model")
|
|
167
155
|
```
|
|
168
156
|
|
|
169
|
-
For advanced usage, see our [distillation docs](https://minish.ai/packages/model2vec/distillation), which includes some [distillation best practices](https://minish.ai/packages/model2vec/distillation#distillation-best-practices). After distillation, you can also fine-tune
|
|
157
|
+
For advanced usage, see our [distillation docs](https://minish.ai/packages/model2vec/distillation), which includes some [distillation best practices](https://minish.ai/packages/model2vec/distillation#distillation-best-practices). After distillation, you can also fine-tune the distilled model, or a pre-trained model, for classification, similarity, regression, or pair similarity (e.g. query-document retrieval). First, make sure you install the `train` extras with:
|
|
170
158
|
|
|
171
159
|
```bash
|
|
172
160
|
pip install model2vec[train]
|
|
@@ -175,12 +163,11 @@ pip install model2vec[train]
|
|
|
175
163
|
Then, you can fine-tune a model as follows:
|
|
176
164
|
|
|
177
165
|
```python
|
|
178
|
-
import numpy as np
|
|
179
166
|
from datasets import load_dataset
|
|
180
167
|
from model2vec.train import StaticModelForClassification
|
|
181
168
|
|
|
182
169
|
# Initialize a classifier from a pre-trained model
|
|
183
|
-
classifier = StaticModelForClassification.from_pretrained(
|
|
170
|
+
classifier = StaticModelForClassification.from_pretrained(path="minishlab/blink-8M")
|
|
184
171
|
|
|
185
172
|
# Load a dataset. Note: both single and multi-label classification datasets are supported
|
|
186
173
|
ds = load_dataset("setfit/subj")
|
|
@@ -194,26 +181,15 @@ classification_report = classifier.evaluate(ds["test"]["text"], ds["test"]["labe
|
|
|
194
181
|
|
|
195
182
|
For advanced usage, see our [training docs](https://minish.ai/packages/model2vec/training).
|
|
196
183
|
|
|
197
|
-
## Updates & Announcements
|
|
198
|
-
|
|
199
|
-
- **23/05/2025**: We released [potion-multilingual-128M](https://huggingface.co/minishlab/potion-multilingual-128M), a multilingual model trained on 101 languages. It is the best performing static embedding model for multilingual tasks, and is capable of generating embeddings for any text in any language. The results can be found in our [results](results/README.md#mmteb-results-multilingual) section.
|
|
200
|
-
|
|
201
|
-
- **01/05/2025**: We released backend support for `BPE` and `Unigram` tokenizers, along with quantization and dimensionality reduction. New Model2Vec models are now 50% of the original models size, and can be quantized to int8 to be 25% of the size, without loss of performance.
|
|
202
|
-
|
|
203
|
-
- **12/02/2025**: We released **Model2Vec training**, allowing you to fine-tune your own classification models on top of Model2Vec models. Find out more in our [training documentation](https://github.com/MinishLab/model2vec/blob/main/model2vec/train/README.md) and [results](results/README.md#training-results).
|
|
204
|
-
|
|
205
|
-
- **30/01/2025**: We released two new models: [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) and [potion-retrieval-32M](https://huggingface.co/minishlab/potion-retrieval-32M). [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) is our most performant model to date, using a larger vocabulary and higher dimensions. [potion-retrieval-32M](https://huggingface.co/minishlab/potion-retrieval-32M) is a finetune of [potion-base-32M](https://huggingface.co/minishlab/potion-base-32M) that is optimized for retrieval tasks, and is the best performing static retrieval model currently available.
|
|
206
|
-
|
|
207
|
-
- **30/10/2024**: We released three new models: [potion-base-8M](https://huggingface.co/minishlab/potion-base-8M), [potion-base-4M](https://huggingface.co/minishlab/potion-base-4M), and [potion-base-2M](https://huggingface.co/minishlab/potion-base-2M). These models are trained using [Tokenlearn](https://github.com/MinishLab/tokenlearn). Find out more in our [blog post](https://minishlab.github.io/tokenlearn_blogpost/). NOTE: for users of any of our old English M2V models, we recommend switching to these new models as they [perform better on all tasks](https://github.com/MinishLab/model2vec/tree/main/results).
|
|
208
184
|
|
|
209
185
|
## Main Features
|
|
210
186
|
|
|
211
187
|
- **State-of-the-Art Performance**: Model2Vec models outperform any other static embeddings (such as GLoVe and BPEmb) by a large margin, as can be seen in our [results](results/README.md).
|
|
212
|
-
- **Small**: Model2Vec reduces the size of a Sentence Transformer model by a factor of up to 50. Our [best model](https://huggingface.co/minishlab/
|
|
188
|
+
- **Small**: Model2Vec reduces the size of a Sentence Transformer model by a factor of up to 50. Our [best model](https://huggingface.co/minishlab/blink-8M) is just ~30 MB on disk, and our smallest model just ~8 MB (making it the smallest model on [MTEB](https://huggingface.co/spaces/mteb/leaderboard)!).
|
|
213
189
|
- **Lightweight Dependencies**: the base package's only major dependency is `numpy`.
|
|
214
|
-
- **Lightning-fast Inference**: up to
|
|
190
|
+
- **Lightning-fast Inference**: up to 30000 times faster on CPU than the original model.
|
|
215
191
|
- **Fast, Dataset-free Distillation**: distill your own model in 30 seconds on a CPU, without a dataset.
|
|
216
|
-
- **Fine-tuning**: fine-tune
|
|
192
|
+
- **Fine-tuning**: fine-tune Model2Vec models for classification, similarity, regression, or pair similarity, and run them without `torch`.
|
|
217
193
|
- **Integrated in many popular libraries**: Model2Vec is integrated direclty into popular libraries such as [Sentence Transformers](https://github.com/UKPLab/sentence-transformers) and [LangChain](https://github.com/langchain-ai/langchain). For more information, see our [integrations documentation](https://minish.ai/packages/model2vec/integrations).
|
|
218
194
|
- **Tightly integrated with HuggingFace hub**: easily share and load models from the HuggingFace hub, using the familiar `from_pretrained` and `push_to_hub`. Our own models can be found [here](https://huggingface.co/minishlab).
|
|
219
195
|
|
|
@@ -227,22 +203,20 @@ The core idea is to forward pass a vocabulary through a sentence transformer mod
|
|
|
227
203
|
|
|
228
204
|
Our official documentation can be found [here](https://minish.ai/packages/model2vec/introduction). This includes in-depth documentation on [inference](https://minish.ai/packages/model2vec/inference), [distillation](https://minish.ai/packages/model2vec/distillation), [training](https://minish.ai/packages/model2vec/training), and [integrations](https://minish.ai/packages/model2vec/integrations).
|
|
229
205
|
|
|
206
|
+
For details on the Rust backend and which dtypes to use, see [internals](docs/internals.md).
|
|
207
|
+
|
|
230
208
|
|
|
231
209
|
## Model List
|
|
232
210
|
|
|
233
|
-
We provide a number of models that can be used out of the box. These models are available on the [HuggingFace hub](https://huggingface.co/collections/minishlab/
|
|
211
|
+
We provide a number of models that can be used out of the box. These models are available on the [HuggingFace hub](https://huggingface.co/collections/minishlab/blink) and can be loaded using the `from_pretrained` method. The models are listed below.
|
|
234
212
|
|
|
235
213
|
|
|
236
214
|
|
|
237
215
|
| Model | Language | Sentence Transformer | Params | Task |
|
|
238
216
|
|-----------------------------------------------------------------------|------------|-----------------------------------------------------------------|---------|-----------|
|
|
239
|
-
| [
|
|
240
|
-
| [
|
|
241
|
-
| [
|
|
242
|
-
| [potion-base-8M](https://huggingface.co/minishlab/potion-base-8M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 7.5M | General |
|
|
243
|
-
| [potion-base-4M](https://huggingface.co/minishlab/potion-base-4M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 3.7M | General |
|
|
244
|
-
| [potion-base-2M](https://huggingface.co/minishlab/potion-base-2M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 1.8M | General |
|
|
245
|
-
|
|
217
|
+
| [blink-8M](https://huggingface.co/minishlab/blink-8M) | English | [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 7.7M | General |
|
|
218
|
+
| [blink-multilingual-64M](https://huggingface.co/minishlab/blink-multilingual-64M) | Multilingual | [bge-m3](https://huggingface.co/BAAI/bge-m3) | 64.0M | General |
|
|
219
|
+
| [blink-code-16M](https://huggingface.co/minishlab/blink-code-16M) | Code | [CodeRankEmbed](https://huggingface.co/nomic-ai/CodeRankEmbed) | 16.0M | Code |
|
|
246
220
|
|
|
247
221
|
|
|
248
222
|
|
|
@@ -253,7 +227,10 @@ We have performed extensive experiments to evaluate the performance of Model2Vec
|
|
|
253
227
|
- [MMTEB Results](results/README.md#mmteb-results)
|
|
254
228
|
- [Retrieval Results](results/README.md#retrieval-results)
|
|
255
229
|
- [Training Results](results/README.md#training-results)
|
|
256
|
-
|
|
230
|
+
|
|
231
|
+
## Acknowledgements
|
|
232
|
+
|
|
233
|
+
Thanks to [Greptile](https://greptile.com) for providing free access to their AI code review platform.
|
|
257
234
|
|
|
258
235
|
## License
|
|
259
236
|
|