semhash 0.1.0__tar.gz → 0.2.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.
Files changed (42) hide show
  1. semhash-0.2.0/.github/workflows/ci.yaml +65 -0
  2. {semhash-0.1.0 → semhash-0.2.0}/Makefile +3 -0
  3. semhash-0.2.0/PKG-INFO +389 -0
  4. semhash-0.2.0/README.md +332 -0
  5. semhash-0.2.0/assets/images/semhash_logo.png +0 -0
  6. semhash-0.1.0/benchmarks/datasets.py → semhash-0.2.0/benchmarks/data.py +1 -1
  7. semhash-0.2.0/benchmarks/results/train_benchmark_results.json +155 -0
  8. semhash-0.2.0/benchmarks/results/train_test_benchmark_results.json +172 -0
  9. {semhash-0.1.0 → semhash-0.2.0}/benchmarks/run_benchmarks.py +50 -48
  10. {semhash-0.1.0 → semhash-0.2.0}/pyproject.toml +3 -2
  11. semhash-0.2.0/semhash/datamodels.py +80 -0
  12. semhash-0.2.0/semhash/index.py +67 -0
  13. semhash-0.2.0/semhash/records.py +41 -0
  14. semhash-0.2.0/semhash/semhash.py +277 -0
  15. {semhash-0.1.0 → semhash-0.2.0}/semhash/utils.py +2 -2
  16. {semhash-0.1.0 → semhash-0.2.0}/semhash/version.py +1 -1
  17. semhash-0.2.0/semhash.egg-info/PKG-INFO +389 -0
  18. {semhash-0.1.0 → semhash-0.2.0}/semhash.egg-info/SOURCES.txt +7 -1
  19. {semhash-0.1.0 → semhash-0.2.0}/semhash.egg-info/requires.txt +3 -2
  20. semhash-0.2.0/tests/conftest.py +14 -0
  21. semhash-0.2.0/tests/test_datamodels.py +95 -0
  22. {semhash-0.1.0 → semhash-0.2.0}/tests/test_semhash.py +48 -42
  23. {semhash-0.1.0 → semhash-0.2.0}/uv.lock +47 -8
  24. semhash-0.1.0/PKG-INFO +0 -277
  25. semhash-0.1.0/README.md +0 -221
  26. semhash-0.1.0/benchmarks/results/train_benchmark_results.json +0 -121
  27. semhash-0.1.0/benchmarks/results/train_test_benchmark_results.json +0 -138
  28. semhash-0.1.0/semhash/semhash.py +0 -185
  29. semhash-0.1.0/semhash.egg-info/PKG-INFO +0 -277
  30. semhash-0.1.0/tests/conftest.py +0 -18
  31. {semhash-0.1.0 → semhash-0.2.0}/.gitignore +0 -0
  32. {semhash-0.1.0 → semhash-0.2.0}/.pre-commit-config.yaml +0 -0
  33. {semhash-0.1.0 → semhash-0.2.0}/LICENSE +0 -0
  34. {semhash-0.1.0 → semhash-0.2.0}/benchmarks/__init__.py +0 -0
  35. {semhash-0.1.0 → semhash-0.2.0}/semhash/__init__.py +0 -0
  36. {semhash-0.1.0 → semhash-0.2.0}/semhash.egg-info/dependency_links.txt +0 -0
  37. {semhash-0.1.0 → semhash-0.2.0}/semhash.egg-info/top_level.txt +0 -0
  38. {semhash-0.1.0 → semhash-0.2.0}/setup.cfg +0 -0
  39. {semhash-0.1.0 → semhash-0.2.0}/tests/data/test_model/README.md +0 -0
  40. {semhash-0.1.0 → semhash-0.2.0}/tests/data/test_model/config.json +0 -0
  41. {semhash-0.1.0 → semhash-0.2.0}/tests/data/test_model/model.safetensors +0 -0
  42. {semhash-0.1.0 → semhash-0.2.0}/tests/data/test_model/tokenizer.json +0 -0
@@ -0,0 +1,65 @@
1
+ name: Run tests and upload coverage
2
+
3
+ on:
4
+ push
5
+
6
+ jobs:
7
+ test:
8
+ name: Run tests with pytest
9
+ runs-on: ${{ matrix.os }}
10
+ strategy:
11
+ matrix:
12
+ os: ["ubuntu-latest", "windows-latest"]
13
+ python-version: ["3.9", "3.10", "3.11", "3.12"]
14
+ exclude:
15
+ - os: windows-latest
16
+ python-version: "3.9"
17
+ - os: windows-latest
18
+ python-version: "3.11"
19
+ - os: windows-latest
20
+ python-version: "3.12"
21
+ fail-fast: false
22
+
23
+ steps:
24
+ - uses: actions/checkout@v4
25
+
26
+ - name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
27
+ uses: actions/setup-python@v5
28
+ with:
29
+ python-version: ${{ matrix.python-version }}
30
+ allow-prereleases: true
31
+
32
+ # Step for Windows: Create and activate a virtual environment
33
+ - name: Create and activate a virtual environment (Windows)
34
+ if: ${{ runner.os == 'Windows' }}
35
+ run: |
36
+ irm https://astral.sh/uv/install.ps1 | iex
37
+ $env:Path = "C:\Users\runneradmin\.local\bin;$env:Path"
38
+ uv venv .venv
39
+ "VIRTUAL_ENV=.venv" | Out-File -FilePath $env:GITHUB_ENV -Append
40
+ "$PWD/.venv/Scripts" | Out-File -FilePath $env:GITHUB_PATH -Append
41
+
42
+ # Step for Unix: Create and activate a virtual environment
43
+ - name: Create and activate a virtual environment (Unix)
44
+ if: ${{ runner.os != 'Windows' }}
45
+ run: |
46
+ curl -LsSf https://astral.sh/uv/install.sh | sh
47
+ uv venv .venv
48
+ echo "VIRTUAL_ENV=.venv" >> $GITHUB_ENV
49
+ echo "$PWD/.venv/bin" >> $GITHUB_PATH
50
+
51
+ # Install dependencies using uv pip
52
+ - name: Install dependencies
53
+ run: make install-no-pre-commit
54
+
55
+ # Run tests with coverage
56
+ - name: Run tests under coverage
57
+ run: |
58
+ coverage run -m pytest
59
+ coverage report
60
+
61
+ # Upload results to Codecov
62
+ - name: Upload results to Codecov
63
+ uses: codecov/codecov-action@v4
64
+ with:
65
+ token: ${{ secrets.CODECOV_TOKEN }}
@@ -8,6 +8,9 @@ install: venv
8
8
  uv sync --all-extras
9
9
  uv run pre-commit install
10
10
 
11
+ install-no-pre-commit:
12
+ uv pip install ".[dev]"
13
+
11
14
  fix:
12
15
  uv run pre-commit run --all-files
13
16
 
semhash-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,389 @@
1
+ Metadata-Version: 2.2
2
+ Name: semhash
3
+ Version: 0.2.0
4
+ Summary: Fast Semantic Text Deduplication
5
+ Author-email: Thomas van Dongen <thomas123@live.nl>, Stéphan Tulkens <stephantul@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 The Minish Lab
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/MinishLab
29
+ Project-URL: Bug Reports, https://github.com/MinishLab/semhash/issues
30
+ Project-URL: Source, https://github.com/MinishLab/semhash
31
+ Classifier: Development Status :: 4 - Beta
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: Intended Audience :: Science/Research
34
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
35
+ Classifier: Topic :: Software Development :: Libraries
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Programming Language :: Python :: 3 :: Only
38
+ Classifier: Programming Language :: Python :: 3.9
39
+ Classifier: Programming Language :: Python :: 3.10
40
+ Classifier: Programming Language :: Python :: 3.11
41
+ Classifier: Programming Language :: Python :: 3.12
42
+ Classifier: Natural Language :: English
43
+ Requires-Python: >=3.9
44
+ Description-Content-Type: text/markdown
45
+ License-File: LICENSE
46
+ Requires-Dist: model2vec>=0.3.4
47
+ Requires-Dist: vicinity[usearch]>=0.4.0
48
+ Requires-Dist: frozendict
49
+ Provides-Extra: dev
50
+ Requires-Dist: black; extra == "dev"
51
+ Requires-Dist: ipython; extra == "dev"
52
+ Requires-Dist: mypy; extra == "dev"
53
+ Requires-Dist: pre-commit; extra == "dev"
54
+ Requires-Dist: pytest; extra == "dev"
55
+ Requires-Dist: pytest-coverage; extra == "dev"
56
+ Requires-Dist: ruff; extra == "dev"
57
+
58
+
59
+
60
+ <div align="center">
61
+ <picture>
62
+ <img width="30%" alt="SemHash logo" src="assets/images/semhash_logo.png">
63
+ </picture>
64
+ </a>
65
+ </div>
66
+
67
+ <div align="center">
68
+
69
+ # Fast Semantic Text Deduplication
70
+
71
+
72
+ <h2>
73
+ <a href="https://pypi.org/project/semhash/"><img src="https://img.shields.io/pypi/v/semhash?color=%23007ec6&label=pypi%20package" alt="Package version"></a>
74
+ <a href="https://pypi.org/project/semhash/"><img src="https://img.shields.io/pypi/pyversions/semhash" alt="Supported Python versions"></a>
75
+ <a href="https://app.codecov.io/gh/MinishLab/semhash">
76
+ <img src="https://codecov.io/gh/MinishLab/semhash/graph/badge.svg?token=YPOD6HD0MG" alt="Codecov">
77
+ </a>
78
+ <a href="https://github.com/MinishLab/semhash/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="License - MIT"></a>
79
+ </h2>
80
+
81
+
82
+ [Quickstart](#quickstart) •
83
+ [Main Features](#main-features) •
84
+ [Usage](#usage) •
85
+ [Benchmarks](#benchmarks)
86
+
87
+ </div>
88
+
89
+
90
+ SemHash is a lightweight and flexible tool for deduplicating datasets using semantic similarity. It combines fast embedding generation from [Model2Vec](https://github.com/MinishLab/model2vec) with efficient ANN-based similarity search through [Vicinity](https://github.com/MinishLab/vicinity).
91
+
92
+ SemHash supports both single-dataset deduplication (e.g., cleaning up a train set) and multi-dataset deduplication (e.g., ensuring no overlap between a test set and a train set). It works with simple datasets, such as text lists, and more complex ones, like multi-column QA datasets. Additionally, it includes functions to inspect deduplication results, making it easier to understand and refine your data cleaning process.
93
+
94
+ ## Quickstart
95
+
96
+ Install the package with:
97
+ ```bash
98
+ pip install semhash
99
+ ```
100
+
101
+ Deduplicate a single dataset with the following code (note: the examples assume you have `datasets` installed, which you can install with `pip install datasets`):
102
+
103
+ ```python
104
+ from datasets import load_dataset
105
+ from semhash import SemHash
106
+
107
+ # Load a dataset to deduplicate
108
+ texts = load_dataset("ag_news", split="train")["text"]
109
+
110
+ # Initialize a SemHash instance
111
+ semhash = SemHash.from_records(records=texts)
112
+
113
+ # Deduplicate the texts
114
+ deduplicated_texts = semhash.self_deduplicate().deduplicated
115
+ ```
116
+
117
+ Or, deduplicate across two datasets with the following code (e.g., eliminating train/test leakage):
118
+
119
+ ```python
120
+ from datasets import load_dataset
121
+ from semhash import SemHash
122
+
123
+ # Load two datasets to deduplicate
124
+ train_texts = load_dataset("ag_news", split="train")["text"]
125
+ test_texts = load_dataset("ag_news", split="test")["text"]
126
+
127
+ # Initialize a SemHash instance with the training data
128
+ semhash = SemHash.from_records(records=train_texts)
129
+
130
+ # Deduplicate the test data against the training data
131
+ deduplicated_test_texts = semhash.deduplicate(records=test_texts).deduplicated
132
+ ```
133
+
134
+ Or, deduplicate multi-column datasets with the following code (e.g., deduplicating a QA dataset):
135
+
136
+ ```python
137
+ from datasets import load_dataset
138
+ from semhash import SemHash
139
+
140
+ # Load the dataset
141
+ dataset = load_dataset("squad_v2", split="train")
142
+
143
+ # Convert the dataset to a list of dictionaries
144
+ records = [dict(row) for row in dataset]
145
+
146
+ # Initialize SemHash with the columns to deduplicate
147
+ semhash = SemHash.from_records(records=records, columns=["question", "context"])
148
+
149
+ # Deduplicate the records
150
+ deduplicated_records = semhash.self_deduplicate().deduplicated
151
+ ```
152
+
153
+ The `deduplicate` and `self_deduplicate` functions return a [DeduplicationResult](https://github.com/MinishLab/semhash/blob/prepare-release/semhash/datamodels.py#L35). This object stores the deduplicated corpus, a set of duplicate objec (along with the objects that caused duplication), and several useful functions to further inspect the deduplication result. Examples of how these functions can be used can be found in the [usage](#usage) section.
154
+
155
+ ## Main Features
156
+
157
+ - **Fast**: SemHash uses [model2vec](https://github.com/MinishLab/model2vec) to embed texts and [vicinity](https://github.com/MinishLab/vicinity) to perform similarity search, making it extremely fast.
158
+ - **Scalable**: SemHash can deduplicate large datasets with millions of records thanks to the ANN backends in Vicinity.
159
+ - **Flexible**: SemHash can be used to deduplicate a single dataset or across two datasets, and can also be used to deduplicate multi-column datasets (such as QA datasets).
160
+ - **Lightweight**: SemHash is a lightweight package with minimal dependencies, making it easy to install and use.
161
+
162
+ ## Usage
163
+
164
+ The following examples show the various ways you can use SemHash to deduplicate datasets. These examples assume you have the `datasets` library installed, which you can install with `pip install datasets`.
165
+
166
+ <details>
167
+ <summary> Deduplicate a single dataset </summary>
168
+ <br>
169
+
170
+ The following code snippet shows how to deduplicate a single dataset using SemHash (in this example, the train split of the [AG News dataset](https://huggingface.co/datasets/fancyzhx/ag_news)):
171
+
172
+ ```python
173
+ from datasets import load_dataset
174
+ from semhash import SemHash
175
+
176
+ # Load a dataset to deduplicate
177
+ texts = load_dataset("ag_news", split="train")["text"]
178
+
179
+ # Initialize a SemHash instance
180
+ semhash = SemHash.from_records(records=texts)
181
+
182
+ # Deduplicate the texts
183
+ deduplicated_texts = semhash.self_deduplicate()
184
+ ```
185
+ </details>
186
+
187
+ <details>
188
+ <summary> Deduplicate across two datasets </summary>
189
+ <br>
190
+
191
+ The following code snippet shows how to deduplicate across two datasets using SemHash (in this example, the train/test split of the [AG News dataset](https://huggingface.co/datasets/fancyzhx/ag_news)):
192
+
193
+ ```python
194
+ from datasets import load_dataset
195
+ from semhash import SemHash
196
+
197
+ # Initialize a SemHash instance
198
+ semhash = SemHash()
199
+
200
+ # Load two datasets to deduplicate
201
+ train_texts = load_dataset("ag_news", split="train")["text"]
202
+ test_texts = load_dataset("ag_news", split="test")["text"]
203
+
204
+ # Initialize a SemHash instance
205
+ semhash = SemHash.from_records(records=train_texts)
206
+
207
+ # Deduplicate the test data against the training data
208
+ deduplicated_test_texts = semhash.deduplicate(records=test_texts)
209
+ ```
210
+
211
+ </details>
212
+
213
+ <details>
214
+ <summary> Deduplicate multi-column datasets </summary>
215
+ <br>
216
+
217
+ The following code snippet shows how to deduplicate multi-column datasets using SemHash (in this example, the train split of the QA dataset [SQuAD 2.0](https://huggingface.co/datasets/rajpurkar/squad_v2), which consists of questions, contexts, and answers):
218
+
219
+ ```python
220
+ from datasets import load_dataset
221
+ from semhash import SemHash
222
+
223
+ # Load the dataset
224
+ dataset = load_dataset("squad_v2", split="train")
225
+
226
+ # Convert the dataset to a list of dictionaries
227
+ records = [dict(row) for row in dataset]
228
+
229
+ # Initialize SemHash with the columns to deduplicate
230
+ semhash = SemHash.from_records(records=records, columns=["question", "context"])
231
+
232
+ # Deduplicate the records
233
+ deduplicated_records = semhash.self_deduplicate().deduplicated
234
+ ```
235
+
236
+ </details>
237
+
238
+ <details>
239
+ <summary> DeduplicationResult functionality </summary>
240
+ <br>
241
+
242
+ The `DeduplicationResult` object returned by the `deduplicate` and `self_deduplicate` functions contains several useful functions to inspect the deduplication result. The following code snippet shows how to use these functions:
243
+
244
+ ```python
245
+ from datasets import load_dataset
246
+ from semhash import SemHash
247
+
248
+ # Load a dataset to deduplicate
249
+ texts = load_dataset("ag_news", split="train")["text"]
250
+
251
+ # Initialize a SemHash instance
252
+ semhash = SemHash.from_records(records=texts)
253
+
254
+ # Deduplicate the texts
255
+ deduplication_result = semhash.self_deduplicate()
256
+
257
+ # Check the deduplicated texts
258
+ deduplication_result.deduplicated
259
+ # Check the duplicates
260
+ deduplication_result.duplicates
261
+ # See what percentage of the texts were duplicates
262
+ deduplication_result.duplicate_ratio
263
+ # See what percentage of the texts were exact duplicates
264
+ deduplication_result.exact_duplicate_ratio
265
+
266
+ # Get the least similar text from the duplicates. This is useful for finding the right threshold for deduplication.
267
+ least_similar = deduplication_result.get_least_similar_from_duplicates()
268
+
269
+ # Rethreshold the duplicates. This allows you to instantly rethreshold the duplicates with a new threshold without having to re-deduplicate the texts.
270
+ deduplication_result.rethreshold(0.95)
271
+ ```
272
+
273
+ </details>
274
+
275
+ <details>
276
+ <summary> Using custom encoders </summary>
277
+ <br>
278
+
279
+ The following code snippet shows how to use a custom encoder with SemHash:
280
+
281
+ ```python
282
+ from datasets import load_dataset
283
+ from model2vec import StaticModel
284
+ from semhash import SemHash
285
+
286
+ # Load a dataset to deduplicate
287
+ texts = load_dataset("ag_news", split="train")["text"]
288
+
289
+ # Load an embedding model (in this example, a multilingual model)
290
+ model = StaticModel.from_pretrained("minishlab/M2V_multilingual_output")
291
+
292
+ # Initialize a SemHash with the model and custom encoder
293
+ semhash = SemHash.from_records(records=texts, model=model)
294
+
295
+ # Deduplicate the texts
296
+ deduplicated_texts = semhash.self_deduplicate()
297
+ ```
298
+
299
+ Any encoder can be used that adheres to our [encoder protocol](https://github.com/MinishLab/semhash/blob/main/semhash/utils.py). For example, any [sentence-transformers](https://github.com/UKPLab/sentence-transformers) model can be used as an encoder:
300
+
301
+ ```python
302
+ from datasets import load_dataset
303
+ from semhash import SemHash
304
+ from sentence_transformers import SentenceTransformer
305
+
306
+ # Load a dataset to deduplicate
307
+ texts = load_dataset("ag_news", split="train")["text"]
308
+
309
+ # Load a sentence-transformers model
310
+ model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
311
+
312
+ # Initialize a SemHash with the model and custom encoder
313
+ semhash = SemHash.from_records(records=texts, model=model)
314
+
315
+ # Deduplicate the texts
316
+ deduplicated_texts = semhash.self_deduplicate()
317
+ ```
318
+
319
+ </details>
320
+
321
+ NOTE: By default, we use the ANN (approximate-nearest neighbors) backend for deduplication. We recommend keeping this since the recall for smaller datasets is ~100%, and it's needed for larger datasets (>1M samples) since these will take too long to deduplicate without ANN. If you want to use the flat/exact-matching backend, you can set `use_ann=False` in the SemHash constructor:
322
+
323
+ ```python
324
+ semhash = SemHash.from_records(records=texts, use_ann=False)
325
+ ```
326
+
327
+ ## Benchmarks
328
+
329
+ We've benchmarked SemHash on a variety of datasets to measure the deduplication performance and speed. The benchmarks were run with the following setup:
330
+ - The benchmarks were all run on CPU
331
+ - The benchmarks were all run with `use_ann=True`
332
+ - The used encoder is the default encoder ([potion-base-8M](https://huggingface.co/minishlab/potion-base-8M)).
333
+ - The timings include the encoding time, index building time, and deduplication time.
334
+ ### Train Deduplication Benchmark
335
+
336
+ | Dataset | Original Train Size | Deduplicated Train Size | % Removed | Deduplication Time (s) |
337
+ |----------------------|----------------------|--------------------------|------------|--------------------------|
338
+ | bbc | 1225 | 1144 | 6.61 | 0.57 |
339
+ | senteval_cr | 3012 | 2990 | 0.73 | 0.14 |
340
+ | tweet_sentiment_extraction | 27481 | 26695 | 2.86 | 1.77 |
341
+ | emotion | 16000 | 15695 | 1.91 | 0.77 |
342
+ | amazon_counterfactual | 5000 | 4992 | 0.16 | 0.33 |
343
+ | ag_news | 120000 | 106921 | 10.90 | 5.20 |
344
+ | enron_spam | 31716 | 20540 | 35.24 | 2.03 |
345
+ | subj | 8000 | 7990 | 0.12 | 0.63 |
346
+ | sst5 | 8544 | 8526 | 0.21 | 0.58 |
347
+ | 20_newgroups | 11314 | 10684 | 5.57 | 0.73 |
348
+ | hatespeech_offensive | 22783 | 22090 | 3.04 | 0.92 |
349
+ | ade | 17637 | 15718 | 10.88 | 0.73 |
350
+ | imdb | 25000 | 24830 | 0.68 | 1.76 |
351
+ | massive_scenario | 11514 | 9366 | 18.66 | 0.47 |
352
+ | student | 117519 | 63856 | 45.66 | 8.80 |
353
+ | squad_v2 | 130319 | 109698 | 15.82 | 8.81 |
354
+ | wikitext | 1801350 | 884645 | 50.89 | 83.53 |
355
+
356
+
357
+ ### Train/Test Deduplication Benchmark
358
+
359
+ | Dataset | Train Size | Test Size | Deduplicated Test Size | % Removed | Deduplication Time (s) |
360
+ |----------------------|--------------|--------------|--------------------------|------------|--------------------------|
361
+ | bbc | 1225 | 1000 | 870 | 13.00 | 0.71 |
362
+ | senteval_cr | 3012 | 753 | 750 | 0.40 | 0.13 |
363
+ | tweet_sentiment_extraction | 27481 | 3534 | 3412 | 3.45 | 1.53 |
364
+ | emotion | 16000 | 2000 | 1926 | 3.70 | 0.65 |
365
+ | amazon_counterfactual | 5000 | 5000 | 4990 | 0.20 | 0.51 |
366
+ | ag_news | 120000 | 7600 | 6198 | 18.45 | 3.74 |
367
+ | enron_spam | 31716 | 2000 | 1060 | 47.00 | 1.94 |
368
+ | subj | 8000 | 2000 | 1999 | 0.05 | 0.62 |
369
+ | sst5 | 8544 | 2210 | 2205 | 0.23 | 0.59 |
370
+ | 20_newgroups | 11314 | 7532 | 7098 | 5.76 | 2.25 |
371
+ | hatespeech_offensive | 22783 | 2000 | 1925 | 3.75 | 0.77 |
372
+ | ade | 17637 | 5879 | 4952 | 15.77 | 0.81 |
373
+ | imdb | 25000 | 25000 | 24795 | 0.82 | 2.81 |
374
+ | massive_scenario | 11514 | 2974 | 2190 | 26.36 | 0.46 |
375
+ | student | 117519 | 5000 | 2393 | 52.14 | 3.78 |
376
+ | squad_v2 | 130319 | 11873 | 11863 | 0.08 | 7.13 |
377
+ | wikitext | 1801350 | 4358 | 2139 | 50.92 | 40.32 |
378
+
379
+
380
+ As can be seen, SemHash is extremely fast, and scales to large datasets with millions of records. There are some notable examples of train/test leakage, such as `enron_spam` and `student`, where the test dataset contains a significant amount of semantic overlap with the training dataset.
381
+
382
+ ### Reproducing the Benchmarks
383
+
384
+ To run the benchmarks yourself, you can use the following command (assuming you have the `datasets` library installed):
385
+
386
+ ```bash
387
+ python -m benchmarks.run_benchmarks
388
+ ```
389
+ Optionally, the datasets can be updated in the [datasets.py](https://github.com/MinishLab/semhash/blob/main/benchmarks/datasets.py) file.