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 Conda Version

Installation

  • pip: pip install chinese-whispers
  • Anaconda: conda install -c conda-forge chinese-whispers
  • Mamba: mamba install -c conda-forge chinese-whispers

Usage

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/.

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

Copyright

Copyright (c) 2018–2023 Dmitry Ustalov. See LICENSE for details.

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

chinese_whispers-0.8.2.post2.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chinese_whispers-0.8.2.post2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file chinese_whispers-0.8.2.post2.tar.gz.

File metadata

  • Download URL: chinese_whispers-0.8.2.post2.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for chinese_whispers-0.8.2.post2.tar.gz
Algorithm Hash digest
SHA256 a54e7235795dae199cadb7b94489e77f3cf6331980f6bb8e8439dd732587b1f6
MD5 319bb71add5ac58a3137a6afc37d8efa
BLAKE2b-256 b220df6df4981f937d99934bb18823d646219335ae38e399f09d96bc24f84ff1

See more details on using hashes here.

File details

Details for the file chinese_whispers-0.8.2.post2-py3-none-any.whl.

File metadata

File hashes

Hashes for chinese_whispers-0.8.2.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 9fec02158bbd148b109ed297f8e143ce6b8cdadcfbcbfcbf6a83af698bcd9529
MD5 1d12b33611234a3f68aa46cfd399264a
BLAKE2b-256 4c83d5a27b20bc01f27444d6ff529a665e53d44f1661910196032dce23cca67e

See more details on using hashes here.

Supported by

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