private void primeNext() { K1 k1 = null; if (next != null) { k1 = next.getFirstKey(); } while (innerIterator == null || !innerIterator.hasNext()) { if (!outerIterator.hasNext()) { next = null; return; } Map.Entry<K1, Map<K2, V>> outerEntry = outerIterator.next(); k1 = outerEntry.getKey(); innerIterator = outerEntry.getValue().entrySet().iterator(); } Map.Entry<K2, V> innerEntry = innerIterator.next(); next = new Entry<>(k1, innerEntry.getKey(), innerEntry.getValue()); }
int numRows = entry.getValue().numRows(); int numCols = entry.getValue().numCols(); binaryW_dfsG.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(numRows, numCols)); binaryW_dfsB.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(numRows, numCols)); binaryScoreDerivativesG.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(1, numRows)); binaryScoreDerivativesB.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(1, numRows));
int numRows = entry.getValue().numRows(); int numCols = entry.getValue().numCols(); binaryW_dfsG.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(numRows, numCols)); binaryW_dfsB.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(numRows, numCols)); binaryScoreDerivativesG.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(1, numRows)); binaryScoreDerivativesB.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(1, numRows));
int numRows = entry.getValue().numRows(); int numCols = entry.getValue().numCols(); binaryW_dfsG.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(numRows, numCols)); binaryW_dfsB.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(numRows, numCols)); binaryScoreDerivativesG.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(1, numRows)); binaryScoreDerivativesB.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(1, numRows));
int numRows = entry.getValue().numRows(); int numCols = entry.getValue().numCols(); binaryW_dfsG.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(numRows, numCols)); binaryW_dfsB.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(numRows, numCols)); binaryScoreDerivativesG.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(1, numRows)); binaryScoreDerivativesB.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(1, numRows));
int numRows = entry.getValue().numRows(); int numCols = entry.getValue().numCols(); binaryTD.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(numRows, numCols)); int numRows = entry.getValue().numRows(); int numCols = entry.getValue().numCols(); binaryCD.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleMatrix(numRows, numCols)); int numRows = entry.getValue().numRows(); int numCols = entry.getValue().numCols(); int numSlices = entry.getValue().numSlices(); binaryTensorTD.put(entry.getFirstKey(), entry.getSecondKey(), new SimpleTensor(numRows, numCols, numSlices));
if (!matrix.getFirstKey().equals("") || !matrix.getSecondKey().equals("")) { output.append(matrix.getFirstKey() + " " + matrix.getSecondKey() + ":\n"); output.append(NeuralUtils.toString(matrix.getValue(), "%.8f")); if (!matrix.getFirstKey().equals("") || !matrix.getSecondKey().equals("")) { output.append(matrix.getFirstKey() + " " + matrix.getSecondKey() + ":\n"); output.append(matrix.getValue().toString("%.8f")); if (!matrix.getFirstKey().equals("") || !matrix.getSecondKey().equals("")) { output.append(matrix.getFirstKey() + " " + matrix.getSecondKey() + ":\n"); output.append(NeuralUtils.toString(matrix.getValue(), "%.8f"));
public void printParamInformation(int index) { int curIndex = 0; for (TwoDimensionalMap.Entry<String, String, SimpleMatrix> entry : binaryTransform) { if (curIndex <= index && curIndex + entry.getValue().getNumElements() > index) { System.err.println("Index " + index + " is element " + (index - curIndex) + " of binaryTransform \"" + entry.getFirstKey() + "," + entry.getSecondKey() + "\""); return; } else { curIndex += entry.getValue().getNumElements(); if (curIndex <= index && curIndex + entry.getValue().getNumElements() > index) { System.err.println("Index " + index + " is element " + (index - curIndex) + " of binaryClassification \"" + entry.getFirstKey() + "," + entry.getSecondKey() + "\""); return; } else { curIndex += entry.getValue().getNumElements(); if (curIndex <= index && curIndex + entry.getValue().getNumElements() > index) { System.err.println("Index " + index + " is element " + (index - curIndex) + " of binaryTensor \"" + entry.getFirstKey() + "," + entry.getSecondKey() + "\""); return; } else { curIndex += entry.getValue().getNumElements();
public void printParamInformation(int index) { int curIndex = 0; for (TwoDimensionalMap.Entry<String, String, SimpleMatrix> entry : binaryTransform) { if (curIndex <= index && curIndex + entry.getValue().getNumElements() > index) { log.info("Index " + index + " is element " + (index - curIndex) + " of binaryTransform \"" + entry.getFirstKey() + "," + entry.getSecondKey() + "\""); return; } else { curIndex += entry.getValue().getNumElements(); if (curIndex <= index && curIndex + entry.getValue().getNumElements() > index) { log.info("Index " + index + " is element " + (index - curIndex) + " of binaryClassification \"" + entry.getFirstKey() + "," + entry.getSecondKey() + "\""); return; } else { curIndex += entry.getValue().getNumElements(); if (curIndex <= index && curIndex + entry.getValue().getNumElements() > index) { log.info("Index " + index + " is element " + (index - curIndex) + " of binaryTensor \"" + entry.getFirstKey() + "," + entry.getSecondKey() + "\""); return; } else { curIndex += entry.getValue().getNumElements();
public DVModel(TwoDimensionalMap<String, String, SimpleMatrix> binaryTransform, Map<String, SimpleMatrix> unaryTransform, TwoDimensionalMap<String, String, SimpleMatrix> binaryScore, Map<String, SimpleMatrix> unaryScore, Map<String, SimpleMatrix> wordVectors, Options op) { this.op = op; this.binaryTransform = binaryTransform; this.unaryTransform = unaryTransform; this.binaryScore = binaryScore; this.unaryScore = unaryScore; this.wordVectors = wordVectors; this.numBinaryMatrices = binaryTransform.size(); this.numUnaryMatrices = unaryTransform.size(); if (numBinaryMatrices > 0) { this.binaryTransformSize = binaryTransform.iterator().next().getValue().getNumElements(); this.binaryScoreSize = binaryScore.iterator().next().getValue().getNumElements(); } else { this.binaryTransformSize = 0; this.binaryScoreSize = 0; } if (numUnaryMatrices > 0) { this.unaryTransformSize = unaryTransform.values().iterator().next().getNumElements(); this.unaryScoreSize = unaryScore.values().iterator().next().getNumElements(); } else { this.unaryTransformSize = 0; this.unaryScoreSize = 0; } this.numRows = op.lexOptions.numHid; this.numCols = op.lexOptions.numHid; this.identity = SimpleMatrix.identity(numRows); this.rand = new Random(op.trainOptions.randomSeed); }
public DVModel(TwoDimensionalMap<String, String, SimpleMatrix> binaryTransform, Map<String, SimpleMatrix> unaryTransform, TwoDimensionalMap<String, String, SimpleMatrix> binaryScore, Map<String, SimpleMatrix> unaryScore, Map<String, SimpleMatrix> wordVectors, Options op) { this.op = op; this.binaryTransform = binaryTransform; this.unaryTransform = unaryTransform; this.binaryScore = binaryScore; this.unaryScore = unaryScore; this.wordVectors = wordVectors; this.numBinaryMatrices = binaryTransform.size(); this.numUnaryMatrices = unaryTransform.size(); if (numBinaryMatrices > 0) { this.binaryTransformSize = binaryTransform.iterator().next().getValue().getNumElements(); this.binaryScoreSize = binaryScore.iterator().next().getValue().getNumElements(); } else { this.binaryTransformSize = 0; this.binaryScoreSize = 0; } if (numUnaryMatrices > 0) { this.unaryTransformSize = unaryTransform.values().iterator().next().getNumElements(); this.unaryScoreSize = unaryScore.values().iterator().next().getNumElements(); } else { this.unaryTransformSize = 0; this.unaryScoreSize = 0; } this.numRows = op.lexOptions.numHid; this.numCols = op.lexOptions.numHid; this.identity = SimpleMatrix.identity(numRows); this.rand = new Random(op.trainOptions.randomSeed); }
public DVModel(TwoDimensionalMap<String, String, SimpleMatrix> binaryTransform, Map<String, SimpleMatrix> unaryTransform, TwoDimensionalMap<String, String, SimpleMatrix> binaryScore, Map<String, SimpleMatrix> unaryScore, Map<String, SimpleMatrix> wordVectors, Options op) { this.op = op; this.binaryTransform = binaryTransform; this.unaryTransform = unaryTransform; this.binaryScore = binaryScore; this.unaryScore = unaryScore; this.wordVectors = wordVectors; this.numBinaryMatrices = binaryTransform.size(); this.numUnaryMatrices = unaryTransform.size(); if (numBinaryMatrices > 0) { this.binaryTransformSize = binaryTransform.iterator().next().getValue().getNumElements(); this.binaryScoreSize = binaryScore.iterator().next().getValue().getNumElements(); } else { this.binaryTransformSize = 0; this.binaryScoreSize = 0; } if (numUnaryMatrices > 0) { this.unaryTransformSize = unaryTransform.values().iterator().next().getNumElements(); this.unaryScoreSize = unaryScore.values().iterator().next().getNumElements(); } else { this.unaryTransformSize = 0; this.unaryScoreSize = 0; } this.numRows = op.lexOptions.numHid; this.numCols = op.lexOptions.numHid; this.identity = SimpleMatrix.identity(numRows); this.rand = new Random(op.trainOptions.randomSeed); }
private void primeNext() { K1 k1 = null; if (next != null) { k1 = next.getFirstKey(); } while (innerIterator == null || !innerIterator.hasNext()) { if (!outerIterator.hasNext()) { next = null; return; } Map.Entry<K1, Map<K2, V>> outerEntry = outerIterator.next(); k1 = outerEntry.getKey(); innerIterator = outerEntry.getValue().entrySet().iterator(); } Map.Entry<K2, V> innerEntry = innerIterator.next(); next = new Entry<K1, K2, V>(k1, innerEntry.getKey(), innerEntry.getValue()); }
private void primeNext() { K1 k1 = null; if (next != null) { k1 = next.getFirstKey(); } while (innerIterator == null || !innerIterator.hasNext()) { if (!outerIterator.hasNext()) { next = null; return; } Map.Entry<K1, Map<K2, V>> outerEntry = outerIterator.next(); k1 = outerEntry.getKey(); innerIterator = outerEntry.getValue().entrySet().iterator(); } Map.Entry<K2, V> innerEntry = innerIterator.next(); next = new Entry<>(k1, innerEntry.getKey(), innerEntry.getValue()); }
public void printAllMatrices(PrintStream out) { for (TwoDimensionalMap.Entry<String, String, SimpleMatrix> binary : binaryTransform) { out.println("Binary transform " + binary.getFirstKey() + ":" + binary.getSecondKey()); out.println(binary.getValue()); } for (TwoDimensionalMap.Entry<String, String, SimpleMatrix> binary : binaryScore) { out.println("Binary score " + binary.getFirstKey() + ":" + binary.getSecondKey()); out.println(binary.getValue()); } for (Map.Entry<String, SimpleMatrix> unary : unaryTransform.entrySet()) { out.println("Unary transform " + unary.getKey()); out.println(unary.getValue()); } for (Map.Entry<String, SimpleMatrix> unary : unaryScore.entrySet()) { out.println("Unary score " + unary.getKey()); out.println(unary.getValue()); } }
public void printAllMatrices(PrintStream out) { for (TwoDimensionalMap.Entry<String, String, SimpleMatrix> binary : binaryTransform) { out.println("Binary transform " + binary.getFirstKey() + ":" + binary.getSecondKey()); out.println(binary.getValue()); } for (TwoDimensionalMap.Entry<String, String, SimpleMatrix> binary : binaryScore) { out.println("Binary score " + binary.getFirstKey() + ":" + binary.getSecondKey()); out.println(binary.getValue()); } for (Map.Entry<String, SimpleMatrix> unary : unaryTransform.entrySet()) { out.println("Unary transform " + unary.getKey()); out.println(unary.getValue()); } for (Map.Entry<String, SimpleMatrix> unary : unaryScore.entrySet()) { out.println("Unary score " + unary.getKey()); out.println(unary.getValue()); } }
/** * Add matrices from the second map to the first map, in place. */ public static void addMatrices(TwoDimensionalMap<String, String, SimpleMatrix> first, TwoDimensionalMap<String, String, SimpleMatrix> second) { for (TwoDimensionalMap.Entry<String, String, SimpleMatrix> entry : first) { if (second.contains(entry.getFirstKey(), entry.getSecondKey())) { first.put(entry.getFirstKey(), entry.getSecondKey(), entry.getValue().plus(second.get(entry.getFirstKey(), entry.getSecondKey()))); } } for (TwoDimensionalMap.Entry<String, String, SimpleMatrix> entry : second) { if (!first.contains(entry.getFirstKey(), entry.getSecondKey())) { first.put(entry.getFirstKey(), entry.getSecondKey(), entry.getValue()); } } }
public void printAllMatrices(PrintStream out) { for (TwoDimensionalMap.Entry<String, String, SimpleMatrix> binary : binaryTransform) { out.println("Binary transform " + binary.getFirstKey() + ":" + binary.getSecondKey()); out.println(binary.getValue()); } for (TwoDimensionalMap.Entry<String, String, SimpleMatrix> binary : binaryScore) { out.println("Binary score " + binary.getFirstKey() + ":" + binary.getSecondKey()); out.println(binary.getValue()); } for (Map.Entry<String, SimpleMatrix> unary : unaryTransform.entrySet()) { out.println("Unary transform " + unary.getKey()); out.println(unary.getValue()); } for (Map.Entry<String, SimpleMatrix> unary : unaryScore.entrySet()) { out.println("Unary score " + unary.getKey()); out.println(unary.getValue()); } }
/** * Add tensors from the second map to the first map, in place. */ public static void addTensors(TwoDimensionalMap<String, String, SimpleTensor> first, TwoDimensionalMap<String, String, SimpleTensor> second) { for (TwoDimensionalMap.Entry<String, String, SimpleTensor> entry : first) { if (second.contains(entry.getFirstKey(), entry.getSecondKey())) { first.put(entry.getFirstKey(), entry.getSecondKey(), entry.getValue().plus(second.get(entry.getFirstKey(), entry.getSecondKey()))); } } for (TwoDimensionalMap.Entry<String, String, SimpleTensor> entry : second) { if (!first.contains(entry.getFirstKey(), entry.getSecondKey())) { first.put(entry.getFirstKey(), entry.getSecondKey(), entry.getValue()); } } }
private void primeNext() { K1 k1 = null; if (next != null) { k1 = next.getFirstKey(); } while (innerIterator == null || !innerIterator.hasNext()) { if (!outerIterator.hasNext()) { next = null; return; } Map.Entry<K1, Map<K2, V>> outerEntry = outerIterator.next(); k1 = outerEntry.getKey(); innerIterator = outerEntry.getValue().entrySet().iterator(); } Map.Entry<K2, V> innerEntry = innerIterator.next(); next = new Entry<>(k1, innerEntry.getKey(), innerEntry.getValue()); }