kex

Kex is a python library for unsupervised keyword extraction from a document, providing an easy interface and benchmarks on 15 public datasets.

https://github.com/asahi417/kex

Science Score: 20.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
    1 of 3 committers (33.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.2%) to scientific vocabulary

Keywords

information-retrieval keyword-extraction nlp-machine-learning
Last synced: 11 months ago · JSON representation

Repository

Kex is a python library for unsupervised keyword extraction from a document, providing an easy interface and benchmarks on 15 public datasets.

Basic Info
Statistics
  • Stars: 54
  • Watchers: 3
  • Forks: 4
  • Open Issues: 1
  • Releases: 0
Topics
information-retrieval keyword-extraction nlp-machine-learning
Created almost 6 years ago · Last pushed over 4 years ago
Metadata Files
Readme License

README.md

license PyPI version PyPI pyversions PyPI status

KEX

Kex is a python library for unsurpervised keyword extractions, supporting the following features: - Easy interface for keyword extraction with a variety of algorithms - Quick benchmarking over 15 English public datasets - Custom keyword extractor implementation support

Our paper got accepted by EMNLP 2021 main conference 🎉 (camera-ready is here):
This paper has proposed three new algorithms (LexSpec, LexRank, TFIDFRank) and conducted an extensive comparison/analysis over existing keyword extraction algorithms with the proposed methods. Our algorithms are very simple and fast to compute yet established very strong baseline across the dataset (the best MRR/Precision@5 in the average over all the datasets). The TFIDFRank is based on the SingleRank algorithm but with the TFIDF as the population term and the LexSpec and LexRank are based on the lexical specificity where we write a short introduction to lexical specificity here as it is less popular than TFIDF. To reproduce all the results in the paper, please follow these instructions.

Get Started

Install via pip shell script pip install kex

Extract Keywords with Kex

Built-in algorithms in kex is below: - FirstN: heuristic baseline to pick up first n phrases as keywords - TF: scoring by term frequency - TextRank: Mihalcea et al., 04 - SingleRank: Wan et al., 08 - TopicalPageRank: Liu et al.,10 - SingleTPR: Sterckx et al.,15 - TopicRank: Bougouin et al.,13 - PositionRank: Florescu et al.,18 - TFIDF: Ushio et al., 21 - TFIDFRank: Ushio et al., 21 - LexSpec: Ushio et al., 21 - LexRank: Ushio et al., 21

Basic usage:

```python

import kex model = kex.SingleRank() # any algorithm listed above sample = ''' We propose a novel unsupervised keyphrase extraction approach that filters candidate keywords using outlier detection. It starts by training word embeddings on the target document to capture semantic regularities among the words. It then uses the minimum covariance determinant estimator to model the distribution of non-keyphrase word vectors, under the assumption that these vectors come from the same distribution, indicative of their irrelevance to the semantics expressed by the dimensions of the learned vector representation. Candidate keyphrases only consist of words that are detected as outliers of this dominant distribution. Empirical results show that our approach outperforms state of-the-art and recent unsupervised keyphrase extraction methods. ''' model.getkeywords(sample, nkeywords=2) [{'stemmed': 'non-keyphras word vector', 'pos': 'ADJ NOUN NOUN', 'raw': ['non-keyphrase word vectors'], 'offset': [[47, 49]], 'count': 1, 'score': 0.06874471825637762, 'nsourcetokens': 112}, {'stemmed': 'semant regular word', 'pos': 'ADJ NOUN NOUN', 'raw': ['semantic regularities words'], 'offset': [[28, 32]], 'count': 1, 'score': 0.06001468574146248, 'nsourcetokens': 112}] ```

Compute a statistical prior

Algorithms such as TF, TFIDF, TFIDFRank, LexSpec, LexRank, TopicalPageRank, and SingleTPR need to compute a prior distribution beforehand by ```python

import kex model = kex.SingleTPR() testsentences = ['documentA', 'documentB', 'documentC'] model.train(testsentences, export_directory='./tmp') ```

Priors are cached and can be loaded on the fly as ```python

import kex model = kex.SingleTPR() model.load('./tmp') ```

Supported language

Currently algorithms are available only in English, but soon we will relax the constrain to allow other language to be supported.

Benchmark on 15 Public Datasets

Users can fetch 15 public keyword extraction datasets via kex.get_benchmark_dataset.

```python

import kex jsonline, language = kex.getbenchmarkdataset('Inspec') jsonline[0] { 'keywords': ['kind infer', 'type check', 'overload', 'nonstrict pure function program languag', ...], 'source': 'A static semantics for Haskell\nThis paper gives a static semantics for Haskell 98, a non-strict ...', 'id': '1053.txt' } ```

Please take a look an example script to run a benchmark on those datasets.

Implement Custom Extractor with Kex

We provide an API to run a basic pipeline for preprocessing, by which one can implement a custom keyword extractor.

```python import kex

class CustomExtractor: """ Custom keyword extractor example: First N keywords extractor """

def __init__(self, maximum_word_number: int = 3):
    """ First N keywords extractor """
    self.phrase_constructor = kex.PhraseConstructor(maximum_word_number=maximum_word_number)

def get_keywords(self, document: str, n_keywords: int = 10):
    """ Get keywords

     Parameter
    ------------------
    document: str
    n_keywords: int

     Return
    ------------------
    a list of dictionary consisting of 'stemmed', 'pos', 'raw', 'offset', 'count'.
    eg) {'stemmed': 'grid comput', 'pos': 'ADJ NOUN', 'raw': ['grid computing'], 'offset': [[11, 12]], 'count': 1}
    """
    phrase_instance, stemmed_tokens = self.phrase_constructor.tokenize_and_stem_and_phrase(document)
    sorted_phrases = sorted(phrase_instance.values(), key=lambda x: x['offset'][0][0])
    return sorted_phrases[:min(len(sorted_phrases), n_keywords)]

```

Reference paper

If you use any of these resources, please cite the following paper: @inproceedings{ushio-etal-2021-kex, title={{B}ack to the {B}asics: {A} {Q}uantitative {A}nalysis of {S}tatistical and {G}raph-{B}ased {T}erm {W}eighting {S}chemes for {K}eyword {E}xtraction}, author={Ushio, Asahi and Liberatore, Federico and Camacho-Collados, Jose}, booktitle={Proceedings of the {EMNLP} 2021 Main Conference}, year = {2021}, publisher={Association for Computational Linguistics} }

Owner

  • Name: Asahi Ushio
  • Login: asahi417
  • Kind: user
  • Location: Tokyo, Japan

PhD student at Cardiff University 🇬🇧 🏴󠁧󠁢󠁷󠁬󠁳󠁿 * NLP * Language Model * Art *

GitHub Events

Total
  • Watch event: 1
Last Year
  • Watch event: 1

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 122
  • Total Committers: 3
  • Avg Commits per committer: 40.667
  • Development Distribution Score (DDS): 0.246
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
asahi417 a****o@g****m 92
asahi417 s****k@g****m 25
Jose Camacho-Collados c****j@c****k 5
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 5
  • Total pull requests: 0
  • Average time to close issues: 3 months
  • Average time to close pull requests: N/A
  • Total issue authors: 2
  • Total pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • asahi417 (4)
  • BrandonKMLee (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 21 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 5
  • Total maintainers: 1
pypi.org: kex

Light/easy keyword extraction from documents.

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 21 Last month
Rankings
Stargazers count: 9.4%
Dependent packages count: 10.0%
Forks count: 13.3%
Average: 17.3%
Dependent repos count: 21.7%
Downloads: 31.9%
Maintainers (1)
Last synced: 11 months ago

Dependencies

setup.py pypi
  • gensim >=3.4.0,<3.5.0
  • networkx *
  • nltk ==3.5
  • numpy >=1.16.1
  • requests *
  • segtok *