Extracting Noun Phrases with spaCy

  • Share this:

Code introduction


This function uses the spaCy library to analyze the input text and extract all noun phrases. It first loads the English model, then processes the text with this model, and finally extracts the noun phrases from the processed document.


Technology Stack : spaCy

Code Type : Function

Code Difficulty : Intermediate


                
                    
import spacy
from spacy.lang.en import English

def find_noun_phrases(text):
    # Load English tokenizer, tagger, parser, NER and word vectors
    nlp = English()
    
    # Process whole documents
    doc = nlp(text)
    
    # Extract noun phrases
    noun_phrases = [chunk.text for chunk in doc.noun_chunks]
    
    return noun_phrases                
              
Tags: