Skip to main content

An implementation of the Chinese Whispers clustering algorithm.

Project description

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

In case you require higher performance, please consider our Java implementation that also includes other graph clustering algorithms:


  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},

Project details

Download files

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

Files for chinese-whispers, version 0.7.5
Filename, size File type Python version Upload date Hashes
Filename, size chinese_whispers-0.7.5-py3-none-any.whl (7.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size chinese_whispers-0.7.5.tar.gz (6.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page