Search in sources :

Example 1 with AdaGrad

use of org.nd4j.linalg.learning.AdaGrad in project deeplearning4j by deeplearning4j.

the class BarnesHutTsne method update.

@Override
public void update(INDArray gradient, String paramType) {
    INDArray yGrads = gradient;
    gains = gains.add(.2).muli(sign(yGrads)).neqi(sign(yIncs)).addi(gains.mul(0.8).muli(sign(yGrads)).neqi(sign(yIncs)));
    BooleanIndexing.applyWhere(gains, Conditions.lessThan(minGain), new Value(minGain));
    INDArray gradChange = gains.mul(yGrads);
    if (useAdaGrad) {
        if (adaGrad == null)
            adaGrad = new AdaGrad();
        gradChange = adaGrad.getGradient(gradChange, 0);
    } else
        gradChange.muli(learningRate);
    yIncs.muli(momentum).subi(gradChange);
    Y.addi(yIncs);
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) Value(org.nd4j.linalg.indexing.functions.Value) AdaGrad(org.nd4j.linalg.learning.AdaGrad)

Example 2 with AdaGrad

use of org.nd4j.linalg.learning.AdaGrad in project deeplearning4j by deeplearning4j.

the class GloVe method configure.

@Override
public void configure(@NonNull VocabCache<T> vocabCache, @NonNull WeightLookupTable<T> lookupTable, @NonNull VectorsConfiguration configuration) {
    this.vocabCache = vocabCache;
    this.lookupTable = lookupTable;
    this.configuration = configuration;
    this.syn0 = ((InMemoryLookupTable<T>) lookupTable).getSyn0();
    this.vectorLength = configuration.getLayersSize();
    if (this.learningRate == 0.0d)
        this.learningRate = configuration.getLearningRate();
    weightAdaGrad = new AdaGrad(new int[] { this.vocabCache.numWords() + 1, vectorLength }, learningRate);
    bias = Nd4j.create(syn0.rows());
    biasAdaGrad = new AdaGrad(bias.shape(), this.learningRate);
    //  maxmemory = Runtime.getRuntime().maxMemory() - (vocabCache.numWords() * vectorLength * 2 * 8);
    log.info("GloVe params: {Max Memory: [" + maxmemory + "], Learning rate: [" + this.learningRate + "], Alpha: [" + alpha + "], xMax: [" + xMax + "], Symmetric: [" + symmetric + "], Shuffle: [" + shuffle + "]}");
}
Also used : AdaGrad(org.nd4j.linalg.learning.AdaGrad)

Example 3 with AdaGrad

use of org.nd4j.linalg.learning.AdaGrad in project deeplearning4j by deeplearning4j.

the class GloveWeightLookupTable method resetWeights.

@Override
public void resetWeights(boolean reset) {
    if (rng == null)
        this.rng = Nd4j.getRandom();
    //note the +2 which is the unk vocab word and the bias
    if (syn0 == null || reset) {
        syn0 = Nd4j.rand(new int[] { vocab.numWords() + 1, vectorLength }, rng).subi(0.5).divi((double) vectorLength);
        INDArray randUnk = Nd4j.rand(1, vectorLength, rng).subi(0.5).divi(vectorLength);
        putVector(Word2Vec.DEFAULT_UNK, randUnk);
    }
    if (weightAdaGrad == null || reset) {
        weightAdaGrad = new AdaGrad(new int[] { vocab.numWords() + 1, vectorLength }, lr.get());
    }
    //right after unknown
    if (bias == null || reset)
        bias = Nd4j.create(syn0.rows());
    if (biasAdaGrad == null || reset) {
        biasAdaGrad = new AdaGrad(bias.shape(), lr.get());
    }
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) AdaGrad(org.nd4j.linalg.learning.AdaGrad)

Aggregations

AdaGrad (org.nd4j.linalg.learning.AdaGrad)3 INDArray (org.nd4j.linalg.api.ndarray.INDArray)2 Value (org.nd4j.linalg.indexing.functions.Value)1