SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2605.16527 · 2026

Hypergraph Pattern Machine: Compositional Tokenization for Higher-Order Interactions

Pietro Liò, Fang Wu, Yanfang Ye, Xiangru Tang, Sheng Wang, Zehong Wang, Tianyi Ma, Kyrie Zhao

arXiv · PDF · Open in the Atlas

Code that ran

3 of 4 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 0 failures of our instrument; 1 no recorded run), measured 2026-11-23; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2605.16527.json · badge: /api/ran/2605.16527.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
KryieZhao/HGPM community
Papers with Code archive
3 ran · 1 no recorded run
FunctionStatusWhere it lives
AttentionPool Ran
ran on a synthesized input
KryieZhao/HGPM/HGPM/model/graph/hgpm.py
code served (permissive licence) · get_code("0c41b67a56dcb9cd")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 2, dtype family float, shape (2, 8) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

class AttentionPool(nn.Module):

    def __init__(self, hidden_dim: int) -> None:
        super().__init__()
        self.scorer = nn.Sequential(nn.Linear(hidden_dim, hidden_dim // 2), nn.Tanh(), nn.Linear(hidden_dim // 2, 1))

    def forward(self, hidden: torch.Tensor, seq_mask: torch.Tensor) -> torch.Tensor:
        valid = seq_mask > 0
        scores = self.scorer(hidden).squeeze(-1)
        scores = scores.masked_fill(~valid, float('-inf'))
        no_valid = ~valid.any(dim=1)
        if no_valid.any():
            scores = scores.masked_fill(no_valid.unsqueeze(-1), 0.0)
        weights = torch.softmax(scores, dim=1).unsqueeze(-1)
        return (hidden * weights).sum(dim=1)


INIT_ARGS = {
    'hidden_dim': 8
}

ARGS = {
    'hidden': torch.randn(2, 5, 8),
    'seq_mask': torch.tensor([[1, 1, 1, 0, 0], [1, 1, 1, 1, 1]])
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 8) — shape (2, 8) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
RelationAwareBiasedSelfAttention Ran
ran on a synthesized input
KryieZhao/HGPM/HGPM/model/graph/hgpm.py
code served (permissive licence) · get_code("7c37076dcd3ea67e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float, shape (2, 3, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

class RelationAwareBiasedSelfAttention(nn.Module):

    def __init__(self, hidden_dim: int, num_heads: int, dropout: float) -> None:
        super().__init__()
        if hidden_dim % num_heads != 0:
            raise ValueError('hidden_dim must be divisible by num_heads')
        self.hidden_dim = hidden_dim
        self.num_heads = num_heads
        self.head_dim = hidden_dim // num_heads
        self.scale = self.head_dim ** (-0.5)
        self.q_proj = nn.Linear(hidden_dim, hidden_dim)
        self.k_proj = nn.Linear(hidden_dim, hidden_dim)
        self.v_proj = nn.Linear(hidden_dim, hidden_dim)
        self.out_proj = nn.Linear(hidden_dim, hidden_dim)
        self.dropout = nn.Dropout(dropout)

    def forward(self, hidden: torch.Tensor, seq_mask: torch.Tensor, attn_bias: torch.Tensor) -> torch.Tensor:
        batch_size, seq_len, _ = hidden.shape
        q = self.q_proj(hidden).view(batch_size, seq_len, self.num_heads, self.head_dim).transpose(1, 2)
        k = self.k_proj(hidden).view(batch_size, seq_len, self.num_heads, self.head_dim).transpose(1, 2)
        v = self.v_proj(hidden).view(batch_size, seq_len, self.num_heads, self.head_dim).transpose(1, 2)
        scores = torch.matmul(q, k.transpose(-2, -1)) * self.scale
        scores = scores + attn_bias
        valid = seq_mask > 0
        key_mask = ~valid.unsqueeze(1).unsqueeze(2)
        scores = scores.masked_fill(key_mask, float('-inf'))
        no_valid = ~valid.any(dim=1)
        if no_valid.any():
            scores[no_valid] = 0.0
        attn = torch.softmax(scores, dim=-1)
        attn = self.dropout(attn)
        context = torch.matmul(attn, v)
        context = context.transpose(1, 2).contiguous().view(batch_size, seq_len, self.hidden_dim)
        return self.out_proj(context)


INIT_ARGS = {
    'hidden_dim': 4,
    'num_heads': 2,
    'dropout': 0.1,
}

ARGS = {
    'hidden': torch.randn(2, 3, 4),
    'seq_mask': torch.tensor([[1, 1, 0], [1, 1, 1]], dtype=torch.long),
    'attn_bias': torch.zeros(2, 2, 3, 3),
}

if __name__ == '__main__':
    model = RelationAwareBiasedSelfAttention(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output: {output}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
RelationAwareTransformerBlock Ran
ran on a synthesized input
KryieZhao/HGPM/HGPM/model/graph/hgpm.py
code served (permissive licence) · get_code("28346b0d97e485e0")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float, shape (2, 3, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

class RelationAwareBiasedSelfAttention(nn.Module):

    def __init__(self, hidden_dim: int, num_heads: int, dropout: float) -> None:
        super().__init__()
        if hidden_dim % num_heads != 0:
            raise ValueError('hidden_dim must be divisible by num_heads')
        self.hidden_dim = hidden_dim
        self.num_heads = num_heads
        self.head_dim = hidden_dim // num_heads
        self.scale = self.head_dim ** (-0.5)
        self.q_proj = nn.Linear(hidden_dim, hidden_dim)
        self.k_proj = nn.Linear(hidden_dim, hidden_dim)
        self.v_proj = nn.Linear(hidden_dim, hidden_dim)
        self.out_proj = nn.Linear(hidden_dim, hidden_dim)
        self.dropout = nn.Dropout(dropout)

    def forward(self, hidden: torch.Tensor, seq_mask: torch.Tensor, attn_bias: torch.Tensor) -> torch.Tensor:
        batch_size, seq_len, _ = hidden.shape
        q = self.q_proj(hidden).view(batch_size, seq_len, self.num_heads, self.head_dim).transpose(1, 2)
        k = self.k_proj(hidden).view(batch_size, seq_len, self.num_heads, self.head_dim).transpose(1, 2)
        v = self.v_proj(hidden).view(batch_size, seq_len, self.num_heads, self.head_dim).transpose(1, 2)
        scores = torch.matmul(q, k.transpose(-2, -1)) * self.scale
        scores = scores + attn_bias
        valid = seq_mask > 0
        key_mask = ~valid.unsqueeze(1).unsqueeze(2)
        scores = scores.masked_fill(key_mask, float('-inf'))
        no_valid = ~valid.any(dim=1)
        if no_valid.any():
            scores[no_valid] = 0.0
        attn = torch.softmax(scores, dim=-1)
        attn = self.dropout(attn)
        context = torch.matmul(attn, v)
        context = context.transpose(1, 2).contiguous().view(batch_size, seq_len, self.hidden_dim)
        return self.out_proj(context)

class RelationAwareTransformerBlock(nn.Module):

    def __init__(self, hidden_dim: int, num_heads: int, dropout: float) -> None:
        super().__init__()
        self.norm1 = nn.LayerNorm(hidden_dim)
        self.attn = RelationAwareBiasedSelfAttention(hidden_dim=hidden_dim, num_heads=num_heads, dropout=dropout)
        self.drop1 = nn.Dropout(dropout)
        self.norm2 = nn.LayerNorm(hidden_dim)
        self.ffn = nn.Sequential(nn.Linear(hidden_dim, hidden_dim * 4), nn.GELU(), nn.Dropout(dropout), nn.Linear(hidden_dim * 4, hidden_dim))
        self.drop2 = nn.Dropout(dropout)

    def forward(self, hidden: torch.Tensor, seq_mask: torch.Tensor, attn_bias: torch.Tensor) -> torch.Tensor:
        hidden = hidden + self.drop1(self.attn(self.norm1(hidden), seq_mask, attn_bias))
        hidden = hidden + self.drop2(self.ffn(self.norm2(hidden)))
        return hidden * seq_mask.unsqueeze(-1).to(hidden.dtype)


INIT_ARGS = {
    'hidden_dim': 4,
    'num_heads': 2,
    'dropout': 0.1,
}

ARGS = {
    'hidden': torch.randn(2, 3, 4),
    'seq_mask': torch.ones(2, 3),
    'attn_bias': torch.zeros(2, 2, 3, 3),
}

if __name__ == '__main__':
    model = RelationAwareTransformerBlock(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: {ARGS['hidden'].shape}")
    assert output.shape == ARGS['hidden'].shape, f"Shape mismatch: {output.shape} vs {ARGS['hidden'].shape}"
    print("Test passed!")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
HGPMGraphModel Not yet run
unverified (harvested, no recorded run)
KryieZhao/HGPM/HGPM/model/graph/hgpm.py
code served (permissive licence) · get_code("440763be37d40a3e")
How it ran

no invocation recorded.

Also present in other papers' code

Of 4 samples lifted from this paper's linked repositories, 4 carry a function identity and 0 do not. Of the 4 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 4 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Hypergraphs model higher-order relations that drive real-world decisions, from drug prescriptions to recommendations. A central structural signal in such data, beyond what pairwise relations can express, is interaction compositionality: whether a higher-order relation is compositional, emergent, or inhibitory with respect to its observed or unobserved sets. In polypharmacy, the regime decides whether a drug should be dropped, kept, or excluded: a compositional drug triple can be safely simplified, an emergent triple requires all drugs jointly, and an inhibitory triple flags a drug that disrupts an existing interaction. However, existing hypergraph learning methods, which merely propagate messages over observed hyperedges, leave this compositional signal unmodeled, allowing dangerous drug combinations to slip through and be misclassified. To this end, we propose the Hypergraph Pattern Machine (HGPM), shifting the paradigm from message passing to learning the compositional pattern of subsets. It tokenizes compositional subsets, organizes them in an inclusion DAG, and trains an inclusion-aware Transformer under masked reconstruction. On ten hypergraph benchmarks, HGPM matches or exceeds state-of-the-art methods. Notably, in a real adverse-event prediction case, HGPM correctly identifies the drug addition that inhibits the side effect among feature-identical candidates, a discrimination existing methods cannot make. The code and data are in https://github.com/KryieZhao/HGPM.git. [50,11] makes this concrete. A clinician evaluating multi-drug regimens needs to distinguish three patterns. If both a pair and the full triple of drugs are effective, the third drug merely compounds an existing effect, and the prescription can be simplified. If only the full triple is effective while no smaller subset is, the three drugs are jointly required, and none can be dropped. If a pair is effective but adding the third drug eliminates the effect, the third drug actively disrupts the existing interaction and should be excluded. Each pattern points to a different prescription.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2605.16527")
get_code_for_paper("2605.16527")
have("2605.16527")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2605.16527.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2605.16527.svg)](https://syntology.ai/paper/2605.16527)

Connect an agent — have() is free.