liveBook · Manning

Encoder

As explained in Hugging Face in Action

A text encoder is a neural network component that converts textual input into an internal numerical representation.

A text encoder converts textual input into an internal representation. In a transformer, it receives inputs and builds representations that support tasks such as sentence classification and named entity recognition. section 3.1

Figure 3.1 The transformer architecture (Source: “Attention Is All You Need” paper)
A diagram of a software algorithm

Description automatically generated

Use the transformer architecture to locate the encoder alongside the decoder and understand their distinct roles. section 3.1

A transformer encoder combines several processing elements:

  • Input embeddings convert tokens into dense numerical vectors, while positional encodings preserve token order during parallel processing. section 3.1 section 3.4
  • Multiple identical encoder layers use multi-head attention to capture relationships between tokens and feed-forward networks to transform the results. section 3.1
  • Self-attention assigns different importance to words while representing each word, including words separated by long distances. section 3.1 section 3.4

Using a text encoder with CLIP

CLIP uses a transformer-based text encoder and a separate image encoder. A processor receives labels such as cat, dog, tiger, and train alongside an image; the model computes image-text scores, softmax converts them to probabilities, and the highest-scoring label is selected. For the demonstrated dog image, the result is dog. section 6.2.2

How Hugging Face in Action covers it

How deep it goes
Explains encoder inputs, embeddings, positional information, attention, and feed-forward layers at a high level.
Examples
Demonstrates CLIP matching an image against the text labels cat, dog, tiger, and train.
What you can do after
Apply a transformer-based text encoder through CLIP to compare textual labels with visual content.
How it connects
Connects transformers with self-attention, token embeddings, positional encodings, decoders, image encoders, and multimodal models.

Also explained in

Compare how 21 books explain encoder →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hugging Face in Action. The section links point to the parts of the book it draws on.