← Questions
Write a text parser and fix the bugs in an ML project
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Scale AI's coding round, last asked Sep 2025. It tests debugging, parsing and machine learning.
A one-hour hands-on round on an existing ML project. First write a parser that turns raw, messily formatted text files into the structured examples the project trains on. Then find and fix three bugs elsewhere in the project (data loading, preprocessing, training, evaluation). Finally show, within the time limit, that your fixes work.
Part 1: the parser
Unless you agree on a different interface with the interviewer, assume:
-
parse_file(path: str) -> tuple[list[dict], list[tuple[int, str]]]returns the parsed examples (for example{"id", "text", "label"}) and the rejected lines with their line numbers and reasons. - The input is line-oriented with a delimiter, may quote fields that contain the delimiter, and may contain bad encodings, missing fields and malformed lines. Bad lines are listed with a reason, never silently dropped.
Part 2: three bugs
- In the provided project, find and fix three defects. Typical ones: an off-by-one in tokenization, test data leaking into training (for example fitting a normalizer or vocabulary on all data), the wrong loss reduction (sum instead of mean), unseeded randomness that makes runs irreproducible, or a tensor shape mismatch hidden by broadcasting.
Part 3: proving the fixes
- Show each fix works: a failing test that now passes, an end-to-end run on a small subset, and metrics that make sense.
Example
raw line -> result
7\t"great, really great"\tpositive -> {"id": "7", "text": "great, really great", "label": "positive"}
8\tno label here -> rejected (8, "expected 3 fields, got 2")
9\tcaf\xe9 au lait\tneutral -> {"id": "9", "text": "café au lait", "label": "neutral"} # latin-1 fallback, logged
Clarifying questions
- What exact schema should the parser produce, and which fields are required?
- What should happen to malformed lines: drop, quarantine, or repair?
- For the bugs: is there a known symptom, or do I find all three cold?
- Is there a small data subset and an expected metric range for fast checks?
- Minimal fixes, or may I refactor?
What a strong answer covers
- Using the
csvmodule (with the right dialect) instead of hand-written quote handling; decoding strictly as UTF-8 first, falling back with a logged warning; Unicode normalization; counting and reporting rejected lines. - Tests for the parser: quoted delimiters, empty fields, a BOM, bad bytes, trailing newlines.
- A fast debugging method: run on a tiny subset, read the stack trace, add shape assertions, bisect with logging, build a minimal reproduction.
- Recognizing silent ML bugs: metrics that look too good (leakage), loss that changes with batch size (reduction), results that differ run to run (seeding).
- Validating each fix with a regression test and a short end-to-end run, all within the hour.
Follow-ups
- The files are 50 GB. How does the parser change?
- After your fixes the validation accuracy dropped. Is that good news or bad?
- How would you stop these bugs from coming back?
Where it's asked
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
