Esempio n. 1
0
 def feedback(self, outputs):
     assert self.output_dim == 0
     eye = tensor.eye(self.num_outputs)
     check_theano_variable(outputs, None, "int")
     output_shape = [outputs.shape[i]
                     for i in range(outputs.ndim)] + [self.feedback_dim]
     return eye[outputs.flatten()].reshape(output_shape)
Esempio n. 2
0
def test_check_theano_variable():
    check_theano_variable(None, 3, 'float')
    check_theano_variable([[1, 2]], 2, 'int')
    assert_raises(ValueError, check_theano_variable,
                  tensor.vector(), 2, 'float')
    assert_raises(ValueError, check_theano_variable,
                  tensor.vector(), 1, 'int')
Esempio n. 3
0
 def feedback(self, outputs):
     assert self.output_dim == 0
     eye = tensor.eye(self.num_outputs)
     check_theano_variable(outputs, None, "int")
     output_shape = [outputs.shape[i]
                     for i in range(outputs.ndim)] + [self.feedback_dim]
     return eye[outputs.flatten()].reshape(output_shape)
Esempio n. 4
0
 def apply(self, indices):
     """Perform lookup.
     Parameters
     ----------
     indices : :class:`~tensor.TensorVariable`
         The indices of interest. The dtype must be integer.
     Returns
     -------
     output : :class:`~tensor.TensorVariable`
         Representations for the indices of the query. Has :math:`k+1`
         dimensions, where :math:`k` is the number of dimensions of the
         `indices` parameter. The last dimension stands for the
         representation element.
     """
     check_theano_variable(indices, None, "int")
     output_shape = [indices.shape[i]
                     for i in range(indices.ndim)] + [self.dim]
     return self.W[indices.flatten()].reshape(output_shape) + self.b
Esempio n. 5
0
 def apply(self, indices):
     """Perform lookup.
     Parameters
     ----------
     indices : :class:`~tensor.TensorVariable`
         The indices of interest. The dtype must be integer.
     Returns
     -------
     output : :class:`~tensor.TensorVariable`
         Representations for the indices of the query. Has :math:`k+1`
         dimensions, where :math:`k` is the number of dimensions of the
         `indices` parameter. The last dimension stands for the
         representation element.
     """
     check_theano_variable(indices, None, "int")
     output_shape = [indices.shape[i]
                     for i in range(indices.ndim)] + [self.dim]
     return self.W[indices.flatten()].reshape(output_shape) + self.b
Esempio n. 6
0
 def apply(self, indices):
     check_theano_variable(indices, None, ("int", "uint"))
     output_shape = [indices.shape[i]
                     for i in range(indices.ndim)] + [self.dim]
     return self.W[indices.flatten()].reshape(output_shape)
Esempio n. 7
0
 def apply(self, indices):
     check_theano_variable(indices, None, ("int", "uint"))
     output_shape = [indices.shape[i]
                     for i in range(indices.ndim)] + [self.dim]
     return self.W[indices.flatten()].reshape(output_shape)
Esempio n. 8
0
def test_check_theano_variable():
    check_theano_variable(None, 3, 'float')
    check_theano_variable([[1, 2]], 2, 'int')
    assert_raises(ValueError, check_theano_variable, tensor.vector(), 2,
                  'float')
    assert_raises(ValueError, check_theano_variable, tensor.vector(), 1, 'int')