RAFT on an Electronics Course: A Negative Result
P01 - Converting an Electronics Course into a Dataset
The goal, the method, how I mark measured results vs hypotheses, and the references are on the front page of this series.
Importance of Data Prep
Fine-tuning data and test questions are both built from these documents, so mistakes here carry through to everything else.
Two types of mistake matter most:
- Unnecessary bloat (boilerplate, empty templates, duplicates). The model trains on it, and retrieval returns it.
- Training and testing overlap. If a test question, or a near-copy of it, ends up in training, the scores look better than the model really is.

Stage 1 as a sequence: source files go through four scripts, one per step, and come out as clean text with a train/test split.
Modular Electronics Course
The Modular Electronics (ModEL) archive is 3.6 GB. Almost all of that is images; the text is small:
| file type | count | size | used for |
|---|---|---|---|
LaTeX (.tex/.latex) |
~3,970 | 24 MB | all of the teaching text |
| EPS (PostScript images) | 9,122 | 2.4 GB | diagrams and photos referenced by the text |
| compiled PDFs | 326 | 450 MB | not used (text extraction from PDF loses structure and garbles math) |
The course is built for print. There are 165 modules (one topic each, e.g. Thévenin's theorem or FETs). Each module is a LaTeX file that pulls in shared files: tutorials, case studies, technical references. One shared reference file is pulled in 324 times. The exams are separate: 1,253 question/answer file pairs, plus a C program (exammake.c) that lists which exam questions are interchangeable versions of each other.
Two things about the source shaped the whole project:
- Image-dense. 78% of exam questions refer to a figure (974 of 1,249 usable pairs). Only 243 exam items are without a figure.
- Socratic. Each module ends with Socratic questions: prompts and challenges with no answers (2,004 question sections). Fine as reading material, but they can't serve as test items, and they turn up later as retrieved "documents" that don't contain any answers.
Step 1: Parse (LaTeX → sections, exam pairs, image index)
The pipeline uses its own parser (parse.py) instead of a general converter.
Important decisions:
- Expand includes inline, then remove duplicates. Each module has its shared files pasted in and is cut into sections. Sections with identical content (after whitespace normalisation) are merged into one record, which lists every place that section appears. 7,604 sections → 5,846 unique. This handles whole shared files and repeated sections the same way, with no special cases.
- One chunk per section. Sections are coherent topics in this course, so they work as RAFT's "documents". Sections over 6,000 characters are split by subsection, then paragraph, and never inside a math block or a code listing. Median chunk ~1,900 characters, max ~6,200 (raw LaTeX).
- Drop boilerplates (carefully). Removed: version history, licence text, instructor notes, the identical "reading outline" prompt that appears in every module, and 1,704 empty template chunks ("This is the text of the question!"). Not removed: some
common_*files that look like boilerplate by name but hold real content (feedback control, statistics, safety). I dropped them by an explicit list of names, not by pattern. - Keep useful comments. LaTeX comments are usually noise, but a comment right after an image often holds the values of the pictured circuit (
% f=40k ; dutycycle=9.29%). Those are kept. - Variant groups for the exam.
exammake.clists, for each exam slot, which questions can stand in for each other. They are usually the same question with different numbers. Questions that share a slot are joined into one variant group (189 groups). Rule: a variant group is never split between training and test. Otherwise the model could train on a near-copy of a test question. - Image index. Every image is recorded with each place it's used and the text around it: 7,620 images.
Bug: a commented-out %\begin{verbatim} was read as a real code block, so the comment lines after it were kept as text. Verbatim detection now looks only at the non-comment part of each line.
Step 2: Render (PostScript → PNG + labels)
The plan was to have a vision model describe every figure. That needs raster images, so render.py converts each referenced EPS to PNG with Ghostscript (7,619 images; one referenced file is missing from the archive).
Two details:
- The source is untrusted input. PostScript is a programming language, so Ghostscript always runs with
-dSAFER. All pipeline scripts run in Python's isolated mode (-I) and never execute anything from the source folder. - Free text from the drawings. 5,791 images are schematics drawn in XCircuit, which stores its labels as text inside the file. The parser decodes them: label pieces are stored in reverse order, subscripts are marked with codes, and Greek letters come from the Symbol font (
W→ Ω,m→ µ). Result: 5,622 schematics have readable labels such asV1, R1, R2, TP1. Photos (1,555) get none.
Step 3: Figure Descriptions (paused)
I ran a pilot with Claude describing 50 hard figures (Sonnet: $1.10, Opus: $3.00, measured). Extrapolated to all 7,619 figures with the Batch API, that comes to ~$78 (Sonnet) or ~$216 (Opus).
Pause.
I wanted to see whether RAFT improved the model at all before paying for figures. Total spend on image pilots: $8.17.
That pause decided the shape of everything that came after. The first full run is text-only, and the exam test set shrank to the 243 items that need no figure.
Step 4: Clean Text (LaTeX → light Markdown)
clean_text.py turns each chunk into text a model reads easily:
- A custom converter, not pandoc. The course uses old plain-TeX layout (
$$…$$,\vskip, fill-in blanks drawn as\underbar{\hskip 50pt}), which general converters handle poorly. The converter handles only the macros that actually occur, found by surveying the source. Checked: 0 unknown commands left outside math. - Math stays LaTeX. Models read inline LaTeX well, and converting it to Unicode loses fractions and subscripts.
- Markdown for structure. Bold, lists, tables and code blocks. Bold matters here because the exam answers are often the bold values (
**0.3429 A**). - Figures become placeholders with their labels:
[Figure image_2041: labels V1, R1, R2, R3, TP1]. That makes 9,336 placeholders, 7,333 of them with labels. The tag format matches the planned descriptions, so they can be swapped in later without touching anything else.
The cost of this: a list of labels says what is in a circuit, but not how it's connected. For the 243 text-only exam items that doesn't matter. For the course text it means the documents are thinner than what a student would see.
Spot checks: several chunks, tables and exam pairs were compared side by side with the raw LaTeX.
Step 5: Split (held out for testing)
split.py decides what the model can train on:
- Whole modules are held out, not single sections: 16 of 165, chosen at random. Neighbouring sections of one module overlap, and 35 modules contain both a simplified and a full version of the same tutorial, so a section-level split would leak.
- A shared section counts as held out only if every module that uses it is held out. 145 sections of held-out modules are shared with training modules, so they stay in training. Held-out text never reaches training.
- The exam never trains. The 243 text-only exam items (42 variant groups) are test-only.
| split | used to write Q/A | chunks | characters |
|---|---|---|---|
| held out | yes | 323 | 1.08M |
| held out | no | 178 | 0.18M |
| train | yes | 3,054 | 10.02M |
| train | no | 2,291 | 2.75M |
"Used to write Q/A" means tutorial-like chunks of at least 400 characters. Socratic question chunks and off-topic modules (career advice, teaching pedagogy) stay in the search corpus but don't get training questions.
Limitation: held-out means "a document the model hasn't trained on", not "a topic it hasn't seen". Topics overlap across modules (parallel circuits vs series-parallel circuits). Hypothesis: the bigger issue is that the instruct model has probably seen ModEL itself during pretraining. It's public coursework. I couldn't test this directly, but the later results fit it. Part 5 comes back to it.
Output
- 5,846 unique text chunks (14.0M characters) as the search corpus
- 3,054 training chunks and 323 held-out chunks for writing questions
- 243 text-only exam items in 42 variant groups, never used for training
- all reproducible from the source files and the scripts
Learning Points
- Practise on data that looks like the real target. A well-known public course taught the pipeline, but not the result (part 5).
- Survey the source before committing to it. How image-heavy the course is (78% of exam questions need a figure) only became clear after the work had started. A one-hour count at the start would have shown that the test set would shrink to 243 items without paid figure descriptions.
- Know how the material teaches. A Socratic course is full of questions without answers. That's good for students and awkward for a RAG system: in the exam test with retrieved documents, about a third of the retrieved documents turned out to be these unanswered practice questions.
- Build leak rules in from the start. Variant groups and module-level holdout cost almost nothing at parse time. Adding them afterwards would have meant regenerating data.
Next: part 2, building the test set: where the questions came from, how retrieval was tuned, and how I checked the automated judge against my own grading.
Source: Modular Electronics Learning by Tony R. Kuphaldt, CC BY 4.0.
Code: github.com/wshindev/raft-electronics · Eval set: huggingface.co/datasets/wshindev/model-electronics-eval