Replace or Retrieve Keywords In Documents at Scale

Vikash Singh
10/31/2017
43 citations
cs.DS

Official code: vi3k6i5/flashtext (5,711 stars, Python, MIT, last commit 2025-04-13).

Abstract

In this paper we introduce, the FlashText algorithm for replacing keywords or finding keywords in a given text. FlashText can search or replace keywords in one pass over a document.

Show full abstract

The time complexity of this algorithm is not dependent on the number of terms being searched or replaced. For a document of size N (characters) and a dictionary of M keywords, the time complexity will be O(N). This algorithm is much faster than Regex, because regex time complexity is O(MxN). It is also different from Aho Corasick Algorithm, as it doesn't match substrings. FlashText is designed to only match complete words (words with boundary characters on both sides). For an input dictionary of {Apple}, this algorithm won't match it to 'I like Pineapple'. This algorithm is also designed to go for the longest match first. For an input dictionary {Machine, Learning, Machine learning} on a string 'I like Machine learning', it will only consider the longest match, which is Machine Learning. We have made python implementation of this algorithm available as open-source on GitHub, released under the permissive MIT License.

View on arXivView PDF

Code Implementations(1)

vi3k6i5/flashtextOfficial100%
MIT

Extract Keywords from sentence or Replace keywords in sentences.

5,711595PythonAug 15, 20171 years agoMIT
data-extractionkeyword-extractionnlpsearch-in-textword2vec

Similar Papers

Cite this paper

@article{singh2017replace,
  title  = {Replace or Retrieve Keywords In Documents at Scale},
  author = {Vikash Singh},
  year   = {2017},
  eprint = {1711.00046},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/1711.00046}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/1711.00046.svg)](https://codeofpaper.com/paper/1711.00046)

Discussion