Extract Noun Phrases with spaCy

  • Share this:

Code introduction


This function uses the spaCy library to extract noun phrases from a text. It takes a text and a spaCy nlp object as input and returns a list of all noun phrases.


Technology Stack : spaCy

Code Type : The type of code

Code Difficulty : Intermediate


                
                    
def extract_noun_phrases(text, nlp):
    doc = nlp(text)
    noun_phrases = [token.text for token in doc if token.pos_ == "NOUN" or token.dep_ == "compound"]
    return noun_phrases                
              
Tags: