Skip to content

Instantly share code, notes, and snippets.

@abhishek-shrm
Last active October 4, 2020 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhishek-shrm/fff81d8e4e34a69280cd06fe2873cb9a to your computer and use it in GitHub Desktop.
Save abhishek-shrm/fff81d8e4e34a69280cd06fe2873cb9a to your computer and use it in GitHub Desktop.
# Function for extracting keyphrases
def extract_keyphrase(text):
# Creating Spacy's Doc object
doc=textacy.make_spacy_doc(text,lang=en)
# Getting top 5 keyphrases from the text
keyphrases=textacy.ke.textrank(doc,normalize='lower',topn=0.33)
return [phrase for phrase,score in keyphrases]
# Extracting keyphrases for abstracts in validation set
df_val['pred_keys']=df_val['abstract'].apply(extract_keyphrase)
df_val.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment