Extract Noun Phrases with spaCy NLP

  • Share this:

Code introduction


This function uses spaCy's nlp processor to tokenize and perform syntactic analysis on the input text, then extracts the noun phrases from it. Noun phrases typically consist of multiple words that describe a noun or pronoun and its modifiers.


Technology Stack : spaCy

Code Type : Function

Code Difficulty : Intermediate


                
                    
def extract_noun_phrases(text, nlp):
    """
    Extracts noun phrases from a given text using spaCy's noun phrase chunking.

    Args:
        text (str): The input text from which to extract noun phrases.
        nlp: The spaCy language processor.

    Returns:
        list: A list of noun phrases extracted from the text.
    """
    doc = nlp(text)
    noun_phrases = [chunk.text for chunk in doc.noun_chunks]
    return noun_phrases                
              
Tags: