Skip to content

PoolingByMultiheadAttention

PoolingByMultiheadAttention(
    channels: int,
    num_seed_points: int = 1,
    heads: int = 1,
    layer_norm: bool = True,
    dropout: float = 0.0,
)

Bases: Module

The Pooling by Multihead Attention (PMA) layer from the "Set Transformer" paper: \(\mathrm{PMA}(\mathbf{X}) = \mathrm{MAB}(\mathbf{S}, \mathrm{ReLU}(\mathbf{X}\mathbf{W}))\) for learnable seed points \(\mathbf{S}\).

Parameters:

Name Type Description Default
channels int

Size of each input sample.

required
num_seed_points int

Number of seed points. Default: 1

1
heads int

Number of attention heads. Default: 1

1
layer_norm bool

Whether to apply layer normalization. Default: True

True
dropout float

Dropout probability of the attention weights. Default: 0.0

0.0
Source code in mlx_graphs/nn/aggr/utils.py
def __init__(
    self,
    channels: int,
    num_seed_points: int = 1,
    heads: int = 1,
    layer_norm: bool = True,
    dropout: float = 0.0,
):
    super().__init__()
    self.lin = nn.Linear(channels, channels)
    self.seed = _xavier((1, num_seed_points, channels))
    self.mab = MultiheadAttentionBlock(channels, heads, layer_norm, dropout)

from mlx_graphs.nn.aggr import PoolingByMultiheadAttention · mlx_graphs/nn/aggr/utils.py