#65Which transformer family?EasyTransformers
Which transformer family?
Background
Transformers come in three families, distinguished by which stacks they have:
- Encoder-only (BERT): encoder, no decoder — understanding tasks.
- Decoder-only (GPT): decoder, no encoder — autoregressive generation.
- Encoder-decoder (the 2017 original, T5): both stacks bridged by cross-attention — sequence-to-sequence.
Problem statement
Implement transformer_family(has_encoder, has_decoder) returning the family name.
Input
has_encoder—bool.has_decoder—bool.
Output
Returns one of:
"encoder-only"(encoder, no decoder),"decoder-only"(decoder, no encoder),"encoder-decoder"(both).
Examples
Example 1 — BERT
Input: has_encoder = True, has_decoder = False
Output: "encoder-only"
Example 2 — GPT
Input: has_encoder = False, has_decoder = True
Output: "decoder-only"
Example 3 — original transformer
Input: has_encoder = True, has_decoder = True
Output: "encoder-decoder"
Constraints
- Return the exact family string for each combination.
- (Both
Falsewon't be tested.)
Notes
- The family tells you the masking, the training objective, and the natural task — knowing it up front saves a lot of confusion.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Example 1 - BERT has encoder only
- •Reference - the original transformer has both stacks
- •Sample - GPT has decoder only