Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Fix Transformer Bugs and Recycle as Classifier
00:00
5 left

Fix Transformer Bugs and Recycle as Classifier

HardPython

Problem

Debug a provided Transformer implementation containing several injected bugs (find and fix them), then convert the model into a classifier by modifying only the final layer, passing a provided test harness.

Asked in the coding_transformer_debug stage. The original prompt described four quickly discoverable bugs and a follow-up requiring the final layer to become a classifier. This portable task uses a standard-library function that reports the classifier output contract.

Input and Output

Implement debug_transformer_classifier(vocab_size, d_model, num_heads, num_layers, num_classes, tokens, padding_mask). tokens is a batch of token IDs, and padding_mask is either null or a matching boolean matrix. Return a dictionary containing output_shape, tokens_shape, and, when padding exists, padding_excluded.

Constraints

  • 1 <= len(tokens) <= 128
  • 1 <= len(tokens[i]) <= 512
  • All token rows have the same sequence length
  • 0 <= tokens[i][j] < vocab_size
  • 1 <= d_model, num_heads, num_layers, num_classes
  • d_model is divisible by num_heads
  • padding_mask is null or has the same batch and sequence dimensions as tokens

Function Signature

def debug_transformer_classifier(vocab_size, d_model, num_heads, num_layers, num_classes, tokens, padding_mask):
Interviewer

Your question is Fix Transformer Bugs and Recycle as Classifier. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.