Computer-Aided Design as Language

Yaroslav Ganin, Sergey Bartunov, Yujia Li, Ethan Anderson Keller, Stefano Saliceti

Computer-Aided Design (CAD) applications are the backbone of modern manufacturing, used to model everything from coffee mugs to sports cars. However, these programs are highly complex, requiring years of training and experience to master. The most challenging component of CAD modeling is often the highly structured 2D sketches that serve as the foundation for 3D constructions.

In a novel approach, researchers from DeepMind and Onshape have reframed CAD sketch creation as a language modeling problem. By representing 2D engineering sketches as sequences of structured tokens and training a Transformer-based model on a massive new dataset, they have developed a system capable of synthesizing complex, valid designs from scratch or from images.

The Challenge of CAD Sketches

At the heart of every CAD model is a 2D sketch—a precise geometric "skeleton" made of entities (like lines, arcs, and circles) and constraints (such as tangency, symmetry, and perpendicularity).

A 2D CAD sketch is composed of geometric entities and relational constraints like symmetry and tangency.

Automating the creation of these sketches is notoriously difficult. First, sketches are highly structured; a single missing constraint can ruin the "design intent" of a part. Second, until recently, there was a distinct lack of large-scale, high-quality datasets of parametric sketches (the underlying code and logic of the drawing) rather than just raw pixels or meshes. This paper aims to bridge that gap by treating the construction of a CAD sketch like the generation of a sentence in a natural language.

Translating Geometry into Grammar

The authors propose a framework that treats CAD data serialization as a sequence modeling task, utilizing several key techniques to translate geometry into a machine-readable language:

  • Protocol Buffers (PB) for Representation: Instead of using raw JSON or text, the team uses Google’s Protocol Buffers to define the "grammar" of a CAD sketch. This ensures the data is compact and strictly typed.
  • The Triplet Representation: To feed this data into a Transformer, each field in a sketch is represented as a triplet: (discrete value, continuous value, is_end_flag). This allows the model to handle categorical choices (e.g., "is this a line or a circle?") and numerical coordinates (e.g., "x=0.5") simultaneously.
  • Interpreter-Guided Generation: A state machine (an "interpreter") is used during the generation process. This ensures that the Transformer only predicts tokens that are valid according to the PB schema, preventing the model from "hallucinating" invalid syntax.
  • Pointer Networks: Because constraints must reference specific entities (e.g., "Line A is tangent to Circle B"), Pointer Networks allow the model to "point" back to previously generated items in the sequence.
The model architecture uses a Transformer combined with a Pointer Network to generate entities and link constraints back to them.

A Massive New Dataset and Key Insights

To train their model, the authors introduced a new dataset of over 4.7 million unique, carefully preprocessed parametric CAD sketches from Onshape Public Sketches. This significantly surpasses previous datasets in both scale and quality.

Training on this massive corpus revealed several key insights:

  1. CAD is a Language: The core "aha moment" is that choosing the next geometric entity or constraint is functionally analogous to choosing the next word in a sentence. Both require "grammatical" correctness and a cohesive meaning (design intent).
  2. Interleaving Matters: The researchers found that the order in which a sketch is described matters immensely. "Interleaving" constraints (placing a 'tangent' constraint immediately after the lines it affects) performed significantly better than "concatenating" them (listing all lines, then all constraints). This suggests that local context is vital for the model to understand geometric relationships.
  3. Structure Beats Raw Bytes: While a model can learn to predict the raw byte-stream of a serialized file, providing the model with the explicit "triplet" structure makes it three times faster to train and much more accurate.

Results and Future Directions

The "Triplet Interleaved" model achieved the highest test likelihood, outperforming byte-level models and standard language modeling baselines. Qualitatively, the model successfully generates "solved" sketches that exhibit complex properties like symmetry, closed loops, and regularity—features often lost in non-parametric generative models.

Furthermore, when augmented with a Vision Transformer (ViT) encoder, the model demonstrated a strong ability to "reverse engineer" pixelated bitmaps into fully editable, parametric CAD sketches. This image-to-sketch translation reduced visual reconstruction error by approximately 80% compared to nearest-neighbor baselines.

While this work is currently limited to 2D sketches, it paves the way for intelligent tools that could drastically reduce the effort required to create CAD models. Future work will look toward extending this "language" to 3D operations (like extrusions and lofts), using Reinforcement Learning to reduce error accumulation, and integrating neural networks more tightly with external geometric solvers.

Summary updated

BibTeX
@inproceedings{ganin2021computer,
  author = {Yaroslav Ganin and Sergey Bartunov and Yujia Li and Ethan Anderson Keller and Stefano Saliceti},
  title = {{Computer-Aided Design as Language}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=z-X_PpwaroO},
}
Figure