USC Applied NLP course project · 2026
Teaching a small model to rewrite
code search queries
Developers search code in plain English, but code speaks in function names and APIs. We put a 3B language model in front of a frozen search engine and trained it with reinforcement learning, rewarding it only by how high the correct function ranked.
Developer asks“how to check if a path is writeable python”
RewriterQwen2.5 Coder 3B + LoRA
Rewritten querycheck if path is writeable - os.access
Retriever (frozen)BM25 or UniXcoder
Correct functionBM25 rank 77 → 3
CodeSearchNet with BM25, Hit@10
0.607 → 0.676
About 7 more queries in every 100 find the right function in the top ten
Same model, before vs after training
8 of 8
Trained models beat the untrained 3B in every setting they were trained for, all significant
What we trained
1.0%
29,933,568 LoRA weights on a frozen 3.09B model
Test MRR@10, original query vs prompted vs trained
Higher is better. Whiskers show 95% bootstrap intervals. The trained model uses the combined reward.
Show data
Explore
Go deeper
The data8,000training questionsTwo datasets, 1,500 test questions, and how we built each set.Six stages6stagesFrom a single prompt to trained models, one question at a time, with a chart per stage.Final results0.607 → 0.676Hit@10, CodeSearchNet with BM25Every method compared, the reward choice across retrievers, and the hypothesis verdict.Insights1 → 406rank, after promptingSurprises from the experiments, and what the trained rewrites look like.Examples1,500searchable test queriesOriginal, prompted and trained rewrites side by side, with the rank of the correct function.Limitations and future work6 + 5limitations and next stepsWhat we would not claim from these results, and where the work could go next.