pauli
pauli

Reputation: 4291

How to get all words from spacy vocab?

I need all the words from Spacy vocab. Suppose, I initialize my spacy model as

nlp = spacy.load('en')

How do I get the text of words from nlp.vocab?

Upvotes: 19

Views: 14106

Answers (2)

tyrex
tyrex

Reputation: 8869

As of spaCy v3.0, we need to run

python -m spacy download en_core_web_sm

and then e.g.

import spacy
nlp = spacy.load("en_core_web_sm")
words = set(nlp.vocab.strings)
word = 'would'
print(f"Is '{word}' an English word: {word in words}")  # True

Upvotes: 8

David
David

Reputation: 775

You can get it as a list like this:

list(nlp.vocab.strings)

Upvotes: 35

Related Questions