Skip to content

Input

source

Input(
   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()

[[0,0]]

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

[[1,1],
 [1,1]]

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()

[[0,0]]

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

Info

  • when n_active is provided, Input layers are interpreted as representing binary sparse (one-hot)[https://en.wikipedia.org/wiki/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.

Args

  • 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

Attributes

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

Methods:

.compute_shape

source

.compute_shape()

.init_state

source

.init_state()

.compute

source

.compute()

.reuse_with

source

.reuse_with(
   *layers, name = None
)