Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

spacy get number of tokens

import spacy

nlp = spacy.load("en_core_web_sm") # or a different available model

s = "This is my beautiful string"

# spaCy counts the number of tokens such as
# words, numbers, puntuation marks etc.
len(nlp(s)) 
>>> 5
 
PREVIOUS NEXT
Tagged: #spacy #number #tokens
ADD COMMENT
Topic
Name
1+9 =