HeteroLinearΒΆ

class dgl.nn.pytorch.HeteroLinear(in_size, out_size, bias=True)[source]ΒΆ

Bases: torch.nn.modules.module.Module

Apply linear transformations on heterogeneous inputs.

Parameters
  • in_size (dict[key, int]) – Input feature size for heterogeneous inputs. A key can be a string or a tuple of strings.

  • out_size (int) – Output feature size.

  • bias (bool, optional) – If True, learns a bias term. Defaults: True.

Examples

>>> import dgl
>>> import torch
>>> from dgl.nn import HeteroLinear
>>> layer = HeteroLinear({'user': 1, ('user', 'follows', 'user'): 2}, 3)
>>> in_feats = {'user': torch.randn(2, 1), ('user', 'follows', 'user'): torch.randn(3, 2)}
>>> out_feats = layer(in_feats)
>>> print(out_feats['user'].shape)
torch.Size([2, 3])
>>> print(out_feats[('user', 'follows', 'user')].shape)
torch.Size([3, 3])
forward(feat)[source]ΒΆ

Forward function

Parameters

feat (dict[key, Tensor]) – Heterogeneous input features. It maps keys to features.

Returns

Transformed features.

Return type

dict[key, Tensor]