Matheel 0.2.0__tar.gz → 0.2.2__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.
- matheel-0.2.2/PKG-INFO +293 -0
- matheel-0.2.2/README.md +252 -0
- {matheel-0.2.0 → matheel-0.2.2}/matheel/__init__.py +15 -3
- matheel-0.2.2/matheel/chunking.py +302 -0
- {matheel-0.2.0 → matheel-0.2.2}/matheel/cli.py +62 -27
- {matheel-0.2.0 → matheel-0.2.2}/matheel/code_metrics.py +2 -2
- {matheel-0.2.0 → matheel-0.2.2}/matheel/comparison_suite.py +27 -11
- matheel-0.2.2/matheel/feature_weights.py +127 -0
- matheel-0.2.2/matheel/model_routing.py +136 -0
- matheel-0.2.2/matheel/similarity.py +779 -0
- matheel-0.2.2/matheel/vectors.py +627 -0
- matheel-0.2.2/matheel.egg-info/PKG-INFO +293 -0
- {matheel-0.2.0 → matheel-0.2.2}/matheel.egg-info/SOURCES.txt +5 -0
- matheel-0.2.2/matheel.egg-info/requires.txt +36 -0
- {matheel-0.2.0 → matheel-0.2.2}/pyproject.toml +32 -10
- matheel-0.2.2/tests/test_chunking.py +84 -0
- {matheel-0.2.0 → matheel-0.2.2}/tests/test_cli.py +24 -8
- {matheel-0.2.0 → matheel-0.2.2}/tests/test_comparison_suite.py +6 -4
- matheel-0.2.2/tests/test_feature_weights.py +19 -0
- matheel-0.2.2/tests/test_model_routing.py +81 -0
- matheel-0.2.2/tests/test_real_models.py +123 -0
- matheel-0.2.2/tests/test_similarity.py +447 -0
- matheel-0.2.2/tests/test_vectors.py +144 -0
- matheel-0.2.0/PKG-INFO +0 -215
- matheel-0.2.0/README.md +0 -189
- matheel-0.2.0/matheel/chunking.py +0 -93
- matheel-0.2.0/matheel/similarity.py +0 -517
- matheel-0.2.0/matheel/vectors.py +0 -101
- matheel-0.2.0/matheel.egg-info/PKG-INFO +0 -215
- matheel-0.2.0/matheel.egg-info/requires.txt +0 -16
- matheel-0.2.0/tests/test_chunking.py +0 -20
- matheel-0.2.0/tests/test_similarity.py +0 -200
- matheel-0.2.0/tests/test_vectors.py +0 -15
- {matheel-0.2.0 → matheel-0.2.2}/LICENSE +0 -0
- {matheel-0.2.0 → matheel-0.2.2}/matheel/preprocessing.py +0 -0
- {matheel-0.2.0 → matheel-0.2.2}/matheel.egg-info/dependency_links.txt +0 -0
- {matheel-0.2.0 → matheel-0.2.2}/matheel.egg-info/entry_points.txt +0 -0
- {matheel-0.2.0 → matheel-0.2.2}/matheel.egg-info/top_level.txt +0 -0
- {matheel-0.2.0 → matheel-0.2.2}/setup.cfg +0 -0
- {matheel-0.2.0 → matheel-0.2.2}/tests/test_code_metrics.py +0 -0
- {matheel-0.2.0 → matheel-0.2.2}/tests/test_preprocessing.py +0 -0
matheel-0.2.2/PKG-INFO
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: matheel
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: Matheel: A CLI and Python package for source-code similarity detection.
|
|
5
|
+
Author: Fahad Ebrahim
|
|
6
|
+
License-Expression: CC-BY-NC-4.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/FahadEbrahim/matheel
|
|
8
|
+
Project-URL: Source, https://github.com/FahadEbrahim/matheel
|
|
9
|
+
Requires-Python: <3.13,>=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: click<9,>=8
|
|
13
|
+
Requires-Dist: pandas<3.1,>=2.2
|
|
14
|
+
Requires-Dist: numpy<3,>=2
|
|
15
|
+
Requires-Dist: rapidfuzz<4,>=3
|
|
16
|
+
Requires-Dist: sentence-transformers<5.2,>=5.1
|
|
17
|
+
Requires-Dist: sentencepiece<0.3,>=0.2
|
|
18
|
+
Provides-Extra: chunking
|
|
19
|
+
Requires-Dist: chonkie<1.6,>=1.5; extra == "chunking"
|
|
20
|
+
Provides-Extra: chunking-code
|
|
21
|
+
Requires-Dist: chonkie[code]<1.6,>=1.5; extra == "chunking-code"
|
|
22
|
+
Provides-Extra: metrics
|
|
23
|
+
Provides-Extra: model2vec
|
|
24
|
+
Requires-Dist: model2vec<0.8,>=0.7; extra == "model2vec"
|
|
25
|
+
Provides-Extra: pylate
|
|
26
|
+
Requires-Dist: pylate<1.5,>=1.4; extra == "pylate"
|
|
27
|
+
Provides-Extra: gradio
|
|
28
|
+
Requires-Dist: gradio<6,>=5; extra == "gradio"
|
|
29
|
+
Requires-Dist: gradio-huggingfacehub-search==0.0.8; extra == "gradio"
|
|
30
|
+
Provides-Extra: all
|
|
31
|
+
Requires-Dist: chonkie[code]<1.6,>=1.5; extra == "all"
|
|
32
|
+
Requires-Dist: model2vec<0.8,>=0.7; extra == "all"
|
|
33
|
+
Requires-Dist: pylate<1.5,>=1.4; extra == "all"
|
|
34
|
+
Requires-Dist: gradio<6,>=5; extra == "all"
|
|
35
|
+
Requires-Dist: gradio-huggingfacehub-search==0.0.8; extra == "all"
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: pytest<9,>=8; extra == "dev"
|
|
38
|
+
Requires-Dist: build<2,>=1; extra == "dev"
|
|
39
|
+
Requires-Dist: twine<7,>=6; extra == "dev"
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# Matheel
|
|
43
|
+
|
|
44
|
+
Matheel is a simple, function-based Python package and CLI for source-code similarity. It combines semantic embeddings, lexical similarity, chunking, preprocessing, and code-aware metrics without forcing a class-heavy API.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
Use Python `3.10` to `3.12`.
|
|
49
|
+
|
|
50
|
+
Base install:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install matheel
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Optional extras:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install "matheel[chunking]"
|
|
60
|
+
pip install "matheel[chunking_code]"
|
|
61
|
+
pip install "matheel[model2vec]"
|
|
62
|
+
pip install "matheel[pylate]"
|
|
63
|
+
pip install "matheel[gradio]"
|
|
64
|
+
pip install "matheel[all]"
|
|
65
|
+
pip install "matheel[dev]"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Tested Python 3.12 constraints:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install -c constraints/py312.txt .
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`matheel[all]` installs the currently supported optional backends in one command: Chonkie code chunking, model2vec, PyLate, and the Gradio app dependencies.
|
|
75
|
+
|
|
76
|
+
## Quick Start
|
|
77
|
+
|
|
78
|
+
The repo includes a small Java archive at `sample_pairs.zip` for smoke tests.
|
|
79
|
+
|
|
80
|
+
CLI:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
matheel compare sample_pairs.zip \
|
|
84
|
+
--model sentence-transformers/all-MiniLM-L6-v2 \
|
|
85
|
+
--feature-weight semantic=0.7 \
|
|
86
|
+
--feature-weight levenshtein=0.3 \
|
|
87
|
+
--threshold 0.2 \
|
|
88
|
+
--num 10
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Python:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from matheel.similarity import get_sim_list
|
|
95
|
+
|
|
96
|
+
results = get_sim_list(
|
|
97
|
+
"sample_pairs.zip",
|
|
98
|
+
model_name="sentence-transformers/all-MiniLM-L6-v2",
|
|
99
|
+
threshold=0.2,
|
|
100
|
+
number_results=10,
|
|
101
|
+
feature_weights={
|
|
102
|
+
"semantic": 0.7,
|
|
103
|
+
"levenshtein": 0.3,
|
|
104
|
+
},
|
|
105
|
+
)
|
|
106
|
+
print(results.head())
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Supported Languages
|
|
110
|
+
|
|
111
|
+
- Chunking is language-agnostic by default because it can split any text.
|
|
112
|
+
- `CodeBLEU`-style metrics are intentionally scoped to `Java`, `Python`, `C`, and `C++`.
|
|
113
|
+
- Generic preprocessing works across languages, but code-aware metrics are most defensible in that four-language scope.
|
|
114
|
+
|
|
115
|
+
## Supported Methods
|
|
116
|
+
|
|
117
|
+
Similarity features:
|
|
118
|
+
|
|
119
|
+
- `semantic`
|
|
120
|
+
- `levenshtein`
|
|
121
|
+
- `jaro_winkler`
|
|
122
|
+
- `code_metric`
|
|
123
|
+
|
|
124
|
+
Code metrics:
|
|
125
|
+
|
|
126
|
+
- `codebleu`
|
|
127
|
+
- `codebleu_ngram`
|
|
128
|
+
- `codebleu_weighted_ngram`
|
|
129
|
+
- `codebleu_syntax`
|
|
130
|
+
- `codebleu_dataflow`
|
|
131
|
+
- `crystalbleu`
|
|
132
|
+
|
|
133
|
+
Chunking methods:
|
|
134
|
+
|
|
135
|
+
- `none`
|
|
136
|
+
- Chonkie-backed when installed: `code`, `codechunker`, `chonkie_code`, `chonkie_token`, `chonkie_sentence`, `chonkie_recursive`, `chonkie_fast`
|
|
137
|
+
|
|
138
|
+
Vector backends:
|
|
139
|
+
|
|
140
|
+
- `auto`
|
|
141
|
+
- `sentence_transformers`
|
|
142
|
+
- `model2vec`
|
|
143
|
+
- `pylate`
|
|
144
|
+
|
|
145
|
+
Single-vector similarity functions:
|
|
146
|
+
|
|
147
|
+
- `cosine`
|
|
148
|
+
- `dot`
|
|
149
|
+
- `euclidean`
|
|
150
|
+
- `manhattan`
|
|
151
|
+
|
|
152
|
+
Sentence Transformers pooling methods:
|
|
153
|
+
|
|
154
|
+
- `mean`
|
|
155
|
+
- `max`
|
|
156
|
+
- `cls`
|
|
157
|
+
- `lasttoken`
|
|
158
|
+
- `mean_sqrt_len_tokens`
|
|
159
|
+
- `weightedmean`
|
|
160
|
+
|
|
161
|
+
`auto` inspects Hugging Face model metadata and routes to the correct backend when the model exposes a known library.
|
|
162
|
+
|
|
163
|
+
## Core Parts
|
|
164
|
+
|
|
165
|
+
- Preprocessing: whitespace and comment normalization before any scoring.
|
|
166
|
+
- Chunking: Chonkie-backed document splitting with per-method options.
|
|
167
|
+
- Vectors: dense single-vector, learned static single-vector, and multivector late interaction.
|
|
168
|
+
- Edit distance: normalized Levenshtein and Jaro-Winkler lexical metrics.
|
|
169
|
+
- Code metrics: built-in CodeBLEU-style metrics and CrystalBLEU.
|
|
170
|
+
- Comparison suite: run multiple configurations, rank them, and optionally write summary/detail artifacts.
|
|
171
|
+
|
|
172
|
+
## CLI
|
|
173
|
+
|
|
174
|
+
Compare a directory or ZIP archive:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
matheel compare codes/ \
|
|
178
|
+
--model sentence-transformers/all-MiniLM-L6-v2 \
|
|
179
|
+
--vector-backend auto \
|
|
180
|
+
--max-token-length 256 \
|
|
181
|
+
--feature-weight semantic=0.6 \
|
|
182
|
+
--feature-weight levenshtein=0.2 \
|
|
183
|
+
--feature-weight jaro_winkler=0.1 \
|
|
184
|
+
--feature-weight code_metric=0.1 \
|
|
185
|
+
--similarity-function dot \
|
|
186
|
+
--pooling-method max \
|
|
187
|
+
--preprocess-mode basic \
|
|
188
|
+
--chunking-method code \
|
|
189
|
+
--chunk-language python \
|
|
190
|
+
--chunker-option include_line_numbers=true \
|
|
191
|
+
--code-metric codebleu \
|
|
192
|
+
--code-language python \
|
|
193
|
+
--threshold 0.5 \
|
|
194
|
+
--num 25
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Run multiple configurations:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
matheel compare-suite codes/ runs.json \
|
|
201
|
+
--summary-out results/summary.csv \
|
|
202
|
+
--details-dir results/runs
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Python API
|
|
206
|
+
|
|
207
|
+
Pairwise scoring:
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from matheel.similarity import calculate_similarity
|
|
211
|
+
|
|
212
|
+
score = calculate_similarity(
|
|
213
|
+
"def add(a, b):\n return a + b\n",
|
|
214
|
+
"def add(x, y):\n return x + y\n",
|
|
215
|
+
model_name="sentence-transformers/all-MiniLM-L6-v2",
|
|
216
|
+
vector_backend="auto",
|
|
217
|
+
max_token_length=256,
|
|
218
|
+
similarity_function="dot",
|
|
219
|
+
pooling_method="max",
|
|
220
|
+
preprocess_mode="basic",
|
|
221
|
+
chunking_method="code",
|
|
222
|
+
chunk_language="python",
|
|
223
|
+
code_metric="codebleu",
|
|
224
|
+
code_language="python",
|
|
225
|
+
feature_weights={"semantic": 0.5, "code_metric": 0.5},
|
|
226
|
+
)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Directory or ZIP ranking:
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
from matheel.similarity import get_sim_list
|
|
233
|
+
|
|
234
|
+
results = get_sim_list(
|
|
235
|
+
"sample_codes",
|
|
236
|
+
model_name="sentence-transformers/all-MiniLM-L6-v2",
|
|
237
|
+
threshold=0.4,
|
|
238
|
+
number_results=50,
|
|
239
|
+
vector_backend="auto",
|
|
240
|
+
max_token_length=256,
|
|
241
|
+
chunking_method="chonkie_token",
|
|
242
|
+
chunk_size=120,
|
|
243
|
+
chunk_overlap=20,
|
|
244
|
+
similarity_function="cosine",
|
|
245
|
+
pooling_method="mean",
|
|
246
|
+
feature_weights={
|
|
247
|
+
"semantic": 0.7,
|
|
248
|
+
"levenshtein": 0.15,
|
|
249
|
+
"jaro_winkler": 0.15,
|
|
250
|
+
},
|
|
251
|
+
)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Hugging Face Routing
|
|
255
|
+
|
|
256
|
+
Matheel can inspect Hugging Face model metadata and route automatically:
|
|
257
|
+
|
|
258
|
+
- `sentence-transformers` models go to the Sentence Transformers path
|
|
259
|
+
- `model2vec` models go to the model2vec static path
|
|
260
|
+
- `PyLate` models go to the multivector late-interaction path
|
|
261
|
+
|
|
262
|
+
If metadata is unavailable, Matheel falls back to simple name and tag heuristics, then defaults to the Sentence Transformers path.
|
|
263
|
+
|
|
264
|
+
## Docs
|
|
265
|
+
|
|
266
|
+
- Docs index: [docs/index.md](docs/index.md)
|
|
267
|
+
- Quick usage: [docs/usage.md](docs/usage.md)
|
|
268
|
+
- Preprocessing: [docs/preprocessing.md](docs/preprocessing.md)
|
|
269
|
+
- Chunking: [docs/chunking.md](docs/chunking.md)
|
|
270
|
+
- Vectors: [docs/vectors.md](docs/vectors.md)
|
|
271
|
+
- Edit distance and feature weights: [docs/lexical.md](docs/lexical.md)
|
|
272
|
+
- Code metrics: [docs/code_metrics.md](docs/code_metrics.md)
|
|
273
|
+
- Comparison suite: [docs/comparison_suite.md](docs/comparison_suite.md)
|
|
274
|
+
|
|
275
|
+
The `docs/` folder is already structured well for a later GitHub Pages setup if you decide to publish the docs site from the repository.
|
|
276
|
+
|
|
277
|
+
## Examples
|
|
278
|
+
|
|
279
|
+
- Quick archive smoke test: [examples/sample_pairs_demo.py](examples/sample_pairs_demo.py)
|
|
280
|
+
- Preprocessing: [examples/preprocessing_demo.py](examples/preprocessing_demo.py)
|
|
281
|
+
- Chunking: [examples/chunking_demo.py](examples/chunking_demo.py)
|
|
282
|
+
- Vector backends: [examples/vectors_demo.py](examples/vectors_demo.py)
|
|
283
|
+
- Edit distance and feature weights: [examples/lexical_demo.py](examples/lexical_demo.py)
|
|
284
|
+
- Code metrics: [examples/code_metrics_demo.py](examples/code_metrics_demo.py)
|
|
285
|
+
- Comparison suite: [examples/comparison_suite_demo.py](examples/comparison_suite_demo.py)
|
|
286
|
+
|
|
287
|
+
## Gradio
|
|
288
|
+
|
|
289
|
+
The Gradio demo stays in `gradio_app/`. The core package and CLI can read either a ZIP archive or a directory. The Gradio upload flow remains ZIP-based.
|
|
290
|
+
|
|
291
|
+
## License
|
|
292
|
+
|
|
293
|
+
This project is licensed under the [Creative Commons Attribution-NonCommercial 4.0 International License](https://creativecommons.org/licenses/by-nc/4.0/).
|
matheel-0.2.2/README.md
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# Matheel
|
|
2
|
+
|
|
3
|
+
Matheel is a simple, function-based Python package and CLI for source-code similarity. It combines semantic embeddings, lexical similarity, chunking, preprocessing, and code-aware metrics without forcing a class-heavy API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Use Python `3.10` to `3.12`.
|
|
8
|
+
|
|
9
|
+
Base install:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install matheel
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Optional extras:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install "matheel[chunking]"
|
|
19
|
+
pip install "matheel[chunking_code]"
|
|
20
|
+
pip install "matheel[model2vec]"
|
|
21
|
+
pip install "matheel[pylate]"
|
|
22
|
+
pip install "matheel[gradio]"
|
|
23
|
+
pip install "matheel[all]"
|
|
24
|
+
pip install "matheel[dev]"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Tested Python 3.12 constraints:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install -c constraints/py312.txt .
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`matheel[all]` installs the currently supported optional backends in one command: Chonkie code chunking, model2vec, PyLate, and the Gradio app dependencies.
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
The repo includes a small Java archive at `sample_pairs.zip` for smoke tests.
|
|
38
|
+
|
|
39
|
+
CLI:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
matheel compare sample_pairs.zip \
|
|
43
|
+
--model sentence-transformers/all-MiniLM-L6-v2 \
|
|
44
|
+
--feature-weight semantic=0.7 \
|
|
45
|
+
--feature-weight levenshtein=0.3 \
|
|
46
|
+
--threshold 0.2 \
|
|
47
|
+
--num 10
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Python:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from matheel.similarity import get_sim_list
|
|
54
|
+
|
|
55
|
+
results = get_sim_list(
|
|
56
|
+
"sample_pairs.zip",
|
|
57
|
+
model_name="sentence-transformers/all-MiniLM-L6-v2",
|
|
58
|
+
threshold=0.2,
|
|
59
|
+
number_results=10,
|
|
60
|
+
feature_weights={
|
|
61
|
+
"semantic": 0.7,
|
|
62
|
+
"levenshtein": 0.3,
|
|
63
|
+
},
|
|
64
|
+
)
|
|
65
|
+
print(results.head())
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Supported Languages
|
|
69
|
+
|
|
70
|
+
- Chunking is language-agnostic by default because it can split any text.
|
|
71
|
+
- `CodeBLEU`-style metrics are intentionally scoped to `Java`, `Python`, `C`, and `C++`.
|
|
72
|
+
- Generic preprocessing works across languages, but code-aware metrics are most defensible in that four-language scope.
|
|
73
|
+
|
|
74
|
+
## Supported Methods
|
|
75
|
+
|
|
76
|
+
Similarity features:
|
|
77
|
+
|
|
78
|
+
- `semantic`
|
|
79
|
+
- `levenshtein`
|
|
80
|
+
- `jaro_winkler`
|
|
81
|
+
- `code_metric`
|
|
82
|
+
|
|
83
|
+
Code metrics:
|
|
84
|
+
|
|
85
|
+
- `codebleu`
|
|
86
|
+
- `codebleu_ngram`
|
|
87
|
+
- `codebleu_weighted_ngram`
|
|
88
|
+
- `codebleu_syntax`
|
|
89
|
+
- `codebleu_dataflow`
|
|
90
|
+
- `crystalbleu`
|
|
91
|
+
|
|
92
|
+
Chunking methods:
|
|
93
|
+
|
|
94
|
+
- `none`
|
|
95
|
+
- Chonkie-backed when installed: `code`, `codechunker`, `chonkie_code`, `chonkie_token`, `chonkie_sentence`, `chonkie_recursive`, `chonkie_fast`
|
|
96
|
+
|
|
97
|
+
Vector backends:
|
|
98
|
+
|
|
99
|
+
- `auto`
|
|
100
|
+
- `sentence_transformers`
|
|
101
|
+
- `model2vec`
|
|
102
|
+
- `pylate`
|
|
103
|
+
|
|
104
|
+
Single-vector similarity functions:
|
|
105
|
+
|
|
106
|
+
- `cosine`
|
|
107
|
+
- `dot`
|
|
108
|
+
- `euclidean`
|
|
109
|
+
- `manhattan`
|
|
110
|
+
|
|
111
|
+
Sentence Transformers pooling methods:
|
|
112
|
+
|
|
113
|
+
- `mean`
|
|
114
|
+
- `max`
|
|
115
|
+
- `cls`
|
|
116
|
+
- `lasttoken`
|
|
117
|
+
- `mean_sqrt_len_tokens`
|
|
118
|
+
- `weightedmean`
|
|
119
|
+
|
|
120
|
+
`auto` inspects Hugging Face model metadata and routes to the correct backend when the model exposes a known library.
|
|
121
|
+
|
|
122
|
+
## Core Parts
|
|
123
|
+
|
|
124
|
+
- Preprocessing: whitespace and comment normalization before any scoring.
|
|
125
|
+
- Chunking: Chonkie-backed document splitting with per-method options.
|
|
126
|
+
- Vectors: dense single-vector, learned static single-vector, and multivector late interaction.
|
|
127
|
+
- Edit distance: normalized Levenshtein and Jaro-Winkler lexical metrics.
|
|
128
|
+
- Code metrics: built-in CodeBLEU-style metrics and CrystalBLEU.
|
|
129
|
+
- Comparison suite: run multiple configurations, rank them, and optionally write summary/detail artifacts.
|
|
130
|
+
|
|
131
|
+
## CLI
|
|
132
|
+
|
|
133
|
+
Compare a directory or ZIP archive:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
matheel compare codes/ \
|
|
137
|
+
--model sentence-transformers/all-MiniLM-L6-v2 \
|
|
138
|
+
--vector-backend auto \
|
|
139
|
+
--max-token-length 256 \
|
|
140
|
+
--feature-weight semantic=0.6 \
|
|
141
|
+
--feature-weight levenshtein=0.2 \
|
|
142
|
+
--feature-weight jaro_winkler=0.1 \
|
|
143
|
+
--feature-weight code_metric=0.1 \
|
|
144
|
+
--similarity-function dot \
|
|
145
|
+
--pooling-method max \
|
|
146
|
+
--preprocess-mode basic \
|
|
147
|
+
--chunking-method code \
|
|
148
|
+
--chunk-language python \
|
|
149
|
+
--chunker-option include_line_numbers=true \
|
|
150
|
+
--code-metric codebleu \
|
|
151
|
+
--code-language python \
|
|
152
|
+
--threshold 0.5 \
|
|
153
|
+
--num 25
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Run multiple configurations:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
matheel compare-suite codes/ runs.json \
|
|
160
|
+
--summary-out results/summary.csv \
|
|
161
|
+
--details-dir results/runs
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Python API
|
|
165
|
+
|
|
166
|
+
Pairwise scoring:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
from matheel.similarity import calculate_similarity
|
|
170
|
+
|
|
171
|
+
score = calculate_similarity(
|
|
172
|
+
"def add(a, b):\n return a + b\n",
|
|
173
|
+
"def add(x, y):\n return x + y\n",
|
|
174
|
+
model_name="sentence-transformers/all-MiniLM-L6-v2",
|
|
175
|
+
vector_backend="auto",
|
|
176
|
+
max_token_length=256,
|
|
177
|
+
similarity_function="dot",
|
|
178
|
+
pooling_method="max",
|
|
179
|
+
preprocess_mode="basic",
|
|
180
|
+
chunking_method="code",
|
|
181
|
+
chunk_language="python",
|
|
182
|
+
code_metric="codebleu",
|
|
183
|
+
code_language="python",
|
|
184
|
+
feature_weights={"semantic": 0.5, "code_metric": 0.5},
|
|
185
|
+
)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Directory or ZIP ranking:
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
from matheel.similarity import get_sim_list
|
|
192
|
+
|
|
193
|
+
results = get_sim_list(
|
|
194
|
+
"sample_codes",
|
|
195
|
+
model_name="sentence-transformers/all-MiniLM-L6-v2",
|
|
196
|
+
threshold=0.4,
|
|
197
|
+
number_results=50,
|
|
198
|
+
vector_backend="auto",
|
|
199
|
+
max_token_length=256,
|
|
200
|
+
chunking_method="chonkie_token",
|
|
201
|
+
chunk_size=120,
|
|
202
|
+
chunk_overlap=20,
|
|
203
|
+
similarity_function="cosine",
|
|
204
|
+
pooling_method="mean",
|
|
205
|
+
feature_weights={
|
|
206
|
+
"semantic": 0.7,
|
|
207
|
+
"levenshtein": 0.15,
|
|
208
|
+
"jaro_winkler": 0.15,
|
|
209
|
+
},
|
|
210
|
+
)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Hugging Face Routing
|
|
214
|
+
|
|
215
|
+
Matheel can inspect Hugging Face model metadata and route automatically:
|
|
216
|
+
|
|
217
|
+
- `sentence-transformers` models go to the Sentence Transformers path
|
|
218
|
+
- `model2vec` models go to the model2vec static path
|
|
219
|
+
- `PyLate` models go to the multivector late-interaction path
|
|
220
|
+
|
|
221
|
+
If metadata is unavailable, Matheel falls back to simple name and tag heuristics, then defaults to the Sentence Transformers path.
|
|
222
|
+
|
|
223
|
+
## Docs
|
|
224
|
+
|
|
225
|
+
- Docs index: [docs/index.md](docs/index.md)
|
|
226
|
+
- Quick usage: [docs/usage.md](docs/usage.md)
|
|
227
|
+
- Preprocessing: [docs/preprocessing.md](docs/preprocessing.md)
|
|
228
|
+
- Chunking: [docs/chunking.md](docs/chunking.md)
|
|
229
|
+
- Vectors: [docs/vectors.md](docs/vectors.md)
|
|
230
|
+
- Edit distance and feature weights: [docs/lexical.md](docs/lexical.md)
|
|
231
|
+
- Code metrics: [docs/code_metrics.md](docs/code_metrics.md)
|
|
232
|
+
- Comparison suite: [docs/comparison_suite.md](docs/comparison_suite.md)
|
|
233
|
+
|
|
234
|
+
The `docs/` folder is already structured well for a later GitHub Pages setup if you decide to publish the docs site from the repository.
|
|
235
|
+
|
|
236
|
+
## Examples
|
|
237
|
+
|
|
238
|
+
- Quick archive smoke test: [examples/sample_pairs_demo.py](examples/sample_pairs_demo.py)
|
|
239
|
+
- Preprocessing: [examples/preprocessing_demo.py](examples/preprocessing_demo.py)
|
|
240
|
+
- Chunking: [examples/chunking_demo.py](examples/chunking_demo.py)
|
|
241
|
+
- Vector backends: [examples/vectors_demo.py](examples/vectors_demo.py)
|
|
242
|
+
- Edit distance and feature weights: [examples/lexical_demo.py](examples/lexical_demo.py)
|
|
243
|
+
- Code metrics: [examples/code_metrics_demo.py](examples/code_metrics_demo.py)
|
|
244
|
+
- Comparison suite: [examples/comparison_suite_demo.py](examples/comparison_suite_demo.py)
|
|
245
|
+
|
|
246
|
+
## Gradio
|
|
247
|
+
|
|
248
|
+
The Gradio demo stays in `gradio_app/`. The core package and CLI can read either a ZIP archive or a directory. The Gradio upload flow remains ZIP-based.
|
|
249
|
+
|
|
250
|
+
## License
|
|
251
|
+
|
|
252
|
+
This project is licensed under the [Creative Commons Attribution-NonCommercial 4.0 International License](https://creativecommons.org/licenses/by-nc/4.0/).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from .chunking import chunk_text
|
|
1
|
+
from .chunking import chunk_text, chunker_parameter_names
|
|
2
2
|
from .comparison_suite import load_run_configs, parse_run_configs, run_comparison_suite
|
|
3
3
|
from .code_metrics import (
|
|
4
4
|
available_code_metric_languages,
|
|
@@ -6,28 +6,40 @@ from .code_metrics import (
|
|
|
6
6
|
codebleu_components,
|
|
7
7
|
score_code_metric_pair,
|
|
8
8
|
)
|
|
9
|
+
from .feature_weights import available_default_features, default_feature_weights, normalize_feature_weights
|
|
10
|
+
from .model_routing import infer_model_backend, infer_model_capabilities, available_vector_backends
|
|
9
11
|
from .preprocessing import preprocess_code
|
|
12
|
+
from .vectors import available_pooling_methods, available_similarity_functions
|
|
10
13
|
from .similarity import (
|
|
11
14
|
available_runtime_devices,
|
|
12
15
|
calculate_similarity,
|
|
13
16
|
detect_default_device,
|
|
14
17
|
get_sim_list,
|
|
18
|
+
inspect_model_settings,
|
|
15
19
|
)
|
|
16
|
-
from .vectors import available_vector_backends
|
|
17
20
|
|
|
18
21
|
__all__ = [
|
|
19
22
|
"available_code_metrics",
|
|
20
23
|
"available_code_metric_languages",
|
|
24
|
+
"available_default_features",
|
|
25
|
+
"available_pooling_methods",
|
|
21
26
|
"available_runtime_devices",
|
|
27
|
+
"available_similarity_functions",
|
|
28
|
+
"available_vector_backends",
|
|
22
29
|
"calculate_similarity",
|
|
23
30
|
"chunk_text",
|
|
31
|
+
"chunker_parameter_names",
|
|
24
32
|
"codebleu_components",
|
|
25
33
|
"get_sim_list",
|
|
34
|
+
"infer_model_backend",
|
|
35
|
+
"infer_model_capabilities",
|
|
36
|
+
"inspect_model_settings",
|
|
26
37
|
"load_run_configs",
|
|
38
|
+
"default_feature_weights",
|
|
39
|
+
"normalize_feature_weights",
|
|
27
40
|
"parse_run_configs",
|
|
28
41
|
"preprocess_code",
|
|
29
42
|
"run_comparison_suite",
|
|
30
43
|
"score_code_metric_pair",
|
|
31
44
|
"detect_default_device",
|
|
32
|
-
"available_vector_backends",
|
|
33
45
|
]
|