module = SparseLinear(inputDimension,outputDimension)

Applies a linear transformation to the incoming sparse data, i.e. y= Ax+b. The input tensor given in forward(input) must be a sparse vector represented as 2D tensor of the form torch.Tensor(N, 2) where the pairs represent indices and values. The SparseLinear layer is useful when the number of input dimensions is very large and the input data is sparse.

You can create a sparse linear layer in the following way:

 module= nn.SparseLinear(10000,2)  -- 10000 inputs, 2 outputs
The sparse linear module may be used as part of a larger network, and apart from the form of the input, SparseLinear operates in exactly the same way as the Linear layer.

A sparse input vector may be created as so..


 x=lab.new({1, 0.1},{2, 0.3},{10, 0.3},{31, 0.2})

 print(x)

  1.0000   0.1000
  2.0000   0.3000
 10.0000   0.3000
 31.0000   0.2000
[torch.Tensor of dimension 4x2]

The first column contains indices, the second column contains values in a a vector where all other elements are zeros. The indices should not exceed the stated dimesions of the input to the layer (10000 in the example).