Skip to content



   init_value = None, n_units = None, constant = False, sparse = False,
   n_active: Optional[int] = None, shape = None, dtype = None, cast = True, name = 'input'

Input Layer

An Input layer defines constant or dynamic inputs of a neural network model in TensorX.

An input layer has no inputs and is usable as a placeholder for Tensorflow Tensor or SparseTensor objects. An Input layer is stateful, which means that it can hold and output a given value until this value is changed.

import tensorx as tx
# assumes a shape [None,2]
x = tx.Input(n_units=2, constant=False)
v1 = x()


x.value = tf.ones([2,2])
v2 = x()


x.value = tf.ones([2,3])
# throws an exception because it expects a shape [None,2]

x2 = tx.Input(n_units=2, constant=True)


x2.value = tf.ones([2,2])
# throws ValueError: Cannot set the value of a constant Input Layer


  • when n_active is provided, Input layers are interpreted as representing binary sparse (one-hot)[] encoding and expects it's values to be of type tf.int64.

  • both Linear and Lookup layers are compatible with Input layers that output SparseTensor objects, representing one-hot encodings of categorical inputs.

  • SparseTensor value can be passed as an initial value.


  • init_value (Tensor) : initial value for Input layer, if given, it determines n_units
  • n_units (int or None) : number of output units for this layer.
  • n_active : number of active units <= n_units. If given, input is a Tensor with col indices
  • sparse (bool) : if true, expects the input value to be a SparseTensor.
  • shape (TensorShape) : expected input shape
  • dtype (tf.Dtype) : type for input values.
  • constant : if true, input value cannot be changed after Input is initialized.
  • name (str) : layer name
  • cast (bool) : if True tries to cast the input to the given dtype on value set


  • value (Union[Tensor,SparseTensor]) : if constant=True value cannot be set and an exception is raised













   *layers, name = None