Extracting Noun Phrases with spaCy

  • Share this:

Code introduction


This function uses the spaCy library to extract noun phrases from a given text. It first parses the text using spaCy's nlp object, then iterates over the noun phrase chunks in the document and returns their text representations.


Technology Stack : spaCy

Code Type : Function

Code Difficulty : Intermediate


                
                    
def extract_noun_phrases(text, nlp):
    # Extract noun phrases from the given text using spaCy's pipeline
    doc = nlp(text)
    noun_phrases = [chunk.text for chunk in doc.noun_chunks]
    return noun_phrases                
              
Tags: