Skip to main content

Python implementation of TextRank for phrase extraction and lightweight summarization of text documents

Project description

PyTextRank

DOI GitHub commit activity Checked with mypy

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

Contributing Code

We welcome people getting involved as contributors to this open source project! Please see the CONTRIBUTING.md file for instructions.

Build Instructions

Note: unless you are contributing code and updates, in 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.

thanks noam

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.4568079},
  url = {https://github.com/DerwenAI/pytextrank}
}

Kudos

Many thanks to our contributors: @louisguitton, @Ankush-Chander, @Lord-V15, @anna-droid-beep, @dvsrepo, @kavorite, @htmartin, @williamsmj, @mattkohl, @vanita5, @HarshGrandeur, @mnowotka, @kjam, @SaiThejeshwar, @laxatives, @dimmu, @JasonZhangzy1757, @jake-aft, @junchen1992, @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


Download files

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

Source Distribution

pytextrank-3.1.0.tar.gz (17.9 kB view hashes)

Uploaded Source

Built Distribution

pytextrank-3.1.0-py3-none-any.whl (21.5 kB view hashes)

Uploaded Python 3

Supported by

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