0

I would like to use textacy for key term extraction but the function I am using keyterms.key_terms.pagerank(doc) is just returning an empty list.

I have tried related functions including the longer keyterms.key_terms_from_semantic_network(doc) with no success. I have also tried using longer pieces of text than shown below but it still does not find any key terms. Other functions in textacy do seem to work so it seems to be a problem just with the keyterms class.

import spacy
import textacy
test_string = "Textacy key term extraction is not working properly. Textacy is built on top of SpaCy."
doc = textacy.make_spacy_doc(test_string)
textacy.keyterms.textrank(doc)

I am getting an empty list rather than a list of tuples with terms and ranking scores as expected.

liamt12three
  • 57
  • 1
  • 4

2 Answers2

0

This works for me

Note the following additions:

  1. I explicitly imported keyterms in line 2.
  2. I passed the spaCy English model in line 4.
import spacy
from textacy import keyterms

test_string = "Textacy key term extraction is not working properly. Textacy is built on top of SpaCy."
doc = textacy.make_spacy_doc(test_string, lang='en_core_web_sm')
textacy.keyterms.textrank(doc)

Here is the results I got from your example sentence:

[('term', 0.24594541923542018),
 ('textacy', 0.24594541923542018),
 ('extraction', 0.2390545807645797),
 ('key', 0.13452729038228986),
 ('spacy', 0.13452729038228986)]
coderpc
  • 4,119
  • 6
  • 51
  • 93
MZe
  • 148
  • 2
  • 5
0

Here is an example, working with newest version June 2021 :

import spacy
from textacy.extract import keyterms as kt

test_string = "Textacy key term extraction is not working properly. Textacy is built on top of SpaCy."
doc = textacy.make_spacy_doc(test_string, lang='en_core_web_sm')
kt.textrank(doc)
Farzad Amirjavid
  • 649
  • 5
  • 13