Ejemplo 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)
Ejemplo 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')
Ejemplo 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)
Ejemplo 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
Ejemplo 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
Ejemplo 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)
Ejemplo 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)
Ejemplo 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')