Abstract
While multi-modal learning has successfully bridged natural language with images, video, and source code, the structural topology of neural networks has remained largely isolated. We present ArchBERT, the first bi-modal model designed to jointly represent neural network architectures (as graphs) and natural language. By utilizing a Graph Attention Network (GAT) for structural encoding and a BERT-based text encoder, ArchBERT enables tasks such as architectural reasoning, question answering, and cross-modal retrieval. Our results demonstrate that treating architectures as first-class graph modalities significantly outperforms traditional sequence-based or text-only approaches.
1. Introduction
In the current AI landscape, multi-modal models like CLIP and CodeBERT have revolutionized how machines relate different data types. However, a significant "modality gap" exists regarding the internal structures of neural networks themselves. Currently, developers and researchers rely on manual documentation or brute-force searches to navigate model repositories. There is no unified framework that allows a machine to correlate a computational graph with its textual description.
ArchBERT addresses this challenge by treating neural architectures as Directed Acyclic Graphs (DAGs) and aligning them with natural language descriptions. This allows for a seamless "bridge" between the structural logic of a model and the human language used to describe its function and properties.
2. Methodology
2.1 Architecture Representation
Unlike previous attempts that treat code as a linear sequence of tokens, ArchBERT recognizes that a model’s semantic meaning is rooted in its topology. The model utilizes a Graph Attention Network (GAT) as its architecture encoder. In this representation:
- Nodes represent operations (e.g., convolutions, pooling, batch normalization).
- Edges represent the data flow.
- Shape Metadata is embedded within the nodes, capturing critical dimensions such as input/output channels and kernel sizes, which are often lost in high-level code summaries.
2.2 Cross-Modal Alignment
ArchBERT employs a dual-stream approach. A standard BERT-based tokenizer handles text inputs, while the GAT processes the architecture graph. A transformer-based Cross Encoder then integrates these streams, learning the intricate relationships between specific graph patterns (like skip connections) and their textual labels.
2.3 Pre-training Tasks
The model is trained using two primary objectives:
- Masked Architecture Modeling (MAM): Inspired by BERT’s Masked Language Modeling, MAM randomly masks 15% of the nodes in an architecture graph. The model must predict the missing operation based on the surrounding connectivity, forcing it to learn the "grammar" of neural network design.
- Cosine Similarity Loss ($L_{SIM}$): This objective pushes the embeddings of corresponding text-architecture pairs closer together in a shared vector space while separating unrelated pairs.
3. Datasets
To facilitate this research, the authors introduced two novel benchmarks:
- TVHF (TorchVision & HuggingFace): A high-quality dataset featuring 538 unique human-designed architectures. It contains approximately 30,000 manually refined architecture-description pairs.
- AutoNet: A large-scale synthetic dataset of 11,000 randomly generated architectures. This includes AutoNet-AQA, a collection of 385,000 question-and-answer pairs designed to train the model on technical reasoning regarding network depth, width, and connectivity.
4. Key Insights
- Topology vs. Sequence: The transition from sequence-based code parsing to graph-based understanding is vital. ArchBERT can distinguish between a $3 \times 3$ and a $7 \times 7$ convolution not just as text tokens, but as structural features with different computational implications.
- The Importance of Shape: Experiments confirmed that including metadata like kernel sizes significantly boosts performance, as these parameters often define the specific "intent" of an architectural block.
- Structural Grammar: MAM allows the model to understand which operations are likely to follow others, providing a robust foundation for downstream reasoning tasks.
5. Results and Evaluation
ArchBERT demonstrates superior performance across several benchmarks compared to uni-modal baselines:
- Architectural Reasoning (AR): Achieved 96.13% accuracy in verifying if a text statement accurately describes a specific model structure.
- Architecture Question Answering (AQA): Reached 72.73% accuracy, outperforming text-only models by 17%, proving that structural knowledge is essential for answering technical queries.
- Clone Detection: The model achieved an F1 score of 85.98% when identifying semantically equivalent graph structures.
- Embedding Visualization: PCA visualizations show that ArchBERT successfully clusters similar architecture families (e.g., ResNets) near their relevant textual descriptions, demonstrating a well-aligned bi-modal latent space.
6. Conclusion and Future Work
ArchBERT establishes a new frontier for automated model management and discovery. While currently limited by the scale of human-annotated datasets and some sensitivity to framework-specific naming conventions (e.g., PyTorch vs. TensorFlow), it lays the groundwork for future innovations. The authors suggest that the next step is moving from retrieval and reasoning to Text-to-Architecture generation, where researchers can generate optimized neural structures directly from natural language prompts.
Summary updated