@Override protected CRFLogConditionalObjectiveFunction getObjectiveFunction(int[][][][] data, int[][] labels) { int[][][][] unsupDropoutData = null; if (unsupDocs != null) { Timing timer = new Timing(); timer.start(); List<Triple<int[][][], int[], double[][][]>> unsupDataAndLabels = documentsToDataAndLabelsList(unsupDocs); unsupDropoutData = new int[unsupDataAndLabels.size()][][][]; for (int q=0; q<unsupDropoutData.length; q++) unsupDropoutData[q] = unsupDataAndLabels.get(q).first(); long elapsedMs = timer.stop(); log.info("Time to read unsupervised dropout data: " + Timing.toSecondsString(elapsedMs) + " seconds, read " + unsupDropoutData.length + " files"); } return new CRFLogConditionalObjectiveFunctionWithDropout(data, labels, windowSize, classIndex, labelIndices, map, flags.priorType, flags.backgroundSymbol, flags.sigma, null, flags.dropoutRate, flags.dropoutScale, flags.multiThreadGrad, flags.dropoutApprox, flags.unsupDropoutScale, unsupDropoutData); }
to2D(x, weights); setWeights(weights); clear2D(E); clear2D(dropoutPriorGradTotal); if (partialDropout != null) { if (isUnsup) { combine2DArr(dropoutPriorGradTotal, partialDropout, unsupDropoutScale); } else { combine2DArr(dropoutPriorGradTotal, partialDropout); Map<Integer, double[]> partialE = result.third(); if (partialE != null) combine2DArr(E, partialE); if (partialDropout != null) { if (isUnsup) { combine2DArr(dropoutPriorGradTotal, partialDropout, unsupDropoutScale); } else { combine2DArr(dropoutPriorGradTotal, partialDropout); Map<Integer, double[]> partialE = result.third(); if (partialE != null) combine2DArr(E, partialE);
CRFLogConditionalObjectiveFunctionWithDropout(int[][][][] data, int[][] labels, int window, Index<String> classIndex, List<Index<CRFLabel>> labelIndices, int[] map, String priorType, String backgroundSymbol, double sigma, double[][][][] featureVal, double delta, double dropoutScale, int multiThreadGrad, boolean dropoutApprox, double unsupDropoutScale, int[][][][] unsupDropoutData) { super(data, labels, window, classIndex, labelIndices, map, priorType, backgroundSymbol, sigma, featureVal, multiThreadGrad); this.delta = delta; this.dropoutScale = dropoutScale; this.dropoutApprox = dropoutApprox; dropoutPriorGradTotal = empty2D(); this.unsupDropoutStartIndex = data.length; this.unsupDropoutScale = unsupDropoutScale; if (unsupDropoutData != null) { this.totalData = new int[data.length + unsupDropoutData.length][][][]; for (int i=0; i<data.length; i++) { this.totalData[i] = data[i]; } for (int i=0; i<unsupDropoutData.length; i++) { this.totalData[i+unsupDropoutStartIndex] = unsupDropoutData[i]; } } else { this.totalData = data; } initEdgeLabels(); initializeDataFeatureHash(); }
Map<Integer, double[]> EForADoc = sparseE(activeFeatures); List<Map<Integer, double[]>> EForADocPos = null; if (dropoutApprox) { Map<Integer, double[]> EForADocPosAtI = null; if (dropoutApprox) EForADocPosAtI = sparseE(docDataHashI); double p = cliqueTree.prob(i, label); // probability of these labels occurring in this clique with these features if (dropoutApprox) increScore(EForADocPosAtI, fIndex, k, fVal * p); increScore(EForADoc, fIndex, k, fVal * p); timer.start(); dropoutPriorGrad = sparseE(activeFeatures); prob -= getDropoutPrior(cliqueTree, docData, EForADoc, docDataHash, activeFeatures, dropoutPriorGrad, condensedFeaturesMap, EForADocPos);
Map<Integer, List<Integer>> condensedFeaturesMap, List<Map<Integer, double[]>> EForADocPos) { Map<Integer, double[]> dropoutPriorGradFirstHalf = sparseE(activeFeatures); Pair<double[][][], double[][][]> condProbs = getCondProbs(cliqueTree, docData); if (TIMED) { elapsedMs = timer.stop(); increScoreAllowNull(dropoutPriorGradFirstHalf, fIndex, valIndex, VarUp * PtYYpTimesOneMinusPtYYp); System.err.printf("for i=%d, k=%d, y=%d, yP=%d, fIndex=%d, kk=%d, PtYYpPrime=% 5.3f, PtYYp=% 3.3f, (condE-E[fIndex][kk])=% 3.3f, condE=% 3.3f, E[fIndex][k]=% 3.3f, alpha=% 3.3f, beta=% 3.3f, fCount=% 3.3f\n", i, k, y, yP, fIndex, kk, PtYYpPrime, PtYYp, (condE - EForADoc.get(fIndex)[kk]), condE, EForADoc.get(fIndex)[kk], alpha, beta, fCount); increScore(dropoutPriorGrad, fIndex, kk, VarUTimesOneMinus2PtYYp * PtYYpPrime);
Map<Integer, List<Integer>> condensedFeaturesMap, List<Map<Integer, double[]>> EForADocPos) { Map<Integer, double[]> dropoutPriorGradFirstHalf = sparseE(activeFeatures); Pair<double[][][], double[][][]> condProbs = getCondProbs(cliqueTree, docData); if (TIMED) { elapsedMs = timer.stop(); increScoreAllowNull(dropoutPriorGradFirstHalf, fIndex, valIndex, VarUp * PtYYpTimesOneMinusPtYYp); System.err.printf("for i=%d, k=%d, y=%d, yP=%d, fIndex=%d, kk=%d, PtYYpPrime=% 5.3f, PtYYp=% 3.3f, (condE-E[fIndex][kk])=% 3.3f, condE=% 3.3f, E[fIndex][k]=% 3.3f, alpha=% 3.3f, beta=% 3.3f, fCount=% 3.3f\n", i, k, y, yP, fIndex, kk, PtYYpPrime, PtYYp, (condE - EForADoc.get(fIndex)[kk]), condE, EForADoc.get(fIndex)[kk], alpha, beta, fCount); increScore(dropoutPriorGrad, fIndex, kk, VarUTimesOneMinus2PtYYp * PtYYpPrime);
Map<Integer, double[]> EForADoc = sparseE(activeFeatures); List<Map<Integer, double[]>> EForADocPos = null; if (dropoutApprox) { Map<Integer, double[]> EForADocPosAtI = null; if (dropoutApprox) EForADocPosAtI = sparseE(docDataHashI); double p = cliqueTree.prob(i, label); // probability of these labels occurring in this clique with these features if (dropoutApprox) increScore(EForADocPosAtI, fIndex, k, fVal * p); increScore(EForADoc, fIndex, k, fVal * p); timer.start(); dropoutPriorGrad = sparseE(activeFeatures); prob -= getDropoutPrior(cliqueTree, docData, EForADoc, docDataHash, activeFeatures, dropoutPriorGrad, condensedFeaturesMap, EForADocPos);
to2D(x, weights); setWeights(weights); clear2D(E); clear2D(dropoutPriorGradTotal); if (partialDropout != null) { if (isUnsup) { combine2DArr(dropoutPriorGradTotal, partialDropout, unsupDropoutScale); } else { combine2DArr(dropoutPriorGradTotal, partialDropout); Map<Integer, double[]> partialE = result.third(); if (partialE != null) combine2DArr(E, partialE); if (partialDropout != null) { if (isUnsup) { combine2DArr(dropoutPriorGradTotal, partialDropout, unsupDropoutScale); } else { combine2DArr(dropoutPriorGradTotal, partialDropout); Map<Integer, double[]> partialE = result.third(); if (partialE != null) combine2DArr(E, partialE);
Map<Integer, List<Integer>> condensedFeaturesMap, List<Map<Integer, double[]>> EForADocPos) { Map<Integer, double[]> dropoutPriorGradFirstHalf = sparseE(activeFeatures); Pair<double[][][], double[][][]> condProbs = getCondProbs(cliqueTree, docData); if (TIMED) { elapsedMs = timer.stop(); increScoreAllowNull(dropoutPriorGradFirstHalf, fIndex, valIndex, VarUp * PtYYpTimesOneMinusPtYYp); System.err.printf("for i=%d, k=%d, y=%d, yP=%d, fIndex=%d, kk=%d, PtYYpPrime=% 5.3f, PtYYp=% 3.3f, (condE-E[fIndex][kk])=% 3.3f, condE=% 3.3f, E[fIndex][k]=% 3.3f, alpha=% 3.3f, beta=% 3.3f, fCount=% 3.3f\n", i, k, y, yP, fIndex, kk, PtYYpPrime, PtYYp, (condE - EForADoc.get(fIndex)[kk]), condE, EForADoc.get(fIndex)[kk], alpha, beta, fCount); increScore(dropoutPriorGrad, fIndex, kk, VarUTimesOneMinus2PtYYp * PtYYpPrime);
CRFLogConditionalObjectiveFunctionWithDropout(int[][][][] data, int[][] labels, int window, Index<String> classIndex, List<Index<CRFLabel>> labelIndices, int[] map, String priorType, String backgroundSymbol, double sigma, double[][][][] featureVal, double delta, double dropoutScale, int multiThreadGrad, boolean dropoutApprox, double unsupDropoutScale, int[][][][] unsupDropoutData) { super(data, labels, window, classIndex, labelIndices, map, priorType, backgroundSymbol, sigma, featureVal, multiThreadGrad); this.delta = delta; this.dropoutScale = dropoutScale; this.dropoutApprox = dropoutApprox; dropoutPriorGradTotal = empty2D(); this.unsupDropoutStartIndex = data.length; this.unsupDropoutScale = unsupDropoutScale; if (unsupDropoutData != null) { this.totalData = new int[data.length + unsupDropoutData.length][][][]; for (int i=0; i<data.length; i++) { this.totalData[i] = data[i]; } for (int i=0; i<unsupDropoutData.length; i++) { this.totalData[i+unsupDropoutStartIndex] = unsupDropoutData[i]; } } else { this.totalData = data; } initEdgeLabels(); initializeDataFeatureHash(); }
Map<Integer, double[]> EForADoc = sparseE(activeFeatures); List<Map<Integer, double[]>> EForADocPos = null; if (dropoutApprox) { Map<Integer, double[]> EForADocPosAtI = null; if (dropoutApprox) EForADocPosAtI = sparseE(docDataHashI); double p = cliqueTree.prob(i, label); // probability of these labels occurring in this clique with these features if (dropoutApprox) increScore(EForADocPosAtI, fIndex, k, fVal * p); increScore(EForADoc, fIndex, k, fVal * p); timer.start(); dropoutPriorGrad = sparseE(activeFeatures); prob -= getDropoutPrior(cliqueTree, docData, EForADoc, docDataHash, activeFeatures, dropoutPriorGrad, condensedFeaturesMap, EForADocPos);
@Override protected CRFLogConditionalObjectiveFunction getObjectiveFunction(int[][][][] data, int[][] labels) { int[][][][] unsupDropoutData = null; if (unsupDocs != null) { Timing timer = new Timing(); timer.start(); List<Triple<int[][][], int[], double[][][]>> unsupDataAndLabels = documentsToDataAndLabelsList(unsupDocs); unsupDropoutData = new int[unsupDataAndLabels.size()][][][]; for (int q=0; q<unsupDropoutData.length; q++) unsupDropoutData[q] = unsupDataAndLabels.get(q).first(); long elapsedMs = timer.stop(); System.err.println("Time to read unsupervised dropout data: " + Timing.toSecondsString(elapsedMs) + " seconds, read " + unsupDropoutData.length + " files"); } return new CRFLogConditionalObjectiveFunctionWithDropout(data, labels, windowSize, classIndex, labelIndices, map, flags.priorType, flags.backgroundSymbol, flags.sigma, null, flags.dropoutRate, flags.dropoutScale, flags.multiThreadGrad, flags.dropoutApprox, flags.unsupDropoutScale, unsupDropoutData); } } // end class CRFClassifier
to2D(x, weights); setWeights(weights); clear2D(E); clear2D(dropoutPriorGradTotal); if (partialDropout != null) { if (isUnsup) { combine2DArr(dropoutPriorGradTotal, partialDropout, unsupDropoutScale); } else { combine2DArr(dropoutPriorGradTotal, partialDropout); Map<Integer, double[]> partialE = result.third(); if (partialE != null) combine2DArr(E, partialE); if (partialDropout != null) { if (isUnsup) { combine2DArr(dropoutPriorGradTotal, partialDropout, unsupDropoutScale); } else { combine2DArr(dropoutPriorGradTotal, partialDropout); Map<Integer, double[]> partialE = result.third(); if (partialE != null) combine2DArr(E, partialE);
CRFLogConditionalObjectiveFunctionWithDropout(int[][][][] data, int[][] labels, int window, Index<String> classIndex, List<Index<CRFLabel>> labelIndices, int[] map, String priorType, String backgroundSymbol, double sigma, double[][][][] featureVal, double delta, double dropoutScale, int multiThreadGrad, boolean dropoutApprox, double unsupDropoutScale, int[][][][] unsupDropoutData) { super(data, labels, window, classIndex, labelIndices, map, priorType, backgroundSymbol, sigma, featureVal, multiThreadGrad); this.delta = delta; this.dropoutScale = dropoutScale; this.dropoutApprox = dropoutApprox; dropoutPriorGradTotal = empty2D(); this.unsupDropoutStartIndex = data.length; this.unsupDropoutScale = unsupDropoutScale; if (unsupDropoutData != null) { this.totalData = new int[data.length + unsupDropoutData.length][][][]; for (int i=0; i<data.length; i++) { this.totalData[i] = data[i]; } for (int i=0; i<unsupDropoutData.length; i++) { this.totalData[i+unsupDropoutStartIndex] = unsupDropoutData[i]; } } else { this.totalData = data; } initEdgeLabels(); initializeDataFeatureHash(); }
@Override protected CRFLogConditionalObjectiveFunction getObjectiveFunction(int[][][][] data, int[][] labels) { int[][][][] unsupDropoutData = null; if (unsupDocs != null) { Timing timer = new Timing(); timer.start(); List<Triple<int[][][], int[], double[][][]>> unsupDataAndLabels = documentsToDataAndLabelsList(unsupDocs); unsupDropoutData = new int[unsupDataAndLabels.size()][][][]; for (int q=0; q<unsupDropoutData.length; q++) unsupDropoutData[q] = unsupDataAndLabels.get(q).first(); long elapsedMs = timer.stop(); log.info("Time to read unsupervised dropout data: " + Timing.toSecondsString(elapsedMs) + " seconds, read " + unsupDropoutData.length + " files"); } return new CRFLogConditionalObjectiveFunctionWithDropout(data, labels, windowSize, classIndex, labelIndices, map, flags.priorType, flags.backgroundSymbol, flags.sigma, null, flags.dropoutRate, flags.dropoutScale, flags.multiThreadGrad, flags.dropoutApprox, flags.unsupDropoutScale, unsupDropoutData); }