Python implementation of TextRank for phrase extraction and lightweight summarization of text documents
Project description
PyTextRank
PyTextRank is a Python implementation of TextRank as a spaCy pipeline extension, for graph-based natural language work (with related knowledge graph practices) which gets used to:
- extract the top-ranked phrases from a text document
- run low-cost extractive summarization of a text document
- help infer links from unstructured text into more structured representation
Documentation: https://derwen.ai/docs/ptr/
Getting Started
See the "Getting Started" section of the online documentation.
To install from PyPi:
pip install pytextrank
python -m spacy download en_core_web_sm
If you work directly from this Git repo, be sure to install the dependencies as well:
pip install -r requirements.txt
Then to use the library with a simple use case:
import spacy
import pytextrank
# example text
text = "Compatibility of systems of linear constraints over the set of natural numbers. Criteria of compatibility of a system of linear Diophantine equations, strict inequations, and nonstrict inequations are considered. Upper bounds for components of a minimal set of solutions and algorithms of construction of minimal generating sets of solutions for all types of systems are given. These criteria and the corresponding algorithms for constructing a minimal supporting set of solutions can be used in solving all the considered types systems and systems of mixed types."
# load a spaCy model, depending on language, scale, etc.
nlp = spacy.load("en_core_web_sm")
# add PyTextRank to the spaCy pipeline
nlp.add_pipe("textrank", last=True)
doc = nlp(text)
# examine the top-ranked phrases in the document
for p in doc._.phrases:
print("{:.4f} {:5d} {}".format(p.rank, p.count, p.text))
print(p.chunks)
See the tutorial notebooks in the examples
subdirectory for
sample code and patterns to use in integrating pytextrank with
related libraries in Python:
https://derwen.ai/docs/ptr/tutorial/
Semantic Versioning
Generally speaking the major release number of pytextrank will
track with the major release number of the associated spaCy
version.
We try to minimize any breaking changes between releases and provide
careful notes in the changelog.txt
file.
Build Instructions
Note: most use cases won't need to build this package locally. Instead, simply install from PyPi or Conda.
To set up the build environment locally, see the "Build Instructions" section of the online documentation.
License and Copyright
Source code for PyTextRank plus its logo, documentation, and examples have an MIT license which is succinct and simplifies use in commercial applications.
All materials herein are Copyright © 2016-2021 Derwen, Inc.
Attribution
Please use the following BibTeX entry for citing PyTextRank if you use it in your research or software. Citations are helpful for the continued development and maintenance of this library.
@software{PyTextRank,
author = {Paco Nathan},
title = {{PyTextRank, a Python implementation of TextRank for phrase extraction and summarization of text documents}},
year = 2016,
publisher = {Derwen},
doi = {10.5281/zenodo.4540784},
url = {https://github.com/DerwenAI/pytextrank}
}
DOI: https://doi.org/10.5281/zenodo.4540784
Kudos
Many thanks to our contributors: @louisguitton, @Lord-V15, @anna-droid-beep, @kavorite, @htmartin, @williamsmj, @mattkohl, @vanita5, @HarshGrandeur, @mnowotka, @kjam, @dvsrepo, @SaiThejeshwar, @laxatives, @dimmu, @JasonZhangzy1757, @jake-aft, @junchen1992, @Ankush-Chander, @shyamcody, @chikubee, outstanding NLP research work led by @mihalcea, encouragement from the wonderful folks at Explosion who develop spaCy, plus general support from Derwen, Inc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytextrank-3.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 171127843c926ba711061e7c267c9fe208025edea00b0329a7e569451df10d03 |
|
MD5 | 1951aa8c76099ae639ecfd664dcbd4b7 |
|
BLAKE2b-256 | ca668763d571e7b0c858f8eec543bb1c3d22fa8b7e5b9ce1dcc0a760a6dcad1a |