/** * Returns the key corresponding to this entry. * * @return the key corresponding to this entry * @throws IllegalStateException implementations may, but are not * required to, throw this exception if the entry has been * removed from the backing map. */ public Pair<K, T> getKey() { return new Pair<>(firstKey, secondKey); } }
public Pair<String, double[]> nextSentence() { int idx; if(this.rng == null) { idx = this.cursor++; } else { idx = this.order[this.cursor++]; } return new Pair<>(this.documents.get(idx), this.labels.get(idx)); }
@Override public Pair<Double, INDArray> computeGradientAndScore(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask, boolean average) { return new Pair<>( computeScore(labels, preOutput, activationFn, mask, average), computeGradient(labels, preOutput, activationFn, mask)); }
@Override public Pair<Double, INDArray> computeGradientAndScore(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask, boolean average) { //TODO: probably a more efficient way to do this... return new Pair<>(computeScore(labels, preOutput, activationFn, mask, average), computeGradient(labels, preOutput, activationFn, mask)); }
@Override public Pair<Double, INDArray> computeGradientAndScore(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask, boolean average) { //TODO optimize return new Pair<>(computeScore(labels, preOutput, activationFn, mask, average), computeGradient(labels, preOutput, activationFn, mask)); }
@Override public Pair<Double, INDArray> computeGradientAndScore(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask, boolean average) { //TODO: probably a more efficient way to do this... return new Pair<>(computeScore(labels, preOutput, activationFn, mask, average), computeGradient(labels, preOutput, activationFn, mask)); }
@Override public Pair<Double, INDArray> computeGradientAndScore(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask, boolean average) { //TODO: probably a more efficient way to do this... return new Pair<>(computeScore(labels, preOutput, activationFn, mask, average), computeGradient(labels, preOutput, activationFn, mask)); }
@Override public Pair<Double, INDArray> computeGradientAndScore(INDArray labels, INDArray preOutput, IActivation activationFn, INDArray mask, boolean average) { //TODO: probably a more efficient way to do this... return new Pair<>(computeScore(labels, preOutput, activationFn, mask, average), computeGradient(labels, preOutput, activationFn, mask)); }
public static List<Pair<INDArray, String>> get4dPermutedWithShape(int seed, int... shape) { Nd4j.getRandom().setSeed(seed); int[] createdShape = {shape[1], shape[3], shape[2], shape[0]}; INDArray arr = Nd4j.rand(createdShape); INDArray permuted = arr.permute(3, 0, 2, 1); return Collections.singletonList(new Pair<>(permuted, "get4dPermutedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)")); }
public static List<Pair<INDArray, String>> get6dPermutedWithShape(int seed, int... shape) { Nd4j.getRandom().setSeed(seed); int[] createdShape = {shape[1], shape[4], shape[5], shape[3], shape[2], shape[0]}; INDArray arr = Nd4j.rand(createdShape); INDArray permuted = arr.permute(5, 0, 4, 3, 1, 2); return Collections.singletonList(new Pair<>(permuted, "get6dPermutedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)")); }
public static List<Pair<INDArray, String>> get6dReshapedWithShape(int seed, int... shape) { Nd4j.getRandom().setSeed(seed); int[] shape3d = {shape[0] * shape[2], shape[4] * shape[5], shape[1] * shape[3]}; INDArray array3d = Nd4j.rand(shape3d); INDArray array6d = array3d.reshape(ArrayUtil.toLongArray(shape)); return Collections.singletonList(new Pair<>(array6d, "get6dReshapedWithShape(" + seed + "," + Arrays.toString(shape) + ").get(0)")); }
@Override public Pair<INDArray, INDArray> backprop(INDArray in, INDArray epsilon) { INDArray dLdz = Nd4j.getExecutioner().execAndReturn(new HardSigmoidDerivative(in)); dLdz.muli(epsilon); return new Pair<>(dLdz, null); }
@Override public Pair<INDArray, INDArray> backprop(INDArray in, INDArray epsilon) { INDArray dLdz = Nd4j.getExecutioner().execAndReturn(new CubeDerivative(in)); dLdz.muli(epsilon); return new Pair<>(dLdz, null); }
@Override public Pair<INDArray, INDArray> backprop(INDArray in, INDArray epsilon) { INDArray dLdz = Nd4j.getExecutioner().execAndReturn(new RectifiedTanhDerivative(in)); dLdz.muli(epsilon); return new Pair<>(dLdz, null); }
@Override public Pair<INDArray, INDArray> backprop(INDArray in, INDArray epsilon) { INDArray dLdz = Nd4j.getExecutioner().execAndReturn(new RationalTanhDerivative(in)); dLdz.muli(epsilon); return new Pair<>(dLdz, null); }
@Override public Pair<INDArray, INDArray> backprop(INDArray in, INDArray epsilon) { INDArray dLdz = Nd4j.getExecutioner().execAndReturn(new SoftSignDerivative(in)); dLdz.muli(epsilon); return new Pair<>(dLdz, null); }
@Override public Pair<INDArray, INDArray> backprop(INDArray in, INDArray epsilon) { INDArray dLdz = Nd4j.getExecutioner().execAndReturn(new SwishDerivative(in)); dLdz.muli(epsilon); return new Pair<>(dLdz, null); }
public static Pair<INDArray, String> getTransposedMatrixWithShape(char ordering, int rows, int cols, int seed) { Nd4j.getRandom().setSeed(seed); INDArray out = Nd4j.linspace(1, rows * cols, rows * cols).reshape(ordering, cols, rows); return new Pair<>(out.transpose(), "getTransposedMatrixWithShape(" + rows + "," + cols + "," + seed + ")"); }
public static Pair<INDArray, String> getPermutedWithShape(char ordering, long rows, long cols, long seed) { Nd4j.getRandom().setSeed(seed); long len = rows * cols; INDArray arr = Nd4j.linspace(1, len, len).reshape(cols, rows); return new Pair<>(arr.permute(1, 0), "getPermutedWithShape(" + rows + "," + cols + "," + seed + ")"); }
@Override public Pair<INDArray, INDArray> backprop(INDArray in, INDArray epsilon) { INDArray dLdz = Nd4j.ones(in.shape()); BooleanIndexing.replaceWhere(dLdz, alpha, Conditions.lessThanOrEqual(0.0)); dLdz.muli(epsilon); return new Pair<>(dLdz, null); }