Evaluate a multilayer perceptron using the supplied weight matrices and bias vectors in forward order. Apply tanh after every layer, including the final layer.
hℓ=tanh(Wℓhℓ−1+bℓ)Here h is a layer's output, the initial h is inputs, W is its weight matrix, b is its bias vector, and the layer index runs through the supplied lists. Each weight row represents one output neuron.
Return a tuple containing the final output tensor and a Python list of every layer's output tensor in forward order. All output tensors are one-dimensional and preserve the common input dtype and device. The list includes the final output.
Input: inputs = [1,2], weights = [[[1,0],[0,1]]], biases = [[0,0]]
Output: ([0.761594, 0.964028], [[0.761594, 0.964028]])
Explanation: The identity weight matrix leaves the inputs unchanged before tanh; the trace contains this single layer’s output.
Input: inputs = [1], weights = [[[1],[-1]],[[1,1]]], biases = [[0,0],[0]]
Output: ([0.0], [[0.761594, -0.761594], [0.0]])
Input: inputs = [10], weights = [[[2]]], biases = [[0]]
Output: ([1.0], [[1.0]])
torch.mv computes a matrix-vector product.
zip pairs each layer’s weight matrix with its bias vector.
list.append can retain each layer output without flattening it.
Accepts: array
Accepts: array
Accepts: array
Evaluate a multilayer perceptron using the supplied weight matrices and bias vectors in forward order. Apply tanh after every layer, including the final layer.
hℓ=tanh(Wℓhℓ−1+bℓ)Here h is a layer's output, the initial h is inputs, W is its weight matrix, b is its bias vector, and the layer index runs through the supplied lists. Each weight row represents one output neuron.
Return a tuple containing the final output tensor and a Python list of every layer's output tensor in forward order. All output tensors are one-dimensional and preserve the common input dtype and device. The list includes the final output.
Input: inputs = [1,2], weights = [[[1,0],[0,1]]], biases = [[0,0]]
Output: ([0.761594, 0.964028], [[0.761594, 0.964028]])
Explanation: The identity weight matrix leaves the inputs unchanged before tanh; the trace contains this single layer’s output.
Input: inputs = [1], weights = [[[1],[-1]],[[1,1]]], biases = [[0,0],[0]]
Output: ([0.0], [[0.761594, -0.761594], [0.0]])
Input: inputs = [10], weights = [[[2]]], biases = [[0]]
Output: ([1.0], [[1.0]])
torch.mv computes a matrix-vector product.
zip pairs each layer’s weight matrix with its bias vector.
list.append can retain each layer output without flattening it.
Accepts: array
Accepts: array
Accepts: array