clusterizer 0.7.1__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.
- clusterizer-0.7.1/PKG-INFO +144 -0
- clusterizer-0.7.1/README.md +126 -0
- clusterizer-0.7.1/aladeen_clusterizer/ClusteringPipeline.py +712 -0
- clusterizer-0.7.1/aladeen_clusterizer/DailyClusteringPipeline.py +106 -0
- clusterizer-0.7.1/aladeen_clusterizer/MultiSentClusteringPipeline.py +49 -0
- clusterizer-0.7.1/aladeen_clusterizer/__init__.py +49 -0
- clusterizer-0.7.1/aladeen_clusterizer/abstract/ClusterScorer.py +10 -0
- clusterizer-0.7.1/aladeen_clusterizer/abstract/ClusteringAlgorithm.py +8 -0
- clusterizer-0.7.1/aladeen_clusterizer/abstract/DataPreprocessor.py +7 -0
- clusterizer-0.7.1/aladeen_clusterizer/abstract/DimensionalityReducer.py +35 -0
- clusterizer-0.7.1/aladeen_clusterizer/abstract/EmbeddingGenerator.py +9 -0
- clusterizer-0.7.1/aladeen_clusterizer/abstract/OutlierDetector.py +17 -0
- clusterizer-0.7.1/aladeen_clusterizer/abstract/__init__.py +0 -0
- clusterizer-0.7.1/aladeen_clusterizer/cluster_scorers/CosineSimililarityClusterScorer.py +31 -0
- clusterizer-0.7.1/aladeen_clusterizer/cluster_scorers/SilhouetteClusterScorer.py +16 -0
- clusterizer-0.7.1/aladeen_clusterizer/cluster_scorers/__init__.py +0 -0
- clusterizer-0.7.1/aladeen_clusterizer/clustering_algorithms/HDBSCANClustering.py +300 -0
- clusterizer-0.7.1/aladeen_clusterizer/clustering_algorithms/KMeansClustering.py +15 -0
- clusterizer-0.7.1/aladeen_clusterizer/clustering_algorithms/__init__.py +0 -0
- clusterizer-0.7.1/aladeen_clusterizer/embedding_generators/DirectModelEmbeddingGenerator.py +17 -0
- clusterizer-0.7.1/aladeen_clusterizer/embedding_generators/SentenceTransformerEmbeddingGenerator.py +27 -0
- clusterizer-0.7.1/aladeen_clusterizer/embedding_generators/__init__.py +8 -0
- clusterizer-0.7.1/aladeen_clusterizer/factory.py +146 -0
- clusterizer-0.7.1/aladeen_clusterizer/misc/BenchmarkUtils.py +124 -0
- clusterizer-0.7.1/aladeen_clusterizer/misc/EmbeddingTimestamper.py +21 -0
- clusterizer-0.7.1/aladeen_clusterizer/misc/TextPreprocessor.py +20 -0
- clusterizer-0.7.1/aladeen_clusterizer/misc/__init__.py +0 -0
- clusterizer-0.7.1/aladeen_clusterizer/outlier_detectors/DynamicZScoreOutlierDetector.py +53 -0
- clusterizer-0.7.1/aladeen_clusterizer/outlier_detectors/IQROutlierDetector.py +60 -0
- clusterizer-0.7.1/aladeen_clusterizer/outlier_detectors/LOFOutlierDetector.py +47 -0
- clusterizer-0.7.1/aladeen_clusterizer/outlier_detectors/StandardDeviationOutlierDetector.py +27 -0
- clusterizer-0.7.1/aladeen_clusterizer/outlier_detectors/ZScoreOutlierDetector.py +37 -0
- clusterizer-0.7.1/aladeen_clusterizer/outlier_detectors/__init__.py +0 -0
- clusterizer-0.7.1/aladeen_clusterizer/result_visualizers/MultiResultVisualizer.py +65 -0
- clusterizer-0.7.1/aladeen_clusterizer/result_visualizers/ResultVisualizer.py +179 -0
- clusterizer-0.7.1/aladeen_clusterizer/result_visualizers/__init__.py +0 -0
- clusterizer-0.7.1/clusterizer.egg-info/PKG-INFO +144 -0
- clusterizer-0.7.1/clusterizer.egg-info/SOURCES.txt +42 -0
- clusterizer-0.7.1/clusterizer.egg-info/dependency_links.txt +1 -0
- clusterizer-0.7.1/clusterizer.egg-info/requires.txt +10 -0
- clusterizer-0.7.1/clusterizer.egg-info/top_level.txt +1 -0
- clusterizer-0.7.1/pyproject.toml +48 -0
- clusterizer-0.7.1/setup.cfg +4 -0
- clusterizer-0.7.1/tests/test_smoke.py +182 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: clusterizer
|
|
3
|
+
Version: 0.7.1
|
|
4
|
+
Summary: A package for clustering news articles
|
|
5
|
+
Author-email: Alexandre Amiredjibi <alexamirejibi@gmail.com>, Irakli Janiashvili <irakli.janiashvili@gmail.com>
|
|
6
|
+
Requires-Python: <4.0,>=3.12
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: pandas<4,>=3.1.1
|
|
9
|
+
Requires-Dist: torch
|
|
10
|
+
Requires-Dist: hdbscan<1.0.0,>=0.8.40
|
|
11
|
+
Requires-Dist: scikit-learn<2.0.0,>=1.6.0
|
|
12
|
+
Requires-Dist: sentence-transformers<7,>=6.2.0
|
|
13
|
+
Requires-Dist: umap-learn<1.0.0,>=0.5.7
|
|
14
|
+
Requires-Dist: tqdm<5.0.0,>=4.67.1
|
|
15
|
+
Requires-Dist: transformers<6,>=5.22.2
|
|
16
|
+
Requires-Dist: huggingface-hub<3,>=2.4.0
|
|
17
|
+
Requires-Dist: numba>=0.68.1
|
|
18
|
+
|
|
19
|
+
# clusterizer
|
|
20
|
+
|
|
21
|
+
News clustering with embeddings, HDBSCAN and cosine item scores. Version 0.7.1
|
|
22
|
+
requires Python 3.12+ and pandas 3.1.1+.
|
|
23
|
+
|
|
24
|
+
The PyPI distribution name is `clusterizer`; the Python import namespace remains
|
|
25
|
+
`aladeen_clusterizer` for compatibility. Moving a project into the `aladeen` PyPI
|
|
26
|
+
organization changes ownership, not its global distribution name.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
Install the released distribution into a uv project:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
uv add 'clusterizer==0.7.1'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
This package does not require the Temporal application or its workspace to
|
|
37
|
+
install. Runtime dependencies are declared in the wheel metadata. The old
|
|
38
|
+
`aladeen-clusterizer` distribution and its published history remain separate;
|
|
39
|
+
do not install both names into one environment, because they provide the same
|
|
40
|
+
Python modules. Remove the old dependency when migrating.
|
|
41
|
+
|
|
42
|
+
## Builder interface
|
|
43
|
+
|
|
44
|
+
For a DataFrame `frame` with `uuid`, `title`, `content` and `created_at` columns:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from aladeen_clusterizer.ClusteringPipeline import (
|
|
48
|
+
ClusteringConfig,
|
|
49
|
+
ClusteringPipelineBuilder,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
config = ClusteringConfig(model_name="bge-m3", outlier_threshold=0.6)
|
|
53
|
+
pipeline = ClusteringPipelineBuilder().with_config(config).build()
|
|
54
|
+
result = pipeline.run(
|
|
55
|
+
frame,
|
|
56
|
+
text_col="title",
|
|
57
|
+
uuid_col="uuid",
|
|
58
|
+
title_col="title",
|
|
59
|
+
content_col="content",
|
|
60
|
+
datetime_col="created_at",
|
|
61
|
+
)
|
|
62
|
+
clusters = result["clusters"]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The cached embedding adapter requires an existing, trusted
|
|
66
|
+
`MODELS_CACHE_DIR/bge-m3` directory. Set that location before constructing the
|
|
67
|
+
pipeline. Missing models fail locally; loading uses `local_files_only=True` and
|
|
68
|
+
`trust_remote_code=False`. This example does not download or set up a model.
|
|
69
|
+
|
|
70
|
+
Applications can explicitly configure the HDBSCAN algorithm, item scorer and
|
|
71
|
+
outlier detector through the builder. Final item scores use final cluster
|
|
72
|
+
memberships and exclude self-similarity.
|
|
73
|
+
|
|
74
|
+
## Migration from the last aladeen-clusterizer PyPI release (0.6.3)
|
|
75
|
+
|
|
76
|
+
- Change the distribution dependency from `aladeen-clusterizer` to `clusterizer`.
|
|
77
|
+
Existing `aladeen_clusterizer` imports stay unchanged. Distribution metadata
|
|
78
|
+
lookups should use `importlib.metadata.version("clusterizer")`.
|
|
79
|
+
- The old `ClusteringPipeline(...).run(data, embeddings=None,
|
|
80
|
+
process_embeddings=True)` interface is not the builder API in 0.7.x. Use
|
|
81
|
+
`ClusteringPipelineBuilder` and pass the column names to `run`, as above.
|
|
82
|
+
An explicit embedding generator can be injected through the builder.
|
|
83
|
+
- Python 3.12+, pandas 3, sentence-transformers 6 and Transformers 5 are required.
|
|
84
|
+
- The old `huggingface-hub[cli]` dependency extra is no longer requested.
|
|
85
|
+
Optional SQL/demo/lint tools remain in the separate development group.
|
|
86
|
+
- Final cluster scoring preserves per-item positions and excludes self-similarity.
|
|
87
|
+
- The cached loader disables model-provided Python and implicit model downloads.
|
|
88
|
+
The explicit direct-model embedding adapter is a separate API, not a promise
|
|
89
|
+
that all embedding adapters are offline.
|
|
90
|
+
|
|
91
|
+
## Development and offline smoke test
|
|
92
|
+
|
|
93
|
+
The project uses uv and a checked-in `uv.lock`. `.python-version` selects Python
|
|
94
|
+
3.12.16; `UV_PYTHON` can select an already-installed interpreter, including the
|
|
95
|
+
application's prebuilt Nix interpreter. No existing application environment is
|
|
96
|
+
needed. From this repository:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
uv sync --frozen --no-dev --no-editable
|
|
100
|
+
HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 CUDA_VISIBLE_DEVICES='' \
|
|
101
|
+
uv run --frozen --no-dev --no-editable python -I -B -m unittest discover -s tests -p 'test_smoke.py'
|
|
102
|
+
uv build --no-sources
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`--no-editable` makes this an installed-package smoke, rather than an import from
|
|
106
|
+
an editable source checkout. The tests use owned vectors and real HDBSCAN/cosine
|
|
107
|
+
scoring, plus real UMAP reduction through the public builder. They check finite
|
|
108
|
+
reduced data and preserved item identities, not a stochastic UMAP layout oracle.
|
|
109
|
+
They need no model weights, database or GPU. Python-level socket calls
|
|
110
|
+
are denied during tests; remote execution also needs an outer network/resource
|
|
111
|
+
sandbox. The optional dev group retains the original SQL/demo/lint tools and is
|
|
112
|
+
not needed for this test or published runtime. Installing that group includes
|
|
113
|
+
`psycopg2`, which can require PostgreSQL headers and a compiler.
|
|
114
|
+
|
|
115
|
+
### Linux x86_64 CPU profile
|
|
116
|
+
|
|
117
|
+
This repository's uv configuration selects torch from the explicit official
|
|
118
|
+
PyTorch CPU index on Linux x86_64. The frozen standalone lock therefore does not
|
|
119
|
+
select the default PyPI CUDA stack for that target. Other platforms keep their
|
|
120
|
+
normal PyPI torch source. This is a CPU development/test profile, not GPU
|
|
121
|
+
production validation.
|
|
122
|
+
|
|
123
|
+
A wheel's `Requires-Dist` does not carry uv source configuration. Consumers that
|
|
124
|
+
want the same CPU profile must also configure it in their own project:
|
|
125
|
+
|
|
126
|
+
```toml
|
|
127
|
+
[tool.uv.sources]
|
|
128
|
+
torch = [{ index = "pytorch-cpu", marker = "sys_platform == 'linux' and platform_machine == 'x86_64'" }]
|
|
129
|
+
|
|
130
|
+
[[tool.uv.index]]
|
|
131
|
+
name = "pytorch-cpu"
|
|
132
|
+
url = "https://download.pytorch.org/whl/cpu"
|
|
133
|
+
explicit = true
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Without that choice, a normal Linux PyPI resolution can download CUDA dependencies
|
|
137
|
+
even on a machine without a GPU. Owned packages still come from PyPI; the torch
|
|
138
|
+
CPU wheel comes from the official PyTorch index, with its source/hash in the lock.
|
|
139
|
+
|
|
140
|
+
The Temporal integration has additional offline local-encoder regressions. Tiny
|
|
141
|
+
smokes do not cover every legacy interface, including `DailyClusteringPipeline`
|
|
142
|
+
and hyperparameter tuning. Real pretrained inference, production data, Linux/GPU
|
|
143
|
+
deployment and full application compatibility need separate validation; a smoke
|
|
144
|
+
pass is not rollout clearance.
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# clusterizer
|
|
2
|
+
|
|
3
|
+
News clustering with embeddings, HDBSCAN and cosine item scores. Version 0.7.1
|
|
4
|
+
requires Python 3.12+ and pandas 3.1.1+.
|
|
5
|
+
|
|
6
|
+
The PyPI distribution name is `clusterizer`; the Python import namespace remains
|
|
7
|
+
`aladeen_clusterizer` for compatibility. Moving a project into the `aladeen` PyPI
|
|
8
|
+
organization changes ownership, not its global distribution name.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
Install the released distribution into a uv project:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
uv add 'clusterizer==0.7.1'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
This package does not require the Temporal application or its workspace to
|
|
19
|
+
install. Runtime dependencies are declared in the wheel metadata. The old
|
|
20
|
+
`aladeen-clusterizer` distribution and its published history remain separate;
|
|
21
|
+
do not install both names into one environment, because they provide the same
|
|
22
|
+
Python modules. Remove the old dependency when migrating.
|
|
23
|
+
|
|
24
|
+
## Builder interface
|
|
25
|
+
|
|
26
|
+
For a DataFrame `frame` with `uuid`, `title`, `content` and `created_at` columns:
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from aladeen_clusterizer.ClusteringPipeline import (
|
|
30
|
+
ClusteringConfig,
|
|
31
|
+
ClusteringPipelineBuilder,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
config = ClusteringConfig(model_name="bge-m3", outlier_threshold=0.6)
|
|
35
|
+
pipeline = ClusteringPipelineBuilder().with_config(config).build()
|
|
36
|
+
result = pipeline.run(
|
|
37
|
+
frame,
|
|
38
|
+
text_col="title",
|
|
39
|
+
uuid_col="uuid",
|
|
40
|
+
title_col="title",
|
|
41
|
+
content_col="content",
|
|
42
|
+
datetime_col="created_at",
|
|
43
|
+
)
|
|
44
|
+
clusters = result["clusters"]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The cached embedding adapter requires an existing, trusted
|
|
48
|
+
`MODELS_CACHE_DIR/bge-m3` directory. Set that location before constructing the
|
|
49
|
+
pipeline. Missing models fail locally; loading uses `local_files_only=True` and
|
|
50
|
+
`trust_remote_code=False`. This example does not download or set up a model.
|
|
51
|
+
|
|
52
|
+
Applications can explicitly configure the HDBSCAN algorithm, item scorer and
|
|
53
|
+
outlier detector through the builder. Final item scores use final cluster
|
|
54
|
+
memberships and exclude self-similarity.
|
|
55
|
+
|
|
56
|
+
## Migration from the last aladeen-clusterizer PyPI release (0.6.3)
|
|
57
|
+
|
|
58
|
+
- Change the distribution dependency from `aladeen-clusterizer` to `clusterizer`.
|
|
59
|
+
Existing `aladeen_clusterizer` imports stay unchanged. Distribution metadata
|
|
60
|
+
lookups should use `importlib.metadata.version("clusterizer")`.
|
|
61
|
+
- The old `ClusteringPipeline(...).run(data, embeddings=None,
|
|
62
|
+
process_embeddings=True)` interface is not the builder API in 0.7.x. Use
|
|
63
|
+
`ClusteringPipelineBuilder` and pass the column names to `run`, as above.
|
|
64
|
+
An explicit embedding generator can be injected through the builder.
|
|
65
|
+
- Python 3.12+, pandas 3, sentence-transformers 6 and Transformers 5 are required.
|
|
66
|
+
- The old `huggingface-hub[cli]` dependency extra is no longer requested.
|
|
67
|
+
Optional SQL/demo/lint tools remain in the separate development group.
|
|
68
|
+
- Final cluster scoring preserves per-item positions and excludes self-similarity.
|
|
69
|
+
- The cached loader disables model-provided Python and implicit model downloads.
|
|
70
|
+
The explicit direct-model embedding adapter is a separate API, not a promise
|
|
71
|
+
that all embedding adapters are offline.
|
|
72
|
+
|
|
73
|
+
## Development and offline smoke test
|
|
74
|
+
|
|
75
|
+
The project uses uv and a checked-in `uv.lock`. `.python-version` selects Python
|
|
76
|
+
3.12.16; `UV_PYTHON` can select an already-installed interpreter, including the
|
|
77
|
+
application's prebuilt Nix interpreter. No existing application environment is
|
|
78
|
+
needed. From this repository:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
uv sync --frozen --no-dev --no-editable
|
|
82
|
+
HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 CUDA_VISIBLE_DEVICES='' \
|
|
83
|
+
uv run --frozen --no-dev --no-editable python -I -B -m unittest discover -s tests -p 'test_smoke.py'
|
|
84
|
+
uv build --no-sources
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`--no-editable` makes this an installed-package smoke, rather than an import from
|
|
88
|
+
an editable source checkout. The tests use owned vectors and real HDBSCAN/cosine
|
|
89
|
+
scoring, plus real UMAP reduction through the public builder. They check finite
|
|
90
|
+
reduced data and preserved item identities, not a stochastic UMAP layout oracle.
|
|
91
|
+
They need no model weights, database or GPU. Python-level socket calls
|
|
92
|
+
are denied during tests; remote execution also needs an outer network/resource
|
|
93
|
+
sandbox. The optional dev group retains the original SQL/demo/lint tools and is
|
|
94
|
+
not needed for this test or published runtime. Installing that group includes
|
|
95
|
+
`psycopg2`, which can require PostgreSQL headers and a compiler.
|
|
96
|
+
|
|
97
|
+
### Linux x86_64 CPU profile
|
|
98
|
+
|
|
99
|
+
This repository's uv configuration selects torch from the explicit official
|
|
100
|
+
PyTorch CPU index on Linux x86_64. The frozen standalone lock therefore does not
|
|
101
|
+
select the default PyPI CUDA stack for that target. Other platforms keep their
|
|
102
|
+
normal PyPI torch source. This is a CPU development/test profile, not GPU
|
|
103
|
+
production validation.
|
|
104
|
+
|
|
105
|
+
A wheel's `Requires-Dist` does not carry uv source configuration. Consumers that
|
|
106
|
+
want the same CPU profile must also configure it in their own project:
|
|
107
|
+
|
|
108
|
+
```toml
|
|
109
|
+
[tool.uv.sources]
|
|
110
|
+
torch = [{ index = "pytorch-cpu", marker = "sys_platform == 'linux' and platform_machine == 'x86_64'" }]
|
|
111
|
+
|
|
112
|
+
[[tool.uv.index]]
|
|
113
|
+
name = "pytorch-cpu"
|
|
114
|
+
url = "https://download.pytorch.org/whl/cpu"
|
|
115
|
+
explicit = true
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Without that choice, a normal Linux PyPI resolution can download CUDA dependencies
|
|
119
|
+
even on a machine without a GPU. Owned packages still come from PyPI; the torch
|
|
120
|
+
CPU wheel comes from the official PyTorch index, with its source/hash in the lock.
|
|
121
|
+
|
|
122
|
+
The Temporal integration has additional offline local-encoder regressions. Tiny
|
|
123
|
+
smokes do not cover every legacy interface, including `DailyClusteringPipeline`
|
|
124
|
+
and hyperparameter tuning. Real pretrained inference, production data, Linux/GPU
|
|
125
|
+
deployment and full application compatibility need separate validation; a smoke
|
|
126
|
+
pass is not rollout clearance.
|