Skip to main content

sequential Information Bottleneck

Project description

sequential Information Bottleneck (sIB)

GitHub Actions CI status

Scope

This project provides an efficient implementation of the text clustering algorithm "sequential Information Bottleneck" (sIB), introduced by Slonim, Friedman and Tishby (2002). The project is packaged as a python library with a cython-wrapped C++ extension for the partition optimization code. A pure python implementation is included as well. The implementation is documented here.

Installation

pip install sib-clustering

Usage

The main class in this library is SIB, which implements the clustering interface of SciKit Learn, providing methods such as fit(), fit_transform(), fit_predict(), etc.

The sample code below clusters the 18.8K documents of the 20-News-Groups dataset into 20 clusters:

import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.datasets import fetch_20newsgroups
from sklearn import metrics
from sib import SIB

# read the dataset
dataset = fetch_20newsgroups(subset='all', categories=None,
                             shuffle=True, random_state=256)

gold_labels = dataset.target
n_clusters = np.unique(gold_labels).shape[0]

# create count vectors using the 10K most frequent words
vectorizer = CountVectorizer(max_features=10000)
X = vectorizer.fit_transform(dataset.data)

# SIB initialization and clustering; parameters:
# perform 10 random initializations (n_init=10); the best one is returned.
# up to 15 optimization iterations in each initialization (max_iter=15)
# use all cores in the running machine for parallel execution (n_jobs=-1)
sib = SIB(n_clusters=n_clusters, random_state=128, n_init=10,
          n_jobs=-1, max_iter=15, verbose=True)
sib.fit(X)

# report standard clustering metrics
print("Homogeneity: %0.3f" % metrics.homogeneity_score(gold_labels, sib.labels_))
print("Completeness: %0.3f" % metrics.completeness_score(gold_labels, sib.labels_))
print("V-measure: %0.3f" % metrics.v_measure_score(gold_labels, sib.labels_))
print("Adjusted Rand-Index: %.3f" % metrics.adjusted_rand_score(gold_labels, sib.labels_))

Expected result:

sIB information stats on best partition:
	I(T;Y) = 0.5685, H(T) = 4.1987
	I(T;Y)/I(X;Y) = 0.1468
	H(T)/H(X) = 0.2956
Homogeneity: 0.616
Completeness: 0.633
V-measure: 0.624
Adjusted Rand-Index: 0.507

See the Examples directory for more illustrations and a comparison against K-Means.

License

Copyright IBM Corporation 2020

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

If you would like to see the detailed LICENSE click here.

Authors

If you have any questions or issues you can create a new issue here.

Reference

N. Slonim, N. Friedman, and N. Tishby (2002). Unsupervised Document Classification using Sequential Information Maximization. SIGIR 2002. https://dl.acm.org/doi/abs/10.1145/564376.564401

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sib-clustering-0.2.4.tar.gz (185.9 kB view hashes)

Uploaded Source

Built Distributions

sib_clustering-0.2.4-cp311-cp311-win_amd64.whl (266.9 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

sib_clustering-0.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (771.7 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

sib_clustering-0.2.4-cp311-cp311-macosx_11_0_arm64.whl (274.3 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

sib_clustering-0.2.4-cp311-cp311-macosx_10_9_x86_64.whl (281.6 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

sib_clustering-0.2.4-cp311-cp311-macosx_10_9_universal2.whl (383.0 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

sib_clustering-0.2.4-cp310-cp310-win_amd64.whl (266.4 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

sib_clustering-0.2.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (731.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

sib_clustering-0.2.4-cp310-cp310-macosx_11_0_arm64.whl (273.8 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

sib_clustering-0.2.4-cp310-cp310-macosx_10_9_x86_64.whl (281.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

sib_clustering-0.2.4-cp310-cp310-macosx_10_9_universal2.whl (382.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

sib_clustering-0.2.4-cp39-cp39-win_amd64.whl (267.0 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

sib_clustering-0.2.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (734.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

sib_clustering-0.2.4-cp39-cp39-macosx_11_0_arm64.whl (274.9 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

sib_clustering-0.2.4-cp39-cp39-macosx_10_9_x86_64.whl (281.6 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

sib_clustering-0.2.4-cp39-cp39-macosx_10_9_universal2.whl (383.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

sib_clustering-0.2.4-cp38-cp38-win_amd64.whl (267.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

sib_clustering-0.2.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (738.8 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

sib_clustering-0.2.4-cp38-cp38-macosx_11_0_arm64.whl (274.8 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

sib_clustering-0.2.4-cp38-cp38-macosx_10_9_x86_64.whl (281.6 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

sib_clustering-0.2.4-cp38-cp38-macosx_10_9_universal2.whl (383.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page