Explore Library
Code QuizIntermediate

Building a Vocabulary from a Corpus

Spot why this vocabulary produces non-contiguous, oversized word indices.

Codepython
corpus = ["nlp is fun", "nlp is hard"]
words = []
for sentence in corpus:
    words += sentence.split()
vocab = {word: i for i, word in enumerate(words)}
print(vocab)

What is the bug in this vocabulary-building code?