how to use spacy lemmatizer to get a word into basic form

后端 未结 5 1321
青春惊慌失措
青春惊慌失措 2021-02-02 08:25

I am new to spacy and I want to use its lemmatizer function, but I don\'t know how to use it, like I into strings of word, which will return the string with the basic form the w

5条回答
  •  佛祖请我去吃肉
    2021-02-02 08:52

    Previous answer is convoluted and can't be edited, so here's a more conventional one.

    # make sure your downloaded the english model with "python -m spacy download en"
    
    import spacy
    nlp = spacy.load('en')
    
    doc = nlp(u"Apples and oranges are similar. Boots and hippos aren't.")
    
    for token in doc:
        print(token, token.lemma, token.lemma_)
    

    Output:

    Apples 6617 apples
    and 512 and
    oranges 7024 orange
    are 536 be
    similar 1447 similar
    . 453 .
    Boots 4622 boot
    and 512 and
    hippos 98365 hippo
    are 536 be
    n't 538 not
    . 453 .
    

    From the official Lighting tour

提交回复
热议问题