Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find the Issue in Code

MediumGenerative AI & LLMs00:00
Practice interviewer
In session
5 left
00:00

Your question is Find the Issue in Code. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

You need to log in / sign up to chat or submit.

Problem

You're an AI Trainer at the AI Research Institute, reviewing a scoring script a colleague wrote for flagging low-quality model completions before they go back for re-annotation.

def flag_low_quality(responses, threshold=0.5):
    flagged = []
    for i in range(len(responses)):
        score = responses[i]["score"]
        if score < threshold:
            flagged.append(responses[i])
        responses[i]["reviewed"] = True
    return flagged


def batch_score(prompts, cache={}):
    results = []
    for prompt in prompts:
        if prompt in cache:
            results.append(cache[prompt])
        else:
            score = compute_score(prompt)
            cache[prompt] = score
            results.append(score)
    return results


def compute_score(prompt):
    words = prompt.split()
    return len(set(words)) / len(words)

What is the issue in this code, and how would you fix it? There's more than one problem, walk through each one you find.