Abstract
Code language models (CodeLLMs) are now commonplace in software development. As a general rule, CodeLLMs are trained by dividing training examples into input tokens and then learning the 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. 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, derived from observations of human visual attention. Our evaluation shows that EyeMulator outperforms strong LLM baselines on several tasks such as code translation, completion, and summarization.
Introduction: The Gap Between Machine and Human Attention
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, utilize "program comprehension." We intuitively recognize that a loop condition or a variable declaration carries more semantic weight than boilerplate code.
Current CodeLLMs often struggle with deep semantic understanding, leading to logical flaws or "hallucinations" because they treat all tokens with similar statistical weight. EyeMulator addresses this gap by bridging the divide between raw statistical pattern matching and human-like intuition through the integration of human gaze patterns.
Methodology: The EyeMulator Pipeline
EyeMulator is a lightweight, model-agnostic framework that "injects" human gaze patterns into the training loop without requiring architectural changes to the underlying LLM.
The process involves four key stages:
- Artifact Distillation: Raw eye-tracking data (fixations and saccades) are mapped to Abstract Syntax Tree (AST) tokens.
- Salience Modeling: Using Bayesian Beta distributions, the framework models the "salience" of different semantic classes (e.g.,
function_callvs.assignment). It also utilizes n-gram transition tables to capture the sequential "flow" of human code reading. - Subword Projection: Since LLMs use subword tokenizers, EyeMulator propagates AST-level weights down to the specific shards the model processes.
- Gaze-Informed Fine-Tuning: The training objective is modified via Weighted SFT (re-weighting cross-entropy loss) and Token-level DPO (Direct Preference Optimization), encouraging the model to prefer outputs that emphasize high-salience tokens identified in the human gaze data.
Experimental Setup and Datasets
The researchers utilized the EyeTrans dataset, which contains eye-tracking recordings from 27 programmers performing reading and writing tasks on Java snippets. Downstream evaluation was conducted using the CodeXGlue benchmark, focusing on Java-to-C# translation, code completion, and Java-to-Natural Language summarization.
Key Insights
- Task-Specific Gaze: The study found that "writing-derived" gaze patterns are significantly more effective for code completion, while "reading-derived" patterns 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 analysis revealed that EyeMulator helps models "prune" irrelevant peripheral tokens. In translation tasks, baseline models often exhibited diffuse attention, whereas EyeMulator-trained models showed sharp, diagonal token-to-token alignment.
Results
Performance boosts across three different architectures (StarCoder, DeepSeek-Coder 1.3B, and Llama-3.2 1B) were substantial:
- Code Translation: StarCoder’s CodeBLEU score improved 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).
Furthermore, the Generation Confidence Score (GCS) improved across all models, indicating that models became more "certain" of their outputs when aligned with human attention.
Conclusion and Future Work
EyeMulator demonstrates that mimicking human visual attention is a viable path toward more robust CodeLLMs. While currently focused on Java and 1B-parameter models, the framework is theoretically architecture-agnostic. Future work will expand the dataset to include professional developers and additional languages like Python and C#. A promising direction involves integrating low-cost webcam-based gaze estimation directly into IDEs to provide real-time, personalized code completions based on a developer's current focus.
Summary updated