# Chinese Whispers for Python
This is an implementation of the [Chinese Whispers](https://doi.org/10.3115/1654758.1654774) clustering algorithm in Python. Since this library is based on [NetworkX](https://networkx.github.io/), it is simple to use.
[![Unit Tests][github_tests_badge]][github_tests_link] [![Read the Docs][rtfd_badge]][rtfd_link] [![PyPI Version][pypi_badge]][pypi_link] [![Conda Version][conda_badge]][conda_link]
[github_tests_badge]: https://github.com/nlpub/chinese-whispers/actions/workflows/test.yml/badge.svg?branch=master
[github_tests_link]: https://github.com/nlpub/chinese-whispers/actions/workflows/test.yml
[rtfd_badge]: https://readthedocs.org/projects/chinese-whispers/badge/
[rtfd_link]: https://chinese-whispers.readthedocs.io/
[pypi_badge]: https://badge.fury.io/py/chinese-whispers.svg
[pypi_link]: https://pypi.python.org/pypi/chinese-whispers
[conda_badge]: https://anaconda.org/conda-forge/chinese-whispers/badges/version.svg
[conda_link]: https://anaconda.org/conda-forge/chinese-whispers
## Installation
- [pip](https://pip.pypa.io/): `pip install chinese-whispers`
- [Anaconda](https://docs.conda.io/en/latest/): `conda install conda-forge::chinese-whispers`
## Usage
Given a NetworkX graph `G`, this library can [cluster](https://en.wikipedia.org/wiki/Cluster_analysis) it using the following code:
```python
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`\t`target`\t`weight).
```shell
# 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](https://github.com/nlpub/chinese-whispers/blob/master/example.ipynb) 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
* [Ustalov, D.](https://github.com/dustalov), [Panchenko, A.](https://github.com/alexanderpanchenko), [Biemann, C.](https://www.inf.uni-hamburg.de/en/inst/ab/lt/people/chris-biemann.html), [Ponzetto, S.P.](https://www.uni-mannheim.de/dws/people/professors/prof-dr-simone-paolo-ponzetto/): [Watset: Local-Global Graph Clustering with Applications in Sense and Frame Induction](https://doi.org/10.1162/COLI_a_00354). Computational Linguistics 45(3), 423–479 (2019)
```bibtex
@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](https://github.com/dustalov). See [LICENSE](LICENSE) for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "chinese-whispers",
"maintainer": null,
"docs_url": null,
"requires_python": "~=3.8",
"maintainer_email": null,
"keywords": "graph clustering, unsupervised learning, chinese whispers, cluster analysis",
"author": "Dmitry Ustalov",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/45/d3/b8d1d6623e6e5042d2b8ed0eb7e4721eacf7d02c195c9680e88601637a2e/chinese_whispers-0.9.0.tar.gz",
"platform": null,
"description": "# Chinese Whispers for Python\n\nThis is an implementation of the [Chinese Whispers](https://doi.org/10.3115/1654758.1654774) clustering algorithm in Python. Since this library is based on [NetworkX](https://networkx.github.io/), it is simple to use.\n\n[![Unit Tests][github_tests_badge]][github_tests_link] [![Read the Docs][rtfd_badge]][rtfd_link] [![PyPI Version][pypi_badge]][pypi_link] [![Conda Version][conda_badge]][conda_link]\n\n[github_tests_badge]: https://github.com/nlpub/chinese-whispers/actions/workflows/test.yml/badge.svg?branch=master\n[github_tests_link]: https://github.com/nlpub/chinese-whispers/actions/workflows/test.yml\n[rtfd_badge]: https://readthedocs.org/projects/chinese-whispers/badge/\n[rtfd_link]: https://chinese-whispers.readthedocs.io/\n[pypi_badge]: https://badge.fury.io/py/chinese-whispers.svg\n[pypi_link]: https://pypi.python.org/pypi/chinese-whispers\n[conda_badge]: https://anaconda.org/conda-forge/chinese-whispers/badges/version.svg\n[conda_link]: https://anaconda.org/conda-forge/chinese-whispers\n\n## Installation\n\n- [pip](https://pip.pypa.io/): `pip install chinese-whispers`\n- [Anaconda](https://docs.conda.io/en/latest/): `conda install conda-forge::chinese-whispers`\n\n## Usage\n\nGiven a NetworkX graph `G`, this library can [cluster](https://en.wikipedia.org/wiki/Cluster_analysis) it using the following code:\n\n```python\nfrom chinese_whispers import chinese_whispers\nchinese_whispers(G, weighting='top', iterations=20)\n```\n\nAs the result, each node of the input graph is provided with the `label` attribute that stores the cluster label.\n\nThe library also offers a convenient command-line interface (CLI) for clustering graphs represented in the ABC tab-separated format (source`\\t`target`\\t`weight).\n\n```shell\n# Write karate_club.tsv (just as example)\npython3 -c 'import networkx as nx; nx.write_weighted_edgelist(nx.karate_club_graph(), \"karate_club.tsv\", delimiter=\"\\t\")'\n\n# Using as CLI\nchinese-whispers karate_club.tsv\n\n# Using as module (same CLI as above)\npython3 -mchinese_whispers karate_club.tsv\n```\n\nA more complete usage example is available in the [example notebook](https://github.com/nlpub/chinese-whispers/blob/master/example.ipynb) and at <https://nlpub.github.io/chinese-whispers/>.\n\nIn case you require higher performance, please consider our Java implementation that also includes other graph clustering algorithms: <https://github.com/nlpub/watset-java>.\n\n## Citation\n\n* [Ustalov, D.](https://github.com/dustalov), [Panchenko, A.](https://github.com/alexanderpanchenko), [Biemann, C.](https://www.inf.uni-hamburg.de/en/inst/ab/lt/people/chris-biemann.html), [Ponzetto, S.P.](https://www.uni-mannheim.de/dws/people/professors/prof-dr-simone-paolo-ponzetto/): [Watset: Local-Global Graph Clustering with Applications in Sense and Frame Induction](https://doi.org/10.1162/COLI_a_00354). Computational Linguistics 45(3), 423–479 (2019)\n\n```bibtex\n@article{Ustalov:19:cl,\n author = {Ustalov, Dmitry and Panchenko, Alexander and Biemann, Chris and Ponzetto, Simone Paolo},\n title = {{Watset: Local-Global Graph Clustering with Applications in Sense and Frame Induction}},\n journal = {Computational Linguistics},\n year = {2019},\n volume = {45},\n number = {3},\n pages = {423--479},\n doi = {10.1162/COLI_a_00354},\n publisher = {MIT Press},\n issn = {0891-2017},\n language = {english},\n}\n```\n\n## Copyright\n\nCopyright (c) 2018–2024 [Dmitry Ustalov](https://github.com/dustalov). See [LICENSE](LICENSE) for details.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "An implementation of the Chinese Whispers clustering algorithm.",
"version": "0.9.0",
"project_urls": {
"Documentation": "https://chinese-whispers.readthedocs.io",
"Download": "https://pypi.org/project/chinese-whispers/#files",
"Homepage": "https://github.com/nlpub/chinese-whispers",
"Repository": "https://github.com/nlpub/chinese-whispers"
},
"split_keywords": [
"graph clustering",
" unsupervised learning",
" chinese whispers",
" cluster analysis"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "755f7a730a71c7845eccab86968e3860f2575b539e278e632dd5e64d437faae3",
"md5": "5b262fdf70fdebcbe11bd2aa7b580772",
"sha256": "da5a4842f991229e4799d7bfa117d3bb320732a08361e1a41b5c29254a80212f"
},
"downloads": -1,
"filename": "chinese_whispers-0.9.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5b262fdf70fdebcbe11bd2aa7b580772",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "~=3.8",
"size": 9595,
"upload_time": "2024-07-28T17:49:01",
"upload_time_iso_8601": "2024-07-28T17:49:01.592152Z",
"url": "https://files.pythonhosted.org/packages/75/5f/7a730a71c7845eccab86968e3860f2575b539e278e632dd5e64d437faae3/chinese_whispers-0.9.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "45d3b8d1d6623e6e5042d2b8ed0eb7e4721eacf7d02c195c9680e88601637a2e",
"md5": "0b71eaf5f09a6efa82c86c0163648a74",
"sha256": "ed63521dec01210c6f0c3e8a6e234aa2dfd6b1fac47872b1ef285bd1b1723704"
},
"downloads": -1,
"filename": "chinese_whispers-0.9.0.tar.gz",
"has_sig": false,
"md5_digest": "0b71eaf5f09a6efa82c86c0163648a74",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "~=3.8",
"size": 10282,
"upload_time": "2024-07-28T17:49:02",
"upload_time_iso_8601": "2024-07-28T17:49:02.914940Z",
"url": "https://files.pythonhosted.org/packages/45/d3/b8d1d6623e6e5042d2b8ed0eb7e4721eacf7d02c195c9680e88601637a2e/chinese_whispers-0.9.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-28 17:49:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "nlpub",
"github_project": "chinese-whispers",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "chinese-whispers"
}