def ner(text,nlp):
    """
        Function to perform Named Entity Recognition 
        to split the possible words into different categories
        depending on output label of the NER.

        Arguments:
            text: the input text corpus
            nlp: spacy english language model object
        
        Returns:
            A dictionary containing list of words belonging
            to each category of NER (used to generate distractors)

    """
    doc=nlp(text)
    categories={}
    ## doc.ents returns a tuple of named entities in the text
    ## has a label for each text which can be a word or a phrase
    for ent in doc.ents:
        ## do not consider large phrase
        if(len(str(ent.text).split())>4):
            continue
        ## add the phrase/word in the categories dictionary
        if(ent.label_ in categories):
            categories[ent.label_].add(ent.text)
        else:
            categories[ent.label_]={ent.text}
    return categories