Input
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 typetf.int64
. -
both
Linear
andLookup
layers are compatible withInput
layers that outputSparseTensor
objects, representing one-hot encodings of categorical inputs. -
SparseTensor
value can be passed as an initial value.
Args
- init_value (
Tensor
) : initial value forInput
layer, if given, it determinesn_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 aSparseTensor
. - 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
]) : ifconstant=True
value cannot be set and an exception is raised
Methods:
.compute_shape
.compute_shape()
.init_state
.init_state()
.compute
.compute()
.reuse_with
.reuse_with(
*layers, name = None
)