Naturalness of Attention: Revisiting Attention in Code Language Models

Mootez Saad, Tushar Sharma
11/22/2023
cs.SEcs.LG

No confident code implementation found for this paper.

Abstract

Language models for code such as CodeBERT offer the capability to learn advanced source code representation, but their opacity poses barriers to understanding of captured properties. Recent attention analysis studies provide initial interpretability insights by focusing solely on attention weights rather than considering the wider context modeling of Transformers. This study aims to shed some light on the previously ignored factors of the attention mechanism beyond the attention weights. We conduct an initial empirical study analyzing both attention distributions and transformed representations in CodeBERT. Across two programming languages, Java and Python, we find that the scaled transformation norms of the input better capture syntactic structure compared to attention weights alone. Our analysis reveals characterization of how CodeBERT embeds syntactic code properties. The findings demonstrate the importance of incorporating factors beyond just attention weights for rigorously understanding neural code models. This lays the groundwork for developing more interpretable models and effective uses of attention mechanisms in program analysis.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{saad2023naturalness,
  title  = {Naturalness of Attention: Revisiting Attention in Code Language Models},
  author = {Mootez Saad and Tushar Sharma},
  year   = {2023},
  eprint = {2311.13508},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2311.13508v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2311.13508.svg)](https://codeofpaper.com/paper/2311.13508)

Discussion