#52Map a model to its transformer familyEasy

Map a model to its transformer family

Background

The three modern families each descend from a piece of the 2017 transformer:

  • BERT → encoder-only
  • GPT (GPT-2, GPT-3, …) → decoder-only
  • T5 / BART → encoder-decoder

Problem statement

Implement model_family(name) returning the family for a known model name.

Input

  • name — a model name string (e.g. "BERT", "GPT-2", "T5", "BART"), any capitalisation.

Output

Returns one of "encoder-only", "decoder-only", "encoder-decoder":

  • names starting with bert"encoder-only",
  • names starting with gpt"decoder-only",
  • names starting with t5 or bart"encoder-decoder".

Examples

Example 1

Input:  name = "BERT"
Output: "encoder-only"

Example 2

Input:  name = "GPT-2"
Output: "decoder-only"

Constraints

  • Match case-insensitively on the name prefix.
  • Handle bert, gpt, t5, bart.

Notes

  • The family predicts the masking and objective: BERT is bidirectional MLM, GPT is causal next-token, T5 is text-to-text seq2seq.
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.

  • BERT example
  • GPT-2 example
  • T5 reference