Menu

1 / 5

Text embeddings and cosine similarity

DEV Community: datascience·Abdul Wahab·about 18 hours ago
#ZKw91hz2
Reading 0:00
15s threshold

Text embeddings represent sentences as vectors; cosine similarity compares their directions to find related candidates. A high score still needs checking against the task. For example, "I forgot my password" and "How can I reset my login?" use different words to ask about a similar problem.

Give each sentence a list of numbers

An embedding is a vector: an ordered list of numbers that represents an item. For text, a trained model produces that list from a word, sentence, or passage. The geometry of these vectors can capture useful relationships for a task. Google's introduction to embedding spaces .

Picture a map of help articles. Password-reset instructions and login troubleshooting might sit near one another. A recipe for banana bread should be somewhere else. The map is an analogy for comparing those representations.

The model learns its representation during training. You do not usually assign one coordinate to "password" and another to "bread." Real embeddings have many dimensions.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.