Skip to main content

Chinese Whispers for Python

This is an implementation of the Chinese Whispers clustering algorithm in Python. Since this library is based on NetworkX, it is simple to use.

Unit Tests Read the Docs PyPI Version

Given a NetworkX graph G, this library can cluster it using the following code:

from chinese_whispers import chinese_whispers
chinese_whispers(G, weighting='top', iterations=20)

As the result, each node of the input graph is provided with the label attribute that stores the cluster label.

The library also offers a convenient command-line interface (CLI) for clustering graphs represented in the ABC tab-separated format (source\ttarget\tweight).

# Write karate_club.tsv (just as example)
python3 -c 'import networkx as nx; nx.write_weighted_edgelist(nx.karate_club_graph(), "karate_club.tsv", delimiter="\t")'

# Using as CLI
chinese-whispers karate_club.tsv

# Using as module (same CLI as above)
python3 -mchinese_whispers karate_club.tsv

A more complete usage example is available in the example notebook and at https://nlpub.github.io/chinese-whispers-python/.

In case you require higher performance, please consider our Java implementation that also includes other graph clustering algorithms: https://github.com/nlpub/watset-java.

Citation

@article{Ustalov:19:cl,
  author    = {Ustalov, Dmitry and Panchenko, Alexander and Biemann, Chris and Ponzetto, Simone Paolo},
  title     = {{Watset: Local-Global Graph Clustering with Applications in Sense and Frame Induction}},
  journal   = {Computational Linguistics},
  year      = {2019},
  volume    = {45},
  number    = {3},
  pages     = {423--479},
  doi       = {10.1162/COLI_a_00354},
  publisher = {MIT Press},
  issn      = {0891-2017},
  language  = {english},
}

Metadata

Release files for chinese-whispers 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chinese-whispers 0.8.0
File Size Uploaded
chinese_whispers-0.8.0.tar.gz 6.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chinese-whispers 0.8.0
File Interpreter ABI Platform
chinese_whispers-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / chinese_whispers-0.8.0.tar.gz

Download URL chinese_whispers-0.8.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0112f5d8cd01bc09564f2b40803c21ef51f27f064b4f234ef97c4dbf09869c53
BLAKE2b-256 checksum
How to use checksums
570a8149887e41c2146a577b6db9141cba36e6926a19bd19903d6025abb53541
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

Release files / chinese_whispers-0.8.0-py3-none-any.whl

Download URL chinese_whispers-0.8.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1031bfbeceed9e36eeef182e40fde7ec0bbcf0aab5dc8c6b1122f26ae0d77782
BLAKE2b-256 checksum
How to use checksums
91a7d9f14650423e0e88126886660dbdcbe134ad064d32ca51432494da9bd56e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page