Search in sources :

Example 6 with SimpleTensor

use of edu.stanford.nlp.neural.SimpleTensor in project CoreNLP by stanfordnlp.

the class SentimentCostAndGradient method scaleAndRegularizeTensor.

private static double scaleAndRegularizeTensor(TwoDimensionalMap<String, String, SimpleTensor> derivatives, TwoDimensionalMap<String, String, SimpleTensor> currentMatrices, double scale, double regCost) {
    // the regularization cost
    double cost = 0.0;
    for (TwoDimensionalMap.Entry<String, String, SimpleTensor> entry : currentMatrices) {
        SimpleTensor D = derivatives.get(entry.getFirstKey(), entry.getSecondKey());
        D = D.scale(scale).plus(entry.getValue().scale(regCost));
        derivatives.put(entry.getFirstKey(), entry.getSecondKey(), D);
        cost += entry.getValue().elementMult(entry.getValue()).elementSum() * regCost / 2.0;
    }
    return cost;
}
Also used : SimpleTensor(edu.stanford.nlp.neural.SimpleTensor) TwoDimensionalMap(edu.stanford.nlp.util.TwoDimensionalMap)

Aggregations

SimpleTensor (edu.stanford.nlp.neural.SimpleTensor)6 SimpleMatrix (org.ejml.simple.SimpleMatrix)4 CoreLabel (edu.stanford.nlp.ling.CoreLabel)1 RNNCoreAnnotations (edu.stanford.nlp.neural.rnn.RNNCoreAnnotations)1 Tree (edu.stanford.nlp.trees.Tree)1 TwoDimensionalMap (edu.stanford.nlp.util.TwoDimensionalMap)1 File (java.io.File)1 Random (java.util.Random)1