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.

