---
title: 'CNML: Contrastive Neural Model Checking'
url: https://www.emergentmind.com/topics/contrastive-neural-model-checking-cnml
type: topic
---

# CNML: Contrastive Neural Model Checking

Searching arXiv for the specified papers and closely related work to ground the article.
Contrastive Neural Model Checking (CNML) is a bi-encoder representation learning framework introduced for learning embeddings of sequential circuits in AIGER format and specifications in Linear Temporal Logic (LTL) in a shared latent space, using the model checking task itself as a self-supervised contrastive objective. Rather than replacing symbolic model checking for sound verification, CNML uses model checking outcomes as supervision to learn semantically meaningful embeddings, so that if a circuit \(c\) satisfies a specification \(\varphi\), their embeddings are close, and if \(c \not\models \varphi\), their embeddings are far. The resulting shared space is used for cross-modal retrieval, intra-modal retrieval, and downstream tasks such as predicting satisfaction \(c \models \varphi\) as a classification task [2510.01853].

## 1. Definition and semantic scope

CNML is organized around the classical decision problem
\[
S \models \varphi\;?
\]
for a system \(S\) and a temporal-logic specification \(\varphi\). In the CNML formulation, the satisfaction relation is not treated as the final output of a neural verifier. Instead, it is treated as a guiding signal for representation learning. The paper explicitly distinguishes this objective from symbolic model checking with full soundness guarantees: classical model checking remains algorithmic and symbolic, whereas CNML uses symbolic model checking only to generate labels, then treats model checking as a contrastive learning signal [2510.01853].

The central idea is a joint embedding space \( \mathbb{R}^d \) in which systems and specifications are aligned by semantics rather than surface form. The target geometry is given by
\[
z_c = f_{\text{circuit}}(c), \quad z_\varphi = f_{\text{spec}}(\varphi),
\]
with high similarity for positive pairs \((c,\varphi)\) such that \(c \models \varphi\), and low similarity for negative pairs \((c,\psi)\) such that \(c \not\models \psi\). The paper describes this as analogous to CLIP-style joint vision–language models, but for formal languages and hardware circuits rather than images and text. A plausible implication is that CNML reframes verification semantics as an alignment problem between two formal modalities.

This positioning also clarifies a common misconception. CNML does not claim to provide sound verification. The learned embeddings capture a soft approximation of the satisfaction relation; for verification, the method is described as a search or heuristics tool, including retrieval, prioritization, or pretraining, rather than as a replacement for model checking [2510.01853].

## 2. Formal setting: LTL specifications and AIGER circuits

The specification language is Linear-time Temporal Logic over atomic propositions \(AP\), with syntax
\[
\varphi \;::=\; \top \mid p \mid \varphi \land \varphi \mid \neg \varphi \mid \mathsf{O}\varphi \mid \varphi \mathsf{U} \varphi
\]
for \(p \in AP\), together with derived Boolean operators \(\lor, \Rightarrow, \Leftrightarrow\) and temporal operators Release, Globally, and Eventually. Semantics are given over infinite traces \(Tr := (2^{AP})^\omega\), and satisfaction \(\tau \models \varphi\) is defined inductively. The work uses an assume–guarantee normal form,
\[
\text{spec} \;:=\; (\text{assumption}_1 \land \dots \land \text{assumption}_n) \;\Rightarrow\; (\text{guarantee}_1 \land \dots \land \text{guarantee}_m),
\]
but, unlike earlier hierarchical-transformer work, all assumptions and guarantees are merged into a single LTL formula string fed to the text encoder [2510.01853].

Systems are sequential circuits represented as And-Inverter Graphs encoded in AIGER. AIGER describes Boolean variables encoded as integers, where even integers denote a signal and the subsequent odd integer denotes its negation. Inputs use a single integer variable per input, outputs use a single integer variable per output, AND-gates use three integers with conjunction semantics, and latches use two integers, with latch output at time \(t\) equal to its input at time \(t-1\) and initialized to FALSE. The header has the form
\[
\texttt{aag}\ M\ I\ L\ O\ A
\]
with \(M\) the maximum variable index, and \(I\), \(L\), \(O\), \(A\) the numbers of inputs, latches, outputs, and AND gates respectively [2510.01853].

The induced semantics is a transition system over latch valuations and input valuations, and the model checking relation is
\[
c \models \varphi,
\]
meaning that for all input traces, the resulting output traces satisfy the LTL formula \(\varphi\). In the machine-learning setup, an off-the-shelf model checker determines whether a pair is positive, \(c \models \varphi\), or negative, \(c \not\models \varphi\). CNML uses only known positives for training, together with implicit negatives within minibatches. This choice is structurally important because the supervision signal is derived from known satisfying pairs rather than from exhaustive positive–negative labeling.

## 3. Architecture and contrastive objective

CNML is a bi-encoder model with a circuit encoder \(E_c\) and a specification encoder \(E_\varphi\), with no shared parameters. Each encoder is initialized from CodeBERT and treated as a text encoder: circuits and specifications are both provided as token sequences, specifically AIGER text and LTL text. For a pair \((c,\varphi)\), the circuit and specification are separately encoded into pooled vectors \(h_c, h_\varphi \in \mathbb{R}^{768}\), then projected into a \(1024\)-dimensional space:
\[
z_c = W_c\,h_c \in \mathbb{R}^{1024}, \qquad
z_\varphi = W_\varphi\,h_\varphi \in \mathbb{R}^{1024}.
\]
The vectors are normalized to unit length for cosine similarity,
\[
\tilde{z}_c = \frac{z_c}{\|z_c\|},\quad \tilde{z}_\varphi = \frac{z_\varphi}{\|z_\varphi\|}.
\]
The use of two separate encoders is described as deliberate: it forces each encoder to model its own modality well, enforces alignment only via the contrastive objective rather than parameter sharing, and helps reduce overfitting to syntactic or dataset-artifact shortcuts [2510.01853].

For a minibatch of \(N\) positive pairs \((c_i,\varphi_i)\), CNML builds an \(N \times N\) similarity matrix
\[
S_{ij} = \text{cosine\_sim}(u_{c_i}, v_{\varphi_j})
       = \tilde{u}_{c_i}^\top \tilde{v}_{\varphi_j}.
\]
Diagonal entries \(S_{ii}\) are positive pairs; off-diagonal entries \(S_{ij}\), \(i \neq j\), are treated as negative pairs, under the assumption that different circuit–specification pairs in a minibatch almost never satisfy each other. The objective is to maximize diagonal similarity and minimize off-diagonal similarity [2510.01853].

The loss is
\[
\mathcal{L}_{\text{CNML}} = \mathcal{L}_{\text{CE}} + \lambda \mathcal{L}_{\text{RR}},
\]
where \(\mathcal{L}_{\text{CE}}\) is a symmetric contrastive cross-entropy loss, \(\mathcal{L}_{\text{RR}}\) is representation similarity regularization, and \(\lambda = 0.25\). The contrastive component follows an InfoNCE-style formulation with temperature scaling \(s_{ij} = S_{ij}/\tau\), initial \(\tau = 0.07\), and symmetric row-wise and column-wise cross-entropy. The regularization term is adopted to stabilize training, avoid overfitting, and allow a higher learning rate without catastrophic forgetting in BERT-like encoders. The paper does not expand the full formula for \(\mathcal{L}_{\text{RR}}\), but states that the general idea is to penalize excessive changes in the similarity structure of embeddings across training [2510.01853].

## 4. Data generation, training regime, and evaluation protocol

A core contribution is the synthetic dataset
\[
\text{cnml-base}: 295{,}665 \text{ positive pairs } (c,\varphi) \text{ with } c \models \varphi.
\]
The generation process has three stated steps. First, LTL formulas are produced by adapting the formula generation technique from Schmitt et al. (2021) to obtain diverse, semantically meaningful assume–guarantee specifications. Second, for each specification, a circuit is synthesized that by construction satisfies the specification using the Strix LTL synthesis tool of Meyer et al. (2018) and existing synthesis pipelines to generate varied AIGER circuits. Third, two augmentation measures are applied to avoid syntactic shortcuts: assumption shuffling, which permutes the order of assumption subformulas within a specification, and fixed IO width, which enforces a uniform number of input and output wires across all circuits, even if unused [2510.01853].

For generalization experiments, the paper derives a second dataset, cnml-split, through formula splitting. If
\[
\varphi := \bigwedge_{\psi \in \Psi_A} \psi \;\Rightarrow\; \bigwedge_{\gamma \in \Psi_G} \gamma
\]
and \(c \models \varphi\), then for any individual guarantee \(\gamma \in \Psi_G\),
\[
c \models \left(\bigwedge_{\psi \in \Psi_A} \psi\right) \Rightarrow \gamma.
\]
This makes it possible to transform complex multi-guarantee specifications into multiple single-guarantee specifications while keeping the circuit fixed. The resulting dataset is used to train CNML-simple, which sees only single-guarantee formulas during pre-training [2510.01853].

Batch construction is performed greedily at the start of each epoch to ensure no duplicate circuits or specifications within a batch, and off-diagonal pairs are cross-checked against the full dataset to reduce the chance that an off-diagonal pair is actually a known positive. The reported false-negative rate is approximately \(4\%\). The optimization stack is PyTorch 2.3 and HuggingFace Transformers, with CodeBERT backbones, projection dimension \(1024\), AdamW with \(\beta_1=0.9\), \(\beta_2=0.999\), weight decay \(0.01\), learning rate \(2 \times 10^{-4}\), linear warm-up for \(4200\) steps, linear decay, per-GPU batch size \(128\), gradient accumulation \(2\), and \(8 \times\)A100 GPUs under DDP with mixed precision. Training time is reported as approximately \(8\) hours to the best checkpoint on cnml-base for CNML-base [2510.01853].

The evaluation protocol centers on retrieval tasks and a downstream classification task. Cross-modal retrieval asks either for circuits satisfying a given specification or for specifications satisfied by a given circuit. Intra-modal retrieval asks for circuits that are functionally similar in the sense of satisfying roughly the same specifications. Retrieval datasets are drawn from the test split of cnml-base at candidate-set sizes \(N=100\) and \(N=1000\), with exactly one satisfying match per batch. The metrics are Mean Reciprocal Rank, Mean Rank, Recall@1\%, and Recall@10\%. Baselines include bag-of-keywords, Weisfeiler–Lehman Graph Kernel, an unadapted CodeBERT encoder, and Siamese-CNML [2510.01853].

## 5. Empirical behavior and learned representation structure

On cross-modal retrieval, CNML-base substantially outperforms the reported baselines. For \(N=100\), CNML-base achieves MRR \(0.371\), MR \(17.2\), R@1\% \(27.3\%\), and R@10\% \(57.6\%\), compared with the CodeBERT baseline at MRR \(0.051\), MR \(41.0\), R@1\% \(0\%\), and R@10\% \(11.1\%\). For \(N=1000\), CNML-base reports MRR \(0.211\), MR \(98.6\), R@1\% \(40.0\%\), and R@10\% \(85.0\%\). CNML-simple is weaker than CNML-base but remains above non-CNML baselines on the reported tasks. The paper states that CNML-base clearly dominates baselines as problem size grows [2510.01853].

On intra-modal circuit retrieval, CNML-base also exceeds algorithmic and neural comparators. For \(N=100\), CNML-base obtains MRR \(0.290\), MR \(19.0\), R@1\% \(17.1\%\), and R@10\% \(49.5\%\), while the best algorithmic baseline, Weisfeiler–Lehman, gives MRR \(0.075\), MR \(42.7\), R@1\% \(3.3\%\), and R@10\% \(13.1\%\). For \(N=1000\), CNML-base records MRR \(0.177\), MR \(117.2\), R@1\% \(40.0\%\), and R@10\% \(80.0\%\), while the Weisfeiler–Lehman baseline gives MRR \(0.007\), MR \(531.1\), R@1\% \(0\%\), and R@10\% \(15.0\%\) [2510.01853].

The representation analysis is framed geometrically. On the test split of cnml-base, cosine similarities show two distinct distributions for positive versus negative circuit–specification pairs, with limited overlap, and the similarity heatmap for a batch has the highest values on the diagonal and lower values off-diagonal. The paper interprets this as evidence that the embedding space encodes the satisfaction relation in a geometrically meaningful way. This suggests that the learned latent space is not merely capturing token overlap or graph-shape similarity, because bag-of-words, edit-distance baselines, and graph kernels underperform the CNML embeddings [2510.01853].

The embeddings also transfer to downstream model-checking classification. In a Sentence-BERT-style classifier trained on \(96{,}940\) training examples and evaluated on \(12{,}262\) test examples, CodeBERT initialization yields accuracy \(0.830\), precision \(0.799\), recall \(0.884\), and F1 \(0.839\); CNML-simple initialization improves this to accuracy \(0.845\), precision \(0.814\), recall \(0.894\), and F1 \(0.852\); CNML-base initialization reaches accuracy \(0.887\), precision \(0.847\), recall \(0.947\), and F1 \(0.894\). The paper presents these results as evidence that contrastive neural model checking learns transferable semantic features about the satisfaction relation [2510.01853].

A further empirical point concerns compositional generalization. CNML-simple is trained only on single-guarantee formulas derived from formula splitting, yet is evaluated on multi-guarantee specifications from cnml-base. Despite that distribution shift, it outperforms non-CNML baselines on both retrieval tasks and improves over CodeBERT in downstream classification fine-tuning. The paper states that this indicates generalization from simpler specifications to more complex ones.

## 6. Relation to neural model checking, limitations, and prospective directions

CNML is situated within a broader neural-symbolic verification literature, but its stated novelty is narrower and more specific than general “neural model checking.” Prior work on LTL and traces is described as learning to decide satisfiability, generate witnesses, or classify traces and formulas, typically with single-modal inputs. Neural SAT, SMT, and theorem-proving systems learn over symbolic formulas and sometimes use contrastive learning, but do not align two different formal semantics into a shared space. In that landscape, CNML is presented as the first framework, to the authors’ knowledge, to treat circuits and LTL specifications as two modalities and learn a shared latent space where satisfaction defines the alignment [2510.01853].

The contrast with “Neural Model Checking” is especially sharp. That framework introduces a machine learning approach to model checking temporal logic in which neural networks serve as formal proof certificates for LTL, trained from randomly generated executions and then symbolically checked with satisfiability solving. Its core proof object is a ranking function for fair termination of the synchronous product of a system and a Büchi automaton for \(\lnot \Phi\), and formal soundness follows when the quantized neural certificate is verified by SMT.

Source: https://www.emergentmind.com/topics/contrastive-neural-model-checking-cnml