The sentence-transformers library is a high-level wrapper for the transformers package. It includes a simplified interface for generating embeddings from sentences, as well as fine-tuning according to several metrics.

Using sentence-transformers with task-specific heads

I’ll explore the case of a classifier here, because it’s what I was trying to do when I wrote this, but my conclusions apply to whatever task head you want.

In a pinch, you could use it to get a decent classifier by first fine-tuning it on labeled data and then feeding those embeddings into a separate classifier. However, this approach does not allow you to fine-tune the classifier and the embedding model together. Additionally, sentence-transformers does not natively support any classification loss functions (which makes sense, since it can’t actually classify).

The best/only option native to sentence-transformers, other than defining a “custom” loss function, is contrastive loss functions, which are kind of an indirect way to get at a classification goal. It lets you specify a “custom” loss, but by the time you’re getting that far in the weeds, it’s become a leaky abstraction; ditch it and use the underlying framework.

In general, if you have the time, you should go ahead and use transformers directly. View sentence-transformers as a half-measure between AutoML and directly fine-tuning a pretrained model.