NodeClassifier, EdgeClassifier, and E2E Models in doc2graph: Architecture Differences Explained

NodeClassifier predicts node labels, EdgeClassifier predicts edge labels, and E2E models perform joint node and edge classification in a single forward pass using shared message-passing layers with dual prediction heads.

The andreagemelli/doc2graph repository provides three distinct graph neural network architectures for document understanding tasks. These models—NodeClassifier, EdgeClassifier, and E2E—are selected via the SetModel factory and differ primarily in their prediction targets and output heads. Understanding the architectural distinctions between these models is essential for choosing the right approach for your document graph parsing task.

Core Architecture Differences

NodeClassifier (GCN Model)

The NodeClassifier focuses exclusively on node-level classification. Implemented in doc2graph/models/graphs.py at lines 109-154, this architecture processes document graphs through an InputProjector that maps multimodal inputs into a common hidden space. The core consists of a stack of GcnSAGELayer modules performing message-passing, followed by a final projection layer that outputs logits for each node class.

Use this model when your task requires identifying entity types or section labels without predicting relationships.

EdgeClassifier (EDGE Model)

The EdgeClassifier specializes in relationship prediction between graph nodes. Defined at lines 167-203 in doc2graph/models/graphs.py, this model shares the same InputProjector and GcnSAGELayer backbone as the node classifier. However, it employs a dedicated MLPPredictor that combines the embeddings of two endpoint nodes with the edge's polar features to generate edge-class logits.

This architecture is optimal for tasks like identifying "belongs-to" or "refers-to" relationships in document structures.

E2E Model (End-to-End)

The E2E model performs joint node and edge classification within a single network. Located at lines 209-255 in doc2graph/models/graphs.py, this architecture runs message-passing through a single GcnSAGELayer, then splits into two specialized heads. The node-head uses nn.Linear with LayerNorm for node predictions, while the edge-head utilizes MLPPredictor_E2E to process node embeddings alongside hidden edge features and an additional edge_pred_features dimension.

Choose this model for complete document-graph parsing requiring simultaneous entity and relationship extraction.

Implementation and Configuration

All three models instantiate through the unified SetModel interface by specifying the model name. The configuration files reside in configs/models/, with gcn.yaml, edge.yaml, and e2e.yaml defining hyperparameters for each architecture.

from doc2graph.models.graphs import SetModel

# Node classification only

node_model = SetModel(name="GCN", device="cpu")
gnn_node = node_model.get_model(
    nodes=5,          # Number of node classes

    edges=0,          # Not used for node-only

    chunks=[128, 256, 64]  # Input modality dimensions

)

# Edge classification only

edge_model = SetModel(name="EDGE", device="cpu")
gnn_edge = edge_model.get_model(
    nodes=0,          # Not used

    edges=3,          # Number of edge classes

    chunks=[128, 256, 64]
)

# Joint node and edge classification

e2e_model = SetModel(name="E2E", device="cpu")
gnn_e2e = e2e_model.get_model(
    nodes=5,
    edges=3,
    chunks=[128, 256, 64]
)

Selecting the Right Model for Your Task

Choose the architecture based on your document understanding requirements:

  • NodeClassifier: Use for entity recognition, section type detection, or any task requiring node labeling without relationship extraction.
  • EdgeClassifier: Deploy when predicting specific relationship types between pre-identified entities is the primary objective.
  • E2E Model: Select for end-to-end document parsing where both entity types and their relationships must be inferred simultaneously.

Summary

  • NodeClassifier ("GCN") processes document graphs through stacked GcnSAGELayer modules to predict node labels exclusively.
  • EdgeClassifier ("EDGE") utilizes an MLPPredictor to classify relationships by combining endpoint node embeddings with edge features.
  • E2E Model ("E2E") combines both tasks using shared message-passing layers with separate node and edge prediction heads.
  • All three models share the InputProjector for multimodal feature alignment and instantiate via SetModel with their respective configuration files in configs/models/.

Frequently Asked Questions

Can the EdgeClassifier predict node labels?

No. The EdgeClassifier architecture lacks a node prediction head. As implemented in doc2graph/models/graphs.py lines 167-203, it only outputs edge logits through its MLPPredictor. For node classification, use the NodeClassifier or E2E model.

Do all three models use the same input projection mechanism?

Yes. All architectures utilize the shared InputProjector (lines 250-270 in doc2graph/models/graphs.py) to map text chunks, visual features, and other modalities into a common hidden representation before message-passing begins.

How does the E2E model handle simultaneous predictions?

The E2E model runs a single GcnSAGELayer for message-passing, then splits the computation into two heads: a node-head using nn.Linear with LayerNorm for node classification, and an edge-head using MLPPredictor_E2E that incorporates edge_pred_features for relationship classification. Both outputs are returned in a single forward pass.

Where are the model hyperparameters defined?

Hyperparameters for each architecture are stored in separate YAML configuration files within configs/models/. The gcn.yaml configures the NodeClassifier, edge.yaml configures the EdgeClassifier, and e2e.yaml configures the joint model. These files specify parameters like num_layers, hidden_dim, and projection settings.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →