Towards Knowledge Alignment in Code LLMs: Contrastive Unlearning for Evolving APIs

· Source: cs.SE updates on arXiv.org · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Software Development & Engineering · Depth: Expert, extended

Summary

CURE, a novel contrastive unlearning approach, addresses the critical issue of Large Language Models (LLMs) generating deprecated API usages in code, which often results in unreliable and incompatible software. Traditional fine-tuning methods are inefficient for localized API modifications, and existing unlearning techniques primarily suppress outdated knowledge without explicitly guiding models toward correct replacements. CURE tackles this by jointly discouraging deprecated APIs and actively promoting their valid alternatives. Evaluated on four Code LLMs—DeepSeek-Coder-1.3B, StarCoder2-3B, CodeLlama-7B, and CodeGen-2B—using a recent deprecated API benchmark, CURE demonstrated superior performance. It significantly reduced deprecated API usage, substantially improved correct API replacement rates, and maintained general code generation capabilities on HumanEval, outperforming two state-of-the-art baselines. This highlights the importance of combining suppression with replacement-aware learning for adapting LLMs to evolving software ecosystems.

Key takeaway

For Machine Learning Engineers adapting Code LLMs to rapidly evolving software libraries, you should integrate contrastive unlearning methods like CURE. Relying solely on suppression-based unlearning risks generating mismatched or incomplete code. Instead, explicitly guide your models to both forget deprecated APIs and adopt correct replacements. This approach significantly improves code reliability and maintains general generation performance, ensuring your models remain current and functional.

Key insights

CURE uses contrastive unlearning to both suppress deprecated APIs and promote valid replacements in Code LLMs.

Principles

Method

CURE extends gradient-based parametric unlearning (SimNPO/PROD) with a contrastive objective. It constructs positive samples with valid APIs to enforce preference for correct alternatives over deprecated ones.

In practice

Topics

Best for: Research Scientist, AI Scientist, Machine Learning Engineer, AI Engineer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by cs.SE updates on arXiv.org.