SNACK: A Sequential Notation Framework for Probabilistic Graph Generation

Hohyun Kim, Hyesung Kim, Min-hwan Oh, Seunggeun Lee

TL;DR

SNACK is a novel string representation for graphs that allows standard sequence models (like Transformers) to generate 100% valid graphs and molecules. By establishing a one-to-one mapping between sequences and adjacency matrices, it enables efficient, principled GFlowNet training and achieves significantly higher throughput than traditional graph-based methods.

What Problem Does This Paper Address?

Generating graphs—especially molecules—is a cornerstone of drug discovery and materials science. Currently, researchers are caught between two paradigms:

  1. Graph-based methods: These operate directly on nodes and edges. They are structurally accurate but computationally expensive (often $O(N^3)$ complexity) and require specialized, complex architectures.
  2. String-based methods: These turn graphs into text (like SMILES). They are fast and work with standard Transformers ($O(N^2)$), but they often produce "broken" strings that don't correspond to real molecules. Furthermore, a single graph can often be represented by many different strings, which creates a "one-to-many" mapping that makes probabilistic modeling and reinforcement learning (like GFlowNets) mathematically messy and biased.

The authors introduce SNACK (Sequential Notation of Adjacent Connectivity FrameworK) to bridge this gap, providing the efficiency of strings with the structural rigor of graph-based methods.

Methods

SNACK linearizes a graph by encoding the non-zero entries of its lower-triangular adjacency matrix row-by-row.

  • The Encoding: Instead of complex grammar, SNACK uses three simple token types: node-type, edge-type, and distance (which indicates which previous node the current node is connecting to).
  • Bijectivity: The core innovation is that every valid SNACK sequence corresponds to exactly one ordered adjacency matrix. This "one-to-one" property is a major upgrade over SMILES.
  • Invalid Logit Masking: Because the representation is "prefix-decodable" (you can understand the partial graph at any point in the sequence), the model can use a mask to block invalid tokens. This guarantees 100% chemical and structural validity during generation.
  • GFlowNet Integration: The authors derive a way to train Generative Flow Networks (GFlowNets) using SNACK. By explicitly accounting for node-ordering symmetries (automorphisms), they ensure unbiased sampling of high-reward molecules.
Overview of the SNACK encoding process

Datasets

The authors evaluated SNACK across a wide range of benchmarks:

  • Generic Graphs: Planar, Enzymes, SBM, Grid, Ego-small, Community-small, and Lobster.
  • Molecules: QM9 (small molecules), MOSES (drug-like molecules), and Peptides-func (larger, more complex chains).
  • Goal-Directed Tasks: Optimizing for the HOMO–LUMO gap and molecular similarity to specific drugs (Albuterol and Aripiprazole).

Key Insights and Ideas

  • Sequence Models "Get" Geometry: Through "bilinear probing," the authors found that Transformers trained only on SNACK strings actually internalize the graph's internal structure. The models could reconstruct the full adjacency matrix and shortest-path distances between nodes with near-perfect accuracy, despite never seeing a "graph" during training.
  • Connectivity Before Nodes: Interestingly, the authors found that placing connectivity information (edges) before the node token in the sequence provides a better inductive bias for autoregressive modeling than the traditional "node-first" approach used in other methods.
  • The Power of Masking: Enforcing Breadth-First Search (BFS) ordering via logit masking doesn't just ensure validity; it reduces the search space, making the model much easier to train and more stable.
  • Superior Conditioned Generation: SNACK excels at "scaffold decoration" (adding to a partial molecule). Unlike SMILES, which can only extend a sequence from the "end," SNACK can attach new atoms to any previous atom within its "bandwidth," mimicking how chemists actually think about building molecules.

Key Results

  • 100% Validity: SNACK achieved perfect validity across all benchmarks, significantly outperforming SMILES and other string baselines on complex datasets like Peptides-func.
  • Massive Speedups: SNACK-based GFlowNets are significantly faster than graph-based versions. As shown in Figure 2, the training throughput remains high even as the number of nodes increases, whereas graph-based methods quickly hit memory and time limits.
Figure 2: GFlowNet training time comparison. The ‘×’ indicates the maximum scale within GPU mem- ory constraints.
  • Competitive Quality: On standard metrics like MMD (for general graphs) and FCD/SNN (for molecules), SNACK consistently matched or beat state-of-the-art specialized models.
  • Success in Constraints: In conditioned generation tasks, SNACK had a 39% success rate, while most other string-based methods hovered near zero because they couldn't handle the structural constraints (Table 3).
Table 3: Success Rate in conditioned generation.

Limitations and Future Work

While SNACK is a powerful step forward, the authors note several areas for improvement:

  • Fixed Ordering: The current version relies on a manually designed BFS ordering policy. Future iterations could involve learning the optimal node ordering jointly with the model.
  • Atom-Level Granularity: SNACK currently builds graphs atom-by-atom. Moving to "fragment-level" generation (using larger chemical building blocks) could further improve scalability for very large molecules.
  • Stereochemistry: The current framework does not yet support 3D properties like chirality (left-handed vs. right-handed molecules), which is critical for many biological applications.

Summary updated

BibTeX
@inproceedings{kim2026snack,
  author = {Hohyun Kim and Hyesung Kim and Min-hwan Oh and Seunggeun Lee},
  title = {{SNACK: A Sequential Notation Framework for Probabilistic Graph Generation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=Komy9HgwRY},
}
Figure