LangVAE and LangSpace: Building and Probing for Language Model VAEs
Danilo S. Carvalho, Yingji Zhang, Harriet Unsworth, André Freitas
TL;DR
This paper introduces LangVAE, a modular framework for constructing language-model VAEs (LM-VAEs) atop pre-trained LMs, paired with LangSpace for systematic latent-space probing and evaluation. A key contribution is the KV cache injection mechanism, which guides autoregressive decoders without altering their architecture, enabling substantial reductions in training and inference compute (average parameter reductions >95% for many decoder sizes) while maintaining compatibility with state-of-the-art LLMs. The authors demonstrate the framework with a case study across encoder/decoder combinations and SRL-annotated inputs, revealing complex interactions in generalisation and disentanglement across architectural families; LangSpace provides quantitative metrics and visualisations (e.g., disentanglement scores, traversal quality) to systematise such experiments. The work emphasizes accessibility and reproducibility through PyPI releases, HF Hub checkpoints, and a supporting video, highlighting the practical impact of modular, scalable LM-VAEs for controlled text generation and interpretability.
Abstract
We present LangVAE, a novel framework for modular construction of variational autoencoders (VAEs) on top of pre-trained large language models (LLMs). Such language model VAEs can encode the knowledge of their pre-trained components into more compact and semantically disentangled representations. The representations obtained in this way can be analysed with the LangVAE companion framework: LangSpace, which implements a collection of probing methods, such as vector traversal and interpolation, disentanglement measures, and cluster visualisations. LangVAE and LangSpace offer a flexible, efficient and scalable way of building and analysing textual representations, with simple integration for models available on the HuggingFace Hub. Additionally, we conducted a set of experiments with different encoder and decoder combinations, as well as annotated inputs, revealing a wide range of interactions across architectural families and sizes w.r.t. generalisation and disentanglement. Our findings demonstrate a promising framework for systematising the experimentation and understanding of textual representations.
