Setup

September 1, 2025 ยท View on GitHub

  1. Create a new environment using conda.
conda create -p ./.venv_text_diffusion python=3.11.10 pip ipykernel -y
conda activate ./.venv_text_diffusion
pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu124 && \
pip install -r core_requirements.txt && \
pip install -r test_requirements.txt && \
pip install -r lint_requirements.txt && \
pip install -e .
  1. Create a .env file in the root directory with the following content:
DATA_DIR=/path/to/the/directory/to/store/data
WANDB_ENTITY=<wandb_username>
WANDB_PROJECT=<wandb_project_name>
TOKENIZERS_PARALLELISM=false
RESULTS_DIR=/path/to/directory/to/store/results
PROJECT_ROOT=.
HYDRA_FULL_ERROR=1

If you do not plan to use wandb for logging, the WANDB_ENTITY and WANDB_PROJECT will be ignored.

Note

The star_small, vstar_small and vstar_medium in the code correspond to the easy, medium and hard versions of the star graph datasets in the paper.

ILM = Insertion Language Model, IT = Insertion Transformer[^1], XLNet = XLNet[^2], MDM = Masked Diffusion Model[^3], ARM = Autoregressive (left-to-right) Model

Training

The scripts listed in the table below are present in the scripts/ directory.

ModelDatasetScriptWeightsExperiment
ILMStar (easy)train_ilm_stopping_star_small.sh-X
ILMStar (medium)train_ilm_stopping_vstar_small.shilm-star_medium.ptX
ILMStar (hard)train_ilm_stopping_vstar_medium.shilm-star_hard.ptX
---------------
MDMStar (easy)train_mdlm_star_small.shmdm-star_easy.ptmdlm_star_small
MDMStar (medium)train_mdlm_vstar_small.shmdm-star_medium.ptmdlm_vstar_small
MDMStar (hard)train_mdlm_vstar_medium.shmdm-star_hard.ptmdlm_vstar_medium
---------------
ARMStar (easy)train_arlm_star_small.sh-X
ARMStar (medium)train_arlm_vstar_small.sh-X
ARMStar (hard)train_arlm_vstar_medium.sh-X
---------------
ITStar (easy)train_it_stochastic_star_small.shit-star_easy.ptit_stochastic_star_small
ITStar (medium)train_it_stochastic_vstar_small.shit-star_medium.ptit_stochastic_vstar_small
ITStar (hard)train_it_stochastic_vstar_medium.shit-star_hard.ptit_stochastic_vstar_medium
---------------
XLNetStar (easy)train_xlnet_star_small.shxlnet-star_easy.ptxlnet_star_small
XLNetStar (medium)train_xlnet_vstar_small.shxlnet-star_medium.ptxlnet_vstar_small
XLNetStar (hard)train_xlnet_vstar_medium.shxlnet-star_hard.ptxlnet_vstar_medium
---------------
---------------
ILMZebratrain_ilm_tiny2_zebra.shilm-zebra.ptilm_tiny2_zebra
---------------
MDMZebratrain_mdlm_zebra.shmdm-zebra.ptmdlm_zebra
---------------
ARMZebratrain_arlm_zebra.sh-X
---------------
ILMLM1Btrain_ilm_lm1b_multi_node.shilm-lm1b.ptX
---------------
MDMLM1Btrain_mdlm_lm1b_multi_node.shmdm-lm1b.ptmdlm_lm1b
---------------
ARMLM1Btrain_arlm_lm1b_multi_node.sh-X
---------------
ILMStoriestrain_ilm_stories_multi_node.shilm-stories.ptilm_stories
---------------
MDMStoriestrain_mdlm_stories_multi_node.shmdm-stories.ptmdlm_stories
---------------
ARMStoriestrain_arlm_stories_multi_node.sh-X
---------------

Generation

First download all the checkpoints using python download_weights.py.

Unconditional generation

ModelDatasetScript
ILMLM1Bscripts/generate_ilm_lm1b_timed.sh
ILMStoriesscripts/generate_ilm_stories_timed.sh

Variable length infill

ModelDatasetScript
ILMLM1Bscripts/infill_ilm_lm1b.sh
ILMStoriesscripts/infill_ilm_stories.sh

Evaluation

  • NLL for unconditional generation

Use scripts/nll_per_sample.sh by providing the path to the unconditional generation file.

  • NLL for variable length infill

Use scripts/nll_per_sample_infill.sh by providing the path to the infill generation file.

  • LLM-as-Judge Evaluation for unconditional generation

Use src/llm/eval/generate_llm_eval.sh for LLM-as-Judge evaluation by providing path to judge model, unconditional generation file, judge output file, and the rubrics (coherence | grammaticality | fluency | consistency | spelling_accuracy). We use the judge model prometheus-eval/prometheus-7b-v2.0 for our evaluation results.

Directory Structure

Inside pcdd/src

  1. commands: Contains the entry-level scripts like lightning_main_v2.py and lightning_train.py
  2. models: Contains complete networks used for generation.
  3. modules: Contains the building blocks of the networks.
  4. utils: Contains utility functions.
  5. datamodule: Contains one file for each dataset.
  6. diffusion: Contains one file for each type of model. The main object in each file a lightning module.

Cite

@misc{patel2025insertion,
    title={Insertion Language Models: Sequence Generation with Arbitrary-Position Insertions},
    author={Dhruvesh Patel and Aishwarya Sahoo and Avinash Amballa and Tahira Naseem and Tim G. J. Rudner and Andrew McCallum},
    year={2025},
    eprint={2505.05755},
    archivePrefix={arXiv},
    primaryClass={cs.CL}
}

The code builds on MDLM.