Extract Noun Phrases with spaCy

  • Share this:

Code introduction


This function uses the spaCy library to extract noun phrases from a given text. It first processes the text using spaCy's NLP pipeline and then extracts and returns the noun phrases from the text.


Technology Stack : spaCy

Code Type : Function

Code Difficulty : Intermediate


                
                    
def extract_noun_phrases(text, nlp):
    """
    Extract noun phrases from a given text using spaCy's NLP pipeline.

    Parameters:
    text (str): The input text to process.
    nlp: The spaCy language processing object.

    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: