双线性 ¶
-
class torch.nn.Bilinear(in1_features, in2_features, out_features, bias=True, device=None, dtype=None)[source][source]
对传入数据进行双线性变换: y=x1TAx2+b 。
- 参数:
in1_features (int) – 每个第一个输入样本的大小
in2_features (int) – 每个第二个输入样本的大小
out_features (int) – 每个输出样本的大小
bias (bool) – 如果设置为 False
,则层将不会学习加性偏置。默认: True
- 形状:
Input1: (∗,Hin1) 其中 Hin1=in1_features 和 ∗ 表示包括零在内的任意数量的额外维度。除了输入的最后维度之外的所有维度都应该相同。
输入 2: (∗,Hin2) 其中 Hin2=in2_features
输出: (∗,Hout) 其中 Hout=out_features 以及所有维度除了最后一个都与输入形状相同。
- 变量:
weight (torch.Tensor) – 该模块的可学习权重,形状为 (out_features,in1_features,in2_features) 。值从 U(−k,k) 初始化,其中 k=in1_features1
bias – 该模块的可学习偏置,形状为 (out_features) 。如果 bias
是 True
,则值从 U(−k,k) 初始化,其中 k=in1_features1
示例:
>>> m = nn.Bilinear(20, 30, 40)
>>> input1 = torch.randn(128, 20)
>>> input2 = torch.randn(128, 30)
>>> output = m(input1, input2)
>>> print(output.size())
torch.Size([128, 40])