Aan de slagGa gratis aan de slag

Word vectors in spaCy vocabulary

The purpose of word vectors is to allow a computer to understand words. In this exercise, you will practice extracting word vectors for a given list of words.

A list of words is compiled as words. The en_core_web_md model is already imported and available as nlp.

The vocabulary of en_core_web_md model contains 20,000 words. If a word does not exist in the vocabulary, you will not be able to extract its corresponding word vector. In this exercise, for simplicity, it is ensured that all the given words exist in this model's vocabulary.

Deze oefening maakt deel uit van de cursus

Natural Language Processing with spaCy

Cursus bekijken

Oefeninstructies

  • Extract the IDs of all the given words and store them in an ids list.
  • For each ID from ids, store the first ten elements of the word vector in the word_vectors list.
  • Print the first ten elements of the first word vector from word_vectors.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

words = ["like", "love"]

# IDs of all the given words
ids = [nlp.____.____[w] for w in words]

# Store the first ten elements of the word vectors for each word
word_vectors = [nlp.____.____[i][:10] for i in ids]

# Print the first ten elements of the first word vector
print(____[0])
Code bewerken en uitvoeren