Giter Site home page Giter Site logo

nlpub / chinese-whispers Goto Github PK

View Code? Open in Web Editor NEW
57.0 6.0 13.0 608 KB

An implementation of Chinese Whispers in Python.

Home Page: https://chinese-whispers.readthedocs.io

License: MIT License

Python 71.98% Jupyter Notebook 28.02%
clustering chinese-whispers graph networkx graph-clustering python

chinese-whispers's Introduction

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โ€“2024 Dmitry Ustalov. See LICENSE for details.

chinese-whispers's People

Contributors

3wille avatar achambers8472 avatar alexanderpanchenko avatar dependabot[bot] avatar dustalov avatar flppgg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

chinese-whispers's Issues

Question about the algorithm

Hello,

I have a question about the Chinese Whisper (CW) algorithm. How does it differ from the Label Propagation Algorithm (LPA)? which is implemented by NetworkX.

When should I use CW? and when LPA?

I'm working on a paper about community detection. and I appreciate the help.

Recieving error 'Graph' object has no attribute 'node'

I am working on a nlp project, and I used the chinese-whispers package. But I encountered this error:

File "/home/usr/.local/lib/python3.6/site-packages/chinese_whispers/init.py", line 44, in chinese_whispers
G.node[node]['label'] = i + 1
AttributeError: 'Graph' object has no attribute 'node'

Conda forge package

Would it be possible to install chinese-whispers through anaconda? Perhaps through conda-forge?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.