Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.