RAKE: Rapid Automatic Keyword Extraction Algorithm

RAKE: Rapid Automatic Keyword Extraction Algorithm 快速自动提取关键词算法

自然语言处理分析的最基本和初始步骤是关键词提取,因为没有关键词提取,就不可能再进一步。正如我们所知,在NLP中,我们有许多算法可以帮助我们提取文本数据的关键字,但是我们知道最常用的算法吗?

大多数数据科学家和机器学习开发人员使用的一些主要文本处理算法是:

image.png

TF-IDF

TextRank

RAKE

What is the RAKE Algorithm?什么是RAKE算法?

image.png

Rake也称为快速自动关键字提取,是一种非常高效的关键字提取算法,可对单个文档进行操作,以实现对动态集合的应用,也可非常轻松地应用于新域,并且在处理多种类型的文档时也非常有效,尤其是遵循特定语法惯例的文本类型。

Rake是基于这样的观察:关键词经常包含多个带有标准标点符号的单词或停用词,或者我们可以说像“and”、“of”、“the”等具有最低词汇意义的功能词,停用词通常会在所有信息系统中删除,也不会包含在各种文本分析中,因为它们被认为是无意义的。被认为具有与文本相关的含义的词被描述为内容承载词,称为内容词。


image.png

RAKE算法的输入参数包括一个停用词列表,以及一组短语分隔符和单词分隔符。它使用停用词和短语分隔符将文档划分为候选关键字,这些候选关键字主要是帮助开发人员提取从文档中获取信息所需的确切关键字。

  • 使用以下命令安装Rake:
$ git clone [https://github.com/zelandiya/*RAKE*-tutorial](https://github.com/zelandiya/RAKE-tutorial)
# 要在python代码中导入rake:
import rake 
import operator

# 加载文本并对其应用rake:
filepath = "keyword_extraction.txt"
rake_object = rake.Rake(filepath)
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 generatingsets 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 of systems and systems of mixed types."
sample_file = open(“data/docs/fao_test/w2167e.txt”, ‘r’)
text = sample_file.read()
keywords = rake_object.run(text) print “Keywords:”, keywords
  • 候选关键字:

如上所述,我们知道RAKE通过使用停用词和短语分隔符解析文档,将包含主要内容的单词分类为候选关键字。这基本上是通过以下一些步骤来完成的,首先,文档文本被特定的单词分隔符分割成一个单词数组,其次,该数组再次被分割成一个在短语分隔符和停用单词位置的连续单词序列。最后,位于相同序列中的单词被分配到文本中的相同位置,并一起被视为候选关键字。

stopwordpattern = rake.build_stop_word_regex(filepath)
phraseList = rake.generate_candidate_keywords(sentenceList, stopwordpattern)
  • 关键词得分:

从文本数据中识别出所有候选关键字后,将生成单词共现图,该图计算每个候选关键字的分数,并定义为成员单词分数。借助该图,我们根据图中顶点的程度和频率评估了计算单词分数的几个指标。

keywordcandidates = rake.generate_candidate_keyword_scores(phraseList, wordscores)
  • 主要指标如下:
    Word Frequency (freq(w))
    Word Degree (deg(w))
    Ratio of degree to frequency (deg(w)/freq(w))
    (Deg (w)) favors words that occur often and in longer candidates.
    (Freq (w)) favors words that occur frequently regardless of the number of words with which they co-occurred.
    (Deg (w)/ Freq (w) favors the words that predominately occur in longer candidate keywords.

每个候选关键字的最终分数计算为其成员单词分数之和。

  • 相邻关键字:

正如我们所知,Rake通过停用词分割候选关键字,因此提取的关键字不包含内部停用词,因此,将包含内部停用词的关键字识别为邪恶轴是一种兴趣。查找在同一文档中以相同顺序彼此至少相邻两次的关键字。为此,将创建一个新的候选关键字,作为这些关键字和内部停用词的组合。在这一部分中,我们应该理解,只有很少的链接词被提取出来,从而增加了意义。

  • 提取关键词:
    After the candidate keyword score is calculated, the top T candidate keywords are selected from the document. The T value is one-third the number of words in the graph.
    计算候选关键字得分后,将从文档中选择前T个候选关键字。T值是图中字数的三分之一。
totalKeywords = len(sortedKeywords)
for keyword in sortedKeywords[0:(totalKeywords / 3)]: 
      print “Keyword: “, keyword[0], “, score: “, keyword[1]
  • 期望输出:

Keywords: Keywords: [(‘household food security’, 7.711414565826329), (‘indigenous groups living’, 7.4), (‘national forest programmes’, 7.249539170506913), (‘wood forest products’, 6.844777265745007)…
Keyword: minimal generating sets , score: 8.66666666667Keyword: linear diophantine equations , score: 8.5
Keyword: minimal supporting set , score: 7.66666666667
Keyword: minimal set , score: 4.66666666667
Keyword: linear constraints , score: 4.5
Keyword: upper bounds , score: 4.0
Keyword: natural numbers , score: 4.0
Keyword: nonstrict inequations , score: 4.

  • 使用以下命令评估Rake算法:
Precision 4.44 Recall 5.17 F-Measure 4.78

原文需翻墙:

https://medium.datadriveninvestor.com/rake-rapid-automatic-keyword-extraction-algorithm-f4ec17b2886c

你可能感兴趣的:(RAKE: Rapid Automatic Keyword Extraction Algorithm)