espnet.nets.chainer_backend.deterministic_embed_id.EmbedIDFunction
espnet.nets.chainer_backend.deterministic_embed_id.EmbedIDFunction
class espnet.nets.chainer_backend.deterministic_embed_id.EmbedIDFunction(ignore_label=None)
Bases: FunctionNode
backward(indexes, grad_outputs)
Computes gradients w.r.t. specified inputs given output gradients.
This method is used to compute one step of the backpropagation corresponding to the forward computation of this function node. Given the gradients w.r.t. output variables, this method computes the gradients w.r.t. specified input variables. Note that this method does not need to compute any input gradients not specified by target_input_indices
.
Unlike Function.backward()
, gradients are given as Variable
objects and this method itself has to return input gradients as Variable
objects. It enables the function node to return the input gradients with the full computational history, in which case it supports differentiable backpropagation or higher-order differentiation.
The default implementation returns None
s, which means the function is not differentiable.
- Parameters:
- target_input_indexes (tuple of int) – Sorted indices of the input variables w.r.t. which the gradients are required. It is guaranteed that this tuple contains at least one element.
- grad_outputs (tuple of
Variable
s) – Gradients w.r.t. the output variables. If the gradient w.r.t. an output variable is not given, the corresponding element isNone
.
- Returns: Tuple of variables that represent the gradients w.r.t. specified input variables. The length of the tuple can be same as either
len(target_input_indexes)
or the number of inputs. In the latter case, the elements not specified bytarget_input_indexes
will be discarded.
SEE ALSO
backward_accumulate()
provides an alternative interface that allows you to implement the backward computation fused with the gradient accumulation.
check_type_forward(in_types)
Checks types of input data before forward propagation.
This method is called before forward()
and validates the types of input variables using the type checking utilities.
- Parameters:in_types (TypeInfoTuple) – The type information of input variables for
forward()
.
forward(inputs)
Computes the output arrays from the input arrays.
It delegates the procedure to forward_cpu()
or forward_gpu()
by default. Which of them this method selects is determined by the type of input arrays. Implementations of FunctionNode
must implement either CPU/GPU methods or this method.
- Parameters:inputs – Tuple of input array(s).
- Returns: Tuple of output array(s).
WARNING
Implementations of FunctionNode
must take care that the return value must be a tuple even if it returns only one array.