EyeMulator: Improving Code Language Models by Mimicking Human Visual Attention

Yifan Zhang, Chen Huang, Yueke Zhang, Jiahao Zhang, Toby Jia-Jun Li, Collin McMillan, Kevin Leach, Yu Huang

TL;DR

EyeMulator is a lightweight, model-agnostic framework that improves Code Language Models (CodeLLMs) by training them to mimic human visual attention. By integrating eye-tracking data into the fine-tuning process via re-weighted loss functions and preference optimization, the researchers achieved massive performance gains in code translation, completion, and summarization without changing the underlying model architecture.

What Problem Does This Paper Address?

While Large Language Models (LLMs) are incredibly powerful, their "machine attention" is purely statistical—it learns which input tokens correlate with output tokens based on massive datasets. Human developers, however, use "program comprehension." We intuitively know that a loop condition or a variable declaration is more semantically salient than boilerplate code.

Current CodeLLMs often struggle with deep semantic understanding, leading to "hallucinations" or logically flawed code because they treat all tokens with similar statistical weight. The authors address this gap: How can we bridge the divide between raw statistical pattern matching and human-like intuition?

Methods

The researchers developed a pipeline called EyeMulator that "injects" human gaze patterns into the training loop:

  1. Artifact Distillation: They took raw eye-tracking data (fixations and saccades) and mapped them to Abstract Syntax Tree (AST) tokens.
  2. Salience Modeling: Using Bayesian Beta distributions, they modeled the "salience" of different semantic classes (e.g., function_call vs. assignment). They also created n-gram transition tables to capture the sequential "flow" of how humans read code.
  3. Subword Projection: Since LLMs use subword tokenizers, EyeMulator propagates AST-level weights down to the specific shards the model actually "sees."
  4. Gaze-Informed Fine-Tuning: This is the core innovation. They modified the training objective in two ways:
  5. Weighted SFT: A supervised fine-tuning stage where the cross-entropy loss is re-weighted so that tokens humans fixate on have a higher influence on model updates.
  6. Token-level DPO: They used Direct Preference Optimization to encourage the model to prefer outputs that emphasize high-salience and rare n-grams identified in the human gaze data.

Crucially, this is a "plug-and-play" approach. It requires no architectural changes to the LLM and adds less than 1MB of overhead.

Datasets

  • EyeTrans: A publicly available dataset containing eye-tracking recordings from 27 intermediate-to-advanced programmers performing reading and writing tasks on Java snippets.
  • CodeXGlue: A standard benchmark used for the downstream evaluation tasks: Java$\rightarrow$C# translation, Java code completion, and Java$\rightarrow$NL summarization.

Key Insights and Ideas

  • Reading vs. Writing Matters: The study found that "writing-derived" gaze patterns (how we look at code while authoring it) are significantly more effective for code completion tasks. Conversely, "reading-derived" patterns (how we comprehend existing code) excel at translation and summarization.
  • The "Anchor" Effect: Variable declarations act as cognitive anchors for humans. EyeMulator successfully teaches models to treat these as high-salience tokens, leading to more contextually accurate generations.
  • Attention Pruning: Qualitative attention maps revealed that EyeMulator helps models "prune" irrelevant peripheral tokens. In translation tasks, the baseline models had diffuse attention, while EyeMulator-trained models showed sharp, diagonal token-to-token alignment.
  • Rarity Weighting: By emphasizing infrequent but semantically important n-grams (rarity weighting), the model avoids over-relying on common boilerplate tokens.

Key Results

The performance boosts across three different architectures (StarCoder, DeepSeek-Coder 1.3B, and Llama-3.2 1B) were substantial:

  • Code Translation: StarCoder’s CodeBLEU score jumped from 52.07 to 86.42 (+34.35).
  • Code Completion: Llama-3.2 (1B) saw its CrystalBLEU score rise from 26.65 to 65.90 (+39.25).
  • Summarization: DeepSeek-Coder’s BERTScore improved from 28.64 to 51.56 (+22.92).
  • Confidence: The "Generation Confidence Score" (GCS) improved across the board, indicating the models became more "certain" of their outputs when aligned with human attention.

Limitations and Future Work

  • Sample Diversity: The eye-tracking data was sourced from 27 student programmers. Professional developers might exhibit different, perhaps more efficient, attention patterns.
  • Language Constraints: The current work is focused on Java. The authors plan to expand to Python and C# in future iterations.
  • Scaling: While tested on 1B-parameter models for efficiency, the authors have yet to run these experiments on 7B+ or 70B+ models due to compute constraints, though the method is theoretically architecture-agnostic.
  • Real-time Integration: A promising future direction is integrating low-cost webcam-based gaze estimation directly into IDEs to provide real-time, personalized code completions based on where the developer is currently looking.

Summary updated

Abstract

Code language models (so-called CodeLLMs) are now commonplace in software development. As a general rule, CodeLLMs are trained by dividing training examples into input tokens and then learn importance of those tokens in a process called machine attention. Machine attention is based solely on input token salience to output token examples during training. Human software developers are different, as humans intuitively know that some tokens are more salient than others. While intuition itself is ineffable and a subject of philosophy, clues about salience are present in human visual attention, since people tend to look at more salient words more often. In this paper, we present EyeMulator, a technique for training CodeLLMs to mimic human visual attention while training for various software development tasks. We add special weights for each token in each input example to the loss function used during LLM fine-tuning. We draw these weights from observations of human visual attention derived from a previously-collected publicly-available dataset of eye-tracking experiments in software engineering tasks. These new weights ultimately induce changes in the attention of the subject LLM during training, resulting in a model that does not need eye-tracking data during inference. Our evaluation shows that EyeMulator outperforms strong LLM baselines on several tasks such as code translation, completion and summarization. We further show an ablation study that demonstrates the improvement is due to subject models learning to mimic human attention.
BibTeX
@inproceedings{zhang2026eyemulator,
  author = {Yifan Zhang and Chen Huang and Yueke Zhang and Jiahao Zhang and Toby Jia-Jun Li and Collin McMillan and Kevin Leach and Yu Huang},
  title = {{EyeMulator: Improving Code Language Models by Mimicking Human Visual Attention}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.acl-long.1158},
}

Loading related content...

Figure