public abstract class BaseOutputLayer<LayerConfT extends BaseOutputLayer> extends BaseLayer<LayerConfT> implements Serializable, IOutputLayer
Layer.TrainingMode, Layer.Type
Modifier and Type | Field and Description |
---|---|
protected org.nd4j.linalg.api.ndarray.INDArray |
inputMaskArray |
protected MaskState |
inputMaskArrayState |
protected org.nd4j.linalg.api.ndarray.INDArray |
labels |
gradient, gradientsFlattened, gradientViews, optimizer, params, paramsFlattened, score, weightNoiseParams
cacheMode, conf, dropoutApplied, dropoutMask, epochCount, index, input, iterationCount, maskArray, maskState, preOutput, trainingListeners
Constructor and Description |
---|
BaseOutputLayer(NeuralNetConfiguration conf) |
BaseOutputLayer(NeuralNetConfiguration conf,
org.nd4j.linalg.api.ndarray.INDArray input) |
Modifier and Type | Method and Description |
---|---|
org.nd4j.linalg.api.ndarray.INDArray |
activate(org.nd4j.linalg.api.ndarray.INDArray input,
boolean training,
LayerWorkspaceMgr workspaceMgr)
Perform forward pass and return the activations array with the specified input
|
protected void |
applyMask(org.nd4j.linalg.api.ndarray.INDArray to) |
org.nd4j.linalg.primitives.Pair<Gradient,org.nd4j.linalg.api.ndarray.INDArray> |
backpropGradient(org.nd4j.linalg.api.ndarray.INDArray epsilon,
LayerWorkspaceMgr workspaceMgr)
Calculate the gradient relative to the error in the next layer
|
void |
clear()
Clear input
|
void |
computeGradientAndScore(LayerWorkspaceMgr workspaceMgr)
Update the score
|
double |
computeScore(double fullNetworkL1,
double fullNetworkL2,
boolean training,
LayerWorkspaceMgr workspaceMgr)
Compute score after labels and input have been set.
|
org.nd4j.linalg.api.ndarray.INDArray |
computeScoreForExamples(double fullNetworkL1,
double fullNetworkL2,
LayerWorkspaceMgr workspaceMgr)
Compute the score for each example individually, after labels and input have been set.
|
double |
f1Score(org.nd4j.linalg.dataset.api.DataSet data)
Sets the input and labels and returns a score for the prediction
wrt true labels
|
double |
f1Score(org.nd4j.linalg.api.ndarray.INDArray examples,
org.nd4j.linalg.api.ndarray.INDArray labels)
Returns the f1 score for the given examples.
|
void |
fit(org.nd4j.linalg.dataset.api.DataSet data)
Fit the model
|
void |
fit(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter)
Train the model based on the datasetiterator
|
void |
fit(org.nd4j.linalg.api.ndarray.INDArray input,
org.nd4j.linalg.api.ndarray.INDArray labels)
Fit the model
|
void |
fit(org.nd4j.linalg.api.ndarray.INDArray examples,
int[] labels)
Fit the model
|
void |
fit(org.nd4j.linalg.api.ndarray.INDArray data,
LayerWorkspaceMgr workspaceMgr)
Fit the model to the given data
|
org.nd4j.linalg.api.ndarray.INDArray |
getLabels()
Get the labels array previously set with
IOutputLayer.setLabels(INDArray) |
protected abstract org.nd4j.linalg.api.ndarray.INDArray |
getLabels2d(LayerWorkspaceMgr workspaceMgr,
ArrayType arrayType) |
Gradient |
gradient()
Gets the gradient from one training iteration
|
org.nd4j.linalg.primitives.Pair<Gradient,Double> |
gradientAndScore()
Get the gradient and score
|
boolean |
hasBias()
Does this layer have no bias term? Many layers (dense, convolutional, output, embedding) have biases by
default, but no-bias versions are possible via configuration
|
boolean |
isPretrainLayer()
Returns true if the layer can be trained in an unsupervised/pretrain manner (AE, VAE, etc)
|
org.nd4j.linalg.api.ndarray.INDArray |
labelProbabilities(org.nd4j.linalg.api.ndarray.INDArray examples)
Returns the probabilities for each label
for each example row wise
|
boolean |
needsLabels()
Returns true if labels are required
for this output layer
|
int |
numLabels()
Returns the number of possible labels
|
List<String> |
predict(org.nd4j.linalg.dataset.api.DataSet dataSet)
Return predicted label names
|
int[] |
predict(org.nd4j.linalg.api.ndarray.INDArray input)
Returns the predictions for each example in the dataset
|
protected org.nd4j.linalg.api.ndarray.INDArray |
preOutput2d(boolean training,
LayerWorkspaceMgr workspaceMgr) |
void |
setLabels(org.nd4j.linalg.api.ndarray.INDArray labels)
Set the labels array for this output layer
|
protected void |
setScoreWithZ(org.nd4j.linalg.api.ndarray.INDArray z) |
accumulateScore, activate, calcL1, calcL2, clearNoiseWeightParams, clone, fit, getGradientsViewArray, getOptimizer, getParam, getParamWithNoise, initParams, layerConf, numParams, params, paramTable, paramTable, preOutput, score, setBackpropGradientsViewArray, setParam, setParams, setParams, setParamsViewArray, setParamTable, toString, transpose, update, update
addListeners, applyConstraints, applyDropOutIfNecessary, assertInputSet, batchSize, conf, feedForwardMaskArray, getIndex, getInput, getInputMiniBatchSize, getListeners, getMaskArray, init, input, layerId, numParams, setCacheMode, setConf, setIndex, setInput, setInputMiniBatchSize, setListeners, setListeners, setMaskArray, type, validateInput
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
activate, calcL1, calcL2, clearNoiseWeightParams, clone, feedForwardMaskArray, getEpochCount, getIndex, getInputMiniBatchSize, getIterationCount, getListeners, getMaskArray, setCacheMode, setEpochCount, setIndex, setInput, setInputMiniBatchSize, setIterationCount, setListeners, setListeners, setMaskArray, transpose, type
accumulateScore, addListeners, applyConstraints, batchSize, conf, fit, getGradientsViewArray, getOptimizer, getParam, init, initParams, input, numParams, numParams, params, paramTable, paramTable, score, setBackpropGradientsViewArray, setConf, setParam, setParams, setParamsViewArray, setParamTable, update, update, validateInput
protected org.nd4j.linalg.api.ndarray.INDArray labels
protected org.nd4j.linalg.api.ndarray.INDArray inputMaskArray
protected MaskState inputMaskArrayState
public BaseOutputLayer(NeuralNetConfiguration conf)
public BaseOutputLayer(NeuralNetConfiguration conf, org.nd4j.linalg.api.ndarray.INDArray input)
public double computeScore(double fullNetworkL1, double fullNetworkL2, boolean training, LayerWorkspaceMgr workspaceMgr)
computeScore
in interface IOutputLayer
fullNetworkL1
- L1 regularization term for the entire networkfullNetworkL2
- L2 regularization term for the entire networktraining
- whether score should be calculated at train or test time (this affects things like application of
dropout, etc)public boolean needsLabels()
IOutputLayer
needsLabels
in interface IOutputLayer
public org.nd4j.linalg.api.ndarray.INDArray computeScoreForExamples(double fullNetworkL1, double fullNetworkL2, LayerWorkspaceMgr workspaceMgr)
computeScoreForExamples
in interface IOutputLayer
fullNetworkL1
- L1 regularization term for the entire network (or, 0.0 to not include regularization)fullNetworkL2
- L2 regularization term for the entire network (or, 0.0 to not include regularization)public void computeGradientAndScore(LayerWorkspaceMgr workspaceMgr)
Model
computeGradientAndScore
in interface Model
computeGradientAndScore
in class BaseLayer<LayerConfT extends BaseOutputLayer>
protected void setScoreWithZ(org.nd4j.linalg.api.ndarray.INDArray z)
setScoreWithZ
in class BaseLayer<LayerConfT extends BaseOutputLayer>
public org.nd4j.linalg.primitives.Pair<Gradient,Double> gradientAndScore()
Model
gradientAndScore
in interface Model
gradientAndScore
in class AbstractLayer<LayerConfT extends BaseOutputLayer>
public org.nd4j.linalg.primitives.Pair<Gradient,org.nd4j.linalg.api.ndarray.INDArray> backpropGradient(org.nd4j.linalg.api.ndarray.INDArray epsilon, LayerWorkspaceMgr workspaceMgr)
Layer
backpropGradient
in interface Layer
backpropGradient
in class BaseLayer<LayerConfT extends BaseOutputLayer>
epsilon
- w^(L+1)*delta^(L+1). Or, equiv: dC/da, i.e., (dC/dz)*(dz/da) = dC/da, where C
is cost function a=sigma(z) is activation.workspaceMgr
- Workspace managerArrayType.ACTIVATION_GRAD
workspace via the workspace managerpublic Gradient gradient()
gradient
in interface Model
gradient
in class BaseLayer<LayerConfT extends BaseOutputLayer>
public org.nd4j.linalg.api.ndarray.INDArray activate(org.nd4j.linalg.api.ndarray.INDArray input, boolean training, LayerWorkspaceMgr workspaceMgr)
Layer
activate
in interface Layer
activate
in class AbstractLayer<LayerConfT extends BaseOutputLayer>
input
- the input to usetraining
- train or test modeworkspaceMgr
- Workspace manager.ArrayType.ACTIVATIONS
workspace via the workspace managerpublic double f1Score(org.nd4j.linalg.dataset.api.DataSet data)
f1Score
in interface Classifier
data
- the data to scorepublic double f1Score(org.nd4j.linalg.api.ndarray.INDArray examples, org.nd4j.linalg.api.ndarray.INDArray labels)
f1Score
in interface Classifier
examples
- te the examples to classify (one example in each row)labels
- the true labelspublic int numLabels()
numLabels
in interface Classifier
public void fit(org.nd4j.linalg.dataset.api.iterator.DataSetIterator iter)
Classifier
fit
in interface Classifier
iter
- the iterator to train onpublic int[] predict(org.nd4j.linalg.api.ndarray.INDArray input)
predict
in interface Classifier
input
- the matrix to predictpublic List<String> predict(org.nd4j.linalg.dataset.api.DataSet dataSet)
predict
in interface Classifier
dataSet
- to predictpublic org.nd4j.linalg.api.ndarray.INDArray labelProbabilities(org.nd4j.linalg.api.ndarray.INDArray examples)
labelProbabilities
in interface Classifier
examples
- the examples to classify (one example in each row)public void fit(org.nd4j.linalg.api.ndarray.INDArray input, org.nd4j.linalg.api.ndarray.INDArray labels)
fit
in interface Classifier
input
- the examples to classify (one example in each row)labels
- the example labels(a binary outcome matrix)public void fit(org.nd4j.linalg.dataset.api.DataSet data)
fit
in interface Classifier
data
- the data to train onpublic void fit(org.nd4j.linalg.api.ndarray.INDArray examples, int[] labels)
fit
in interface Classifier
examples
- the examples to classify (one example in each row)labels
- the labels for each example (the number of labels must matchpublic void clear()
Model
clear
in interface Model
clear
in class BaseLayer<LayerConfT extends BaseOutputLayer>
public void fit(org.nd4j.linalg.api.ndarray.INDArray data, LayerWorkspaceMgr workspaceMgr)
fit
in interface Model
fit
in class BaseLayer<LayerConfT extends BaseOutputLayer>
data
- the data to fit the model topublic org.nd4j.linalg.api.ndarray.INDArray getLabels()
IOutputLayer
IOutputLayer.setLabels(INDArray)
getLabels
in interface IOutputLayer
public void setLabels(org.nd4j.linalg.api.ndarray.INDArray labels)
IOutputLayer
setLabels
in interface IOutputLayer
labels
- Labels array to setprotected org.nd4j.linalg.api.ndarray.INDArray preOutput2d(boolean training, LayerWorkspaceMgr workspaceMgr)
protected void applyMask(org.nd4j.linalg.api.ndarray.INDArray to)
applyMask
in class AbstractLayer<LayerConfT extends BaseOutputLayer>
protected abstract org.nd4j.linalg.api.ndarray.INDArray getLabels2d(LayerWorkspaceMgr workspaceMgr, ArrayType arrayType)
public boolean isPretrainLayer()
Layer
isPretrainLayer
in interface Layer
public boolean hasBias()
BaseLayer
hasBias
in class BaseLayer<LayerConfT extends BaseOutputLayer>
Copyright © 2018. All rights reserved.