liveBook · Manning

Sentence-transformers

As explained in AI-Powered Search

Sentence Transformers is a software library and collection of models for computing semantically meaningful vector representations of sentences and other text.

Sentence Transformers computes semantically meaningful vector representations for sentences and other text. It pools token embeddings into one sentence vector, then uses similarity-oriented training so semantically related sentences occupy nearby positions in vector space. section 13.4.3

Listing 13.5 Loading the RoBERTa SentenceTransformer model
from sentence_transformers import SentenceTransformer
transformer = SentenceTransformer("roberta-base-nli-stsb-mean-tokens")

Load the Python library and a pretrained RoBERTa-based model with SentenceTransformer. section 13.4.3

Encoding and ranking phrases

Encode phrases such as “it's raining hard” and “it is wet outside” into four 768-dimensional embeddings. Normalize them, calculate pairwise dot-product similarities, and sort the results: the two weather phrases rank most similar, while unrelated vehicle phrases score lower.

How AI-Powered Search covers it

How deep it goes
Explains pooling, training, embeddings, normalization, similarity calculation, and ranking, but defers detailed model architecture.
Examples
Uses weather and vehicle phrases, 768-dimensional embeddings, normalized vectors, pairwise scores, and a sorted similarity table.
What you can do after
Build it with Python by loading a pretrained model, encoding phrases, computing similarities, and ranking related text.
How it connects
Connects semantic search with BERT, RoBERTa, natural language inference, embeddings, vector space, and similarity ranking.

Also explained in

Compare how 2 books explain sentence-transformers →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Search. The section links point to the parts of the book it draws on.