Analogy querying answers relationship-based questions by combining word vectors arithmetically. Instead of searching for “Who is to nuclear physics what Louis Pasteur is to germs?”, subtract the known relationship and add the target domain. section 6.2.3 section 6.2
For example, calculate `wv['Louis_Pasteur'] - wv['germs'] + wv['physics']`. The result usually is not an existing vocabulary vector, so retrieve the nearest vector and read its associated word as the answer. section 6.2.3 section 6.3.1
A practical analogy-querying workflow is:
- Express the question as a relationship: Portland Timbers + Seattle − Portland. section 6.3.1
- Add and subtract the corresponding Word2Vec vectors in a continuous, often hundreds-dimensional space. section 6.3.1
- Find the vocabulary vector closest to the resultant rather than expecting exact equality. section 6.3.1
- Treat relationships as corpus-dependent: a model can expose cultural or economic similarities, but also reproduce training-data biases and stereotypes. section 6.4.5
Cities and teams
The expression `Portland Timbers + Seattle − Portland` should approach `Seattle Sounders`, because the model represents Portland Timbers and Seattle Sounders as similarly directed displacements from their cities. A related visualization adds state vectors to city vectors, then projects the resulting 300-dimensional representations into two dimensions with PCA. section 6.3.1 section 6.4.5
>>> answer_vector = wv['Louis_Pasteur'] - wv['germs'] + wv['physics']
Inspect the minimal Python expression that turns an analogy into vector arithmetic. section 6.2.3
