Skip to content

Code and data for the paper "Controlling Reading Ease with Gaze-Guided Text Generation"

License

Notifications You must be signed in to change notification settings

mainlp/gaze-guided-text-generation

Repository files navigation

Gaze-controlled text generation

This repository contains the code for reproducing the results and figures in the paper Controlling Reading Ease with Gaze-Guided Text Generation (EACL 2026).

Contents

Code:

  • gaze_model.ipynb: Code for reproducing the gaze model training
  • generate.py/generate_all.sh: Scripts for generating the texts
  • analysis.ipynb: Code for reproducing the statistical analysis and figures
  • modeling/: Modules for data preprocessing, model training, and text generation

Data:

  • emtec/: Scripts for downloading and converting the EMTeC dataset (Bolliger et al., 2024)
  • eyetracking/: Preprocessed gaze data from the eye-tracking study (corresponds to gaze/measures/cleaned.zip in the dataset repository)
  • responses/: Response data from the eye-tracking study (comprehension questions and ratings; corresponds to responses/responses.csv in the dataset repository)

Outputs:

  • models/: Trained gaze models
  • stories/prompts.jsonl: Story prompts used for generating the texts
  • stories/output-Llama-3B: Generated texts
  • paper/figures/: Figures generated by the analysis notebook

Reproducing results

Requirements and setup

  • Install Python >= 3.12
  • pip install -r requirements.txt

Gaze model training

gaze_model.ipynb contains all the code necessary to train and evaluate the GPT-2-based gaze model used in the paper, as well as the linear regression baseline.

The trained models are also included in the models directory. Retraining the models is not necessary for generating texts in the next section.

Text generation

Running generate_all.sh will reproduce the texts with the settings described in the paper. A GPU with about 80GB of memory is recommended.

To generate texts with other settings, use generate.py:

python generate.py \
    --prompts stories/prompts.jsonl \
    --language-model <hugging-face-model-name> \
    --gaze-model <gaze-model-name> \
    --gaze-weight <gaze-weight> \
    --beam-size <beam-size> \
    --gpu <device-id> \
    > output.jsonl
  • <hugging-face-model-name> can be any instruction-tuned language model on the Hugging Face Hub (or local)
  • <gaze-model-name> can be trf (transformer) or lr (linear regression)
  • <gaze-weight> can be any real number
  • <beam-size> can be any positive non-zero integer
  • <device-id> refers to the CUDA device IDs (comma-separated) for the GPUs to use (will be passed to CUDA_VISIBLE_DEVICES)
  • --verbose can be added to print the beam with the highest total score at each generation step

Analysis

analysis.ipynb contains all the code necessary to reproduce the statistical analyses and figures in the paper.

License

  • The code in this repository is licensed under MIT.
  • The dataset containing the generated texts, eye-tracking and response data is available here and licensed under CC-BY-NC.
  • The EMTeC dataset is available here and licensed under CC-BY.

About

Code and data for the paper "Controlling Reading Ease with Gaze-Guided Text Generation"

Topics

Resources

License

Stars

Watchers

Forks