How to split a text into individual words using spaCy

Here is how you split text into individual words in spaCy:

import spacy

nlp = spacy.load('en_core_web_sm')
doc = nlp('This is the first sentence. And this is the second sentence.')
for tok in doc:
    print(tok.text)

You first need to download and install the en_core_web_sm model to run the above code.

And this is the output:

This
is
the
first
sentence
.
And
this
is
the
second
sentence
.

Similar Posts

Leave a Reply