mlsanityData to 7 Oct 2026

Understanding How CodeLLMs (Mis)Predict Types with Activation Steering

arXiv 2404.01903 ↗First posted 2 Apr 2024cs.CL cs.LG cs.PLcited by 4

Not on the map. Why?

Abstract (arXiv)

Large Language Models (LLMs) are widely used by software engineers for programming tasks. However, research shows that LLMs often lack a deep understanding of program semantics. Even minor changes to syntax, such as renaming variables, can significantly degrade performance across various tasks. In this work, we examine the task of type prediction: given a partially typed program, can a model predict a missing type annotations such that the resulting program is more typed? We construct a dataset of adversarial examples where models initially predict the correct types, but begin to fail after semantically irrelevant edits. This is problematic, as models should ideally generalize across different syntactic forms of semantically equivalent code. This lack of robustness suggests that models may have a shallow understanding of code semantics. Despite this, we provide evidence that LLMs do, in fact, learn robust mechanisms for type prediction-though these mechanisms often fail to activate in adversarial scenarios. By using activation steering, a method that manipulates a model's internal activations to guide it toward using latent knowledge, we restore accurate predictions on adversarial inputs. We show that steering successfully activates a type prediction mechanism that is shared by both Python and TypeScript, and is more effective than prompting with in-context examples. Across five different models, our comprehensive evaluation demonstrates that LLMs can learn generalizable representations of code semantics that transfer across programming languages.

Key facts. Cited by 4 papers in the map (data through 7 Oct 2026). Builds on 24 of its 65 references that are in the map. First posted on arXiv 2 Apr 2024.

Builds on

24 of 65 references.

References · 24

  1. 2023Code Llama: Open Foundation Models for Codecited by 2,105
  2. 2023Inference-Time Intervention: Eliciting Truthful Answers from a Language Modelcited by 1,259
  3. 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,154
  4. 2023Steering Llama 2 via Contrastive Activation Additioncited by 1,009
  5. 2022Transformer Feed-Forward Layers Build Predictions by Promoting Concepts in the Vocabulary Spacecited by 522
  6. 2022InCoder: A Generative Model for Code Infilling and Synthesiscited by 492
  7. 2022The Stack: 3 TB of permissively licensed source codecited by 354
  8. 2023In-Context Learning Creates Task Vectorscited by 302
  9. 2024CRUXEval: A Benchmark for Code Reasoning, Understanding and Executioncited by 294
  10. 2022Efficient Training of Language Models to Fill in the Middlecited by 248
  11. 2023Using an LLM to Help With Code Understandingcited by 222
  12. 2020Causal Mediation Analysis for Interpreting Neural NLP: The Case of Gender Biascited by 183
12 more
  1. 2023The Hydra Effect: Emergent Self-repair in Language Model Computationscited by 145
  2. 2024If LLM Is the Wizard, Then Code Is the Wand: A Survey on How Code Empowers Large Language Models to Serve as Intelligent Agentscited by 77
  3. 2022Parsel: Algorithmic Reasoning with Language Models by Composing Decompositionscited by 62
  4. 2021Counterfactual Interventions Reveal the Causal Effect of Relative Clause Representations on Agreement Predictioncited by 58
  5. 2020LambdaNet: Probabilistic Type Inference using Graph Neural Networkscited by 44
  6. 2023Deploying and Evaluating LLMs to Program Service Mobile Robotscited by 36
  7. 2023Look Before You Leap: A Universal Emergent Decomposition of Retrieval Tasks in Language Modelscited by 17
  8. 2020OptTyper: Probabilistic Type Inference by Optimising Logical and Natural Constraintscited by 14
  9. 2024Do Large Code Models Understand Programming Concepts? Counterfactual Analysis for Code Predicatescited by 14
  10. 2021ManyTypes4Py: A Benchmark Python Dataset for Machine Learning-based Type Inferencecited by 9
  11. 2023Do Machine Learning Models Produce TypeScript Types That Type Check?cited by 6
  12. 2021Solver-based Gradual Type Migrationcited by 3

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2025: 1; 2026: 3.

4 papers.