Understanding How CodeLLMs (Mis)Predict Types with Activation Steering (2404.01903v2)
Abstract: CodeLLMs are transforming software development as we know it. This is especially true for tasks where rule-based approaches fall short, like type prediction. The type prediction task consists in adding a new type annotation to a partially typed program, such that the resulting program is closer to being fully typed. The intractability of rule-based approaches and high cost of manual annotation make CodeLLMs an attractive solution to the problem. However, CodeLLMs are still far from being deployed on the large-scale due to doubts surrounding their reliability. To shed some light on how CodeLLMs approach type prediction, we investigate what happens when a model mispredicts a type. We show that by applying semantics-preserving edits to code, CodeLLMs are eventually misled into mispredicting type annotations. However, by leveraging activation steering we are able to "steer" the model back to the correct prediction, making models more robust against semantically irrelevant prompt features. We show that steering achieves comparable performance to fine-tuning directly on the type prediction task. Furthermore, we find that steering vectors computed from Python code are effective at correcting TypeScript mispredictions, and vice versa. To our knowledge, this is the first evidence of its kind to suggest that CodeLLMs learn task representations that transfer across languages.
- GitHub Copilot: Your AI pair programmer, 2021. URL https://github.com/features/copilot/.
- Efficient training of language models to fill in the middle. arXiv preprint arXiv:2207.14255, 2022.
- Understanding TypeScript. In Richard Jones (ed.), ECOOP 2014 – Object-Oriented Programming, Lecture Notes in Computer Science, pp. 257–281, Berlin, Heidelberg, 2014. Springer. ISBN 978-3-662-44202-9. doi: 10.1007/978-3-662-44202-9˙11.
- Migrating Gradual Types. Proceedings of the ACM on Programming Languages (PACMPL), 2(POPL), 2018.
- Soft typing. In ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), 1991.
- Evaluating Large Language Models Trained on Code, July 2021. URL http://arxiv.org/abs/2107.03374. arXiv:2107.03374 [cs].
- Hints on Test Data Selection: Help for the Practicing Programmer. Computer, 11(4):34–41, April 1978. ISSN 1558-0814. doi: 10.1109/C-M.1978.218136. URL https://ieeexplore.ieee.org/document/1646911. Conference Name: Computer.
- Probing explicit and implicit gender bias through llm conditional text generation. arXiv preprint arXiv:2311.00306, 2023.
- A mathematical framework for transformer circuits. Transformer Circuits Thread, 1:1, 2021.
- InCoder: A Generative Model for Code Infilling and Synthesis. In International Conference on Learning Representations (ICLR), 2023.
- Transformer feed-forward layers build predictions by promoting concepts in the vocabulary space. In Yoav Goldberg, Zornitsa Kozareva, and Yue Zhang (eds.), Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, pp. 30–45, Abu Dhabi, United Arab Emirates, December 2022. Association for Computational Linguistics. doi: 10.18653/v1/2022.emnlp-main.3. URL https://aclanthology.org/2022.emnlp-main.3.
- DeepSeek-Coder: When the Large Language Model Meets Programming – The Rise of Code Intelligence, January 2024. URL http://arxiv.org/abs/2401.14196. arXiv:2401.14196 [cs].
- On the type structure of standard ML. ACM Transactions on Programming Languages and Systems, 15(2):211–252, April 1993. ISSN 0164-0925. doi: 10.1145/169701.169696. URL https://dl.acm.org/doi/10.1145/169701.169696.
- Deep Learning Type Inference. In ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering (ESEC/FSE), 2018.
- In-context learning creates task vectors. arXiv preprint arXiv:2310.15916, 2023.
- Safe polymorphic type inference for a dynamically typed language: Translating Scheme to ML. In International Conference on Functional Programming Languages and Computer Architecture (FPCA), 1995.
- Do large code models understand programming concepts? a black-box approach. arXiv preprint arXiv:2402.05980, 2024.
- Deploying and Evaluating LLMs to Program Service Mobile Robots. IEEE Robotics and Automation Letters, pp. 1–8, 2024. ISSN 2377-3766. doi: 10.1109/LRA.2024.3360020. URL https://ieeexplore.ieee.org/document/10416558.
- Editing models with task arithmetic. arXiv preprint arXiv:2212.04089, 2022.
- Learning type annotation: is big data enough? In Proceedings of the 29th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, pp. 1483–1486, Athens Greece, August 2021. ACM. ISBN 978-1-4503-8562-6. doi: 10.1145/3468264.3473135. URL https://dl.acm.org/doi/10.1145/3468264.3473135.
- Learning To Predict User-Defined Types. IEEE Transactions on Software Engineering, pp. 1–1, 2022. ISSN 0098-5589, 1939-3520, 2326-3881. doi: 10.1109/TSE.2022.3178945. URL https://ieeexplore.ieee.org/document/9785755/.
- Are mutants a valid substitute for real faults in software testing? In Proceedings of the 22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering, FSE 2014, pp. 654–665, New York, NY, USA, November 2014. Association for Computing Machinery. ISBN 978-1-4503-3056-5. doi: 10.1145/2635868.2635929. URL https://doi.org/10.1145/2635868.2635929.
- The Stack: 3 TB of permissively licensed source code. In Deep Learning for Code Workshop (DL4C), 2023. URL http://arxiv.org/abs/2211.15533.
- Inference-time intervention: Eliciting truthful answers from a language model. Advances in Neural Information Processing Systems, 36, 2024.
- StarCoder: may the source be with you! Transactions of Machine Learning Research (TMLR), December 2023.
- Competition-level code generation with AlphaCode. Science, 378(6624):1092–1097, December 2022. doi: 10.1126/science.abq1158. URL https://www.science.org/doi/full/10.1126/science.abq1158. Publisher: American Association for the Advancement of Science.
- The hydra effect: Emergent self-repair in language model computations. arXiv preprint arXiv:2307.15771, 2023.
- Locating and Editing Factual Associations in GPT, October 2022. URL http://arxiv.org/abs/2202.05262. arXiv:2202.05262 [cs].
- What is Decidable about Gradual Types? Proceedings of the ACM on Programming Languages (PACMPL), 4(POPL), 2020.
- Manytypes4py: A benchmark python dataset for machine learning-based type inference. In 2021 IEEE/ACM 18th International Conference on Mining Software Repositories (MSR), pp. 585–589. IEEE, 2021.
- Using an llm to help with code understanding. In 2024 IEEE/ACM 46th International Conference on Software Engineering (ICSE), pp. 881–881. IEEE Computer Society, 2024.
- Probabilistic Type Inference by Optimising Logical and Natural Constraints, 2021. URL https://arxiv.org/abs/2004.00348v3.
- The linear representation hypothesis and the geometry of large language models. arXiv preprint arXiv:2311.03658, 2023.
- Solver-based Gradual Type Migration. Proceedings of the ACM on Programming Languages (PACMPL), 5(OOPSLA), 2021. doi: https://doi.org/10.1145/3485488.
- Python: the full monty. In ACM SIGPLAN Conference on Object Oriented Programmingm, Systems, Languages and Applications (OOPSLA), pp. 217–232, Indianapolis, IN, USA, October 2013. ACM. ISBN 978-1-4503-2374-1. doi: 10.1145/2509136.2509536. URL https://dl.acm.org/doi/10.1145/2509136.2509536.
- The Ins and Outs of Gradual Type Inference. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), 2012.
- Steering llama 2 via contrastive activation addition. arXiv preprint arXiv:2312.06681, 2023.
- Code Llama: Open Foundation Models for Code, January 2024. URL http://arxiv.org/abs/2308.12950. arXiv:2308.12950 [cs].
- Adaptive Test Generation Using a Large Language Model. IEEE Transactions on Software Engineering (TSE), 50(1), 2024. doi: 10.1109/TSE.2023.3334955.
- Gradual Typing for Functional Languages. In Scheme Workshop, 2006.
- Gradual Typing with Unification-based Inference. In ACM SIGPLAN International Symposium on Dynamic Languages (DLS), 2008.
- Extracting latent steering vectors from pretrained language models. arXiv preprint arXiv:2205.05124, 2022.
- Bugs in large language models generated code. arXiv preprint arXiv:2403.08937, 2024.
- Interlanguage Migration: From Scripts to Programs. In ACM SIGPLAN International Symposium on Dynamic Languages (DLS), 2006.
- Activation addition: Steering language models without optimization. arXiv preprint arXiv:2308.10248, 2023.
- Look before you leap: A universal emergent decomposition of retrieval tasks in language models. arXiv preprint arXiv:2312.10091, 2023.
- Causal mediation analysis for interpreting neural nlp: The case of gender bias. arXiv preprint arXiv:2004.12265, 2020.
- LambdaNet: Probabilistic Type Inference using Graph Neural Networks. In International Conference on Learning Representations (ICLR), 2020.
- Tabnine: AI Assistant for software developers, 2013. URL https://www.tabnine.com/.
- If llm is the wizard, then code is the wand: A survey on how code empowers large language models to serve as intelligent agents. arXiv preprint arXiv:2401.00812, 2024.
- Do Machine Learning Models Produce TypeScript Types that Type Check? In European Conference on Object Oriented Programming (ECOOP), 2023.
- Parsel: Algorithmic reasoning with language models by composing decompositions. Advances in Neural Information Processing Systems, 36, 2024.