After training a recurrent network to predict the next word, Elman froze it, ran the corpus through once more and saved the hidden vector produced at every word. Each word occurs in many contexts, so he averaged all hidden vectors produced by the same word into one vector per word and compared those. He then made up a new word, used it everywhere in place of "man", and found that its averaged vector sat next to the vectors of the human nouns. Implement both steps.
Implement type_vectors(hidden, words) and nearest_type(vec, vocab, means, exclude=()).
type_vectors
hidden: array-like of shape , the hidden vector produced at each of word occurrences. words: the words, in the same order.(vocab, means): vocab is the sorted list of distinct words; means is a NumPy array of shape (len(vocab), H) whose row is the average of the hidden vectors of all occurrences of vocab[j].nearest_type
vocab whose row of means has the smallest Euclidean distance to vec, skipping the words in exclude. Ties go to the earlier word in vocab.