DiagrammaticLearning: A Graphical Language for Compositional Training Regimes

Mason Lary, Richard Samuelson, Alexander Wilentz, Alina Zare, Matthew Klawonn, James P. FairbanksarXiv 2025 · DOI

TL;DR

This paper introduces "learning diagrams," a novel graphical language that represents complex machine learning training setups as data, not code. This allows for more intuitive composition, manipulation, and rigorous mathematical understanding of multi-component models, leading to a library that simplifies building and managing sophisticated training pipelines.

What Problem Does This Paper Address?

Modern deep learning often involves intricate training regimes where multiple models interact in complex ways. Think of systems that combine vision and language processing, or techniques like knowledge distillation and multi-task learning. Managing these setups can be challenging, as practitioners often juggle models that are sometimes trained, sometimes frozen, and act as classifiers or feature extractors. The current approach of defining these pipelines as code can become unwieldy and difficult to reason about, especially when trying to reuse components or understand relationships between different training workflows. The authors aim to bridge this gap by providing a more structured, data-centric way to define and manipulate these complex training configurations.

Methods

The core contribution is the concept of learning diagrams. These are graphical representations that depict training setups. Instead of writing code, users define diagrams composed of nodes (representing data spaces or models) and edges (representing the flow of data or transformations). Crucially, these diagrams can be compiled into unique loss functions. The training process then aims to make the predictions of the component models "agree" with each other, effectively making the diagram "commute."

The authors leverage category theory to provide a rigorous mathematical foundation for learning diagrams. This allows for unambiguous interpretation, manipulation, and composition of these diagrams. They define learning graphs as directed multigraphs with a preorder on edges, and learning diagrams as functors from these graphs to a category of Lawvere metric spaces. This framework enables the extraction of parallel paths from diagrams, which are then used to construct composite loss functions. They also introduce concepts like homomorphisms for manipulating sub-diagrams and colimits for composing diagrams in a compositional manner.

To make this practical, they developed a software library, DiagrammaticLearning.jl, which allows users to build and manipulate these learning diagrams using PyTorch and Flux.jl models.

Datasets

The paper demonstrates the utility of learning diagrams on several established datasets commonly used in machine learning research:

  • Flickr8k and Flickr30k: Used for image captioning experiments.
  • CIFAR-10: Used for knowledge distillation experiments.
  • Mini-Imagenet (MI), Tiered-Imagenet (TI), Cifar-FS (CFS), and FC100: Used for few-shot learning experiments.

The authors do not introduce new datasets but rather re-implement existing benchmarks using their framework.

Key Insights and Ideas

  • Training as Data: The most significant insight is treating training regimes as data rather than code. This shift allows for programmatic manipulation, composition, and analysis of complex ML pipelines, akin to how software components are managed.
  • Compositionality: Learning diagrams are inherently compositional. This means complex training setups can be built by combining simpler, pre-defined diagrams, making it easier to manage and reuse components.
  • Rigorous Semantics: The use of category theory provides a strong mathematical foundation, ensuring that operations on learning diagrams are well-defined and interpretable, leading to greater confidence in their manipulation.
  • Unified Framework: The approach offers a unified way to represent diverse training paradigms like few-shot learning, knowledge distillation, and multi-modal learning, highlighting their underlying structural similarities.
  • Model Manipulation: The framework facilitates programmatic manipulation of models, such as easily switching architectures or freezing components, by operating on the diagrammatic representation.

Key Results

The paper demonstrates the effectiveness of learning diagrams by successfully replicating several common machine learning tasks:

  • Image Captioning: They achieved competitive results on Flickr8k and Flickr30k datasets, outperforming the original Vinyals et al. (2015) paper's BLEU score by using more powerful CNN encoders within their diagrammatic framework.
  • Knowledge Distillation: Their implementation on CIFAR-10 achieved performance comparable to the official PyTorch implementation, validating the approach for complex loss functions involving multiple parallel paths.
  • Few-Shot Learning: They replicated the Tian et al. (2020) approach for few-shot learning, demonstrating how learning diagrams can be used to compose complex models, specifically by merging sub-diagrams using a colimit construction. The performance was comparable to the original work across various datasets.

Limitations and Future Work

  • Current Limitation: The current formalism is primarily limited to building losses for finite datasets.
  • Future Work:
    • Investigate how model structure can be exploited for distributed training and high-performance systems.
  • Develop a more complete machine learning model management system.
  • Elevate software-centric definitions of reproducibility to a "implementation-free" mathematical plane.
  • Explore how homomorphisms between diagrams can capture relationships between development iterations and facilitate model searching.
  • Extend the formalism to handle continuous distributions.
  • Address the theoretical aspects of training with mini-batches.

Summary updated

BibTeX
@misc{lary2025diagrammaticlearning,
  author = {Mason Lary and Richard Samuelson and Alexander Wilentz and Alina Zare and Matthew Klawonn and James P. Fairbanks},
  title = {{DiagrammaticLearning: A Graphical Language for Compositional Training Regimes}},
  year = {2025},
  eprint = {2501.01515},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.01515},
}
Figure