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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Tuning LLM Outputs
00:00
5 left

Tuning LLM Outputs

HardPython

Problem

An LLM is producing wrong/inaccurate short answers: examine the prompt and tweak its hyperparameters (temperature, number of tokens, etc.) to fix it.

Asked in the onsite test stage.

Implement choose_llm_hyperparameters(prompt, trials). prompt is a string. trials is a list of objects containing prompt, temperature, max_tokens, response, and expected. Consider only trials whose prompt exactly matches the target. Normalize response and expected by trimming, collapsing whitespace, and ignoring case. Return the configuration with the highest exact-match accuracy. Break ties by lower temperature, then lower max_tokens. Return None if no matching trials exist.

Example: matching configurations with accuracies 1.0 and 0.5 return the first configuration.

Constraints

  • 1 <= len(trials) <= 1000
  • Each trial contains the five required keys
  • temperature is a nonnegative number
  • max_tokens is a positive integer
  • At least one matching trial may be absent
  • Responses and expected answers are strings

Function Signature

def choose_llm_hyperparameters(prompt, trials):
Interviewer

Your question is Tuning LLM Outputs. 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
Sign up free to run your codeLog inLn 2
Run your code to see test output here.