@@ -0,0 +1,868 @@
+from torch import nn%0A%0A%0Aclass EltwiseSubEmbed(nn.Module):%0A    def __init__(self, num_features, nonlinearity='square'):%0A        super(EltwiseSubEmbed, self).__init__()%0A        self.nonlinearity = nonlinearity%0A        if nonlinearity is not None and nonlinearity not in %5B'square', 'abs'%5D:%0A            raise KeyError(%22Unknown nonlinearity:%22, nonlinearity)%0A        self.bn = nn.BatchNorm1d(num_features)%0A        self.bn.weight.data.fill_(1)%0A        self.bn.bias.data.zero_()%0A        self.classifier = nn.Linear(num_features, 2)%0A        self.classifier.weight.data.normal_(0, 0.001)%0A        self.classifier.bias.data.zero_()%0A%0A    def forward(self, x1, x2):%0A        x = x1 - x2%0A        if self.nonlinearity == 'square':%0A            x.pow_(2)%0A        elif self.nonlinearity == 'abs':%0A            x.abs_()%0A        x = self.bn(x)%0A        x = self.classifier(x)%0A        return x%0A

Add embedding module