@Override public CliquePotentialFunction getCliquePotentialFunction(double[] x) { to2D(x, weights); return new LinearCliquePotentialFunction(weights); }
public double[][] separateLopExpertWeights(double[] learnedParams) { double[][] learnedWeights = new double[numLopExpert][]; double[][][] learnedWeights2D = separateLopExpertWeights2D(learnedParams); for (int i = 0; i < numLopExpert; i++) { learnedWeights[i] = CRFLogConditionalObjectiveFunction.to1D(learnedWeights2D[i], lopExpertWeights[i].length); } return learnedWeights; }
public static <INN extends CoreMap> CRFClassifier<INN> getClassifier(ObjectInputStream ois) throws IOException, ClassCastException, ClassNotFoundException { CRFClassifier<INN> crf = new CRFClassifier<>(); crf.loadClassifier(ois,null); return crf; }
/** * This is used to load the default supplied classifier stored within the jar * file. THIS FUNCTION WILL ONLY WORK IF THE CODE WAS LOADED FROM A JAR FILE * WHICH HAS A SERIALIZED CLASSIFIER STORED INSIDE IT. */ public void loadDefaultClassifier() { loadClassifierNoExceptions(DEFAULT_CLASSIFIER); }
@Override public SequenceModel getSequenceModel(List<IN> doc) { Triple<int[][][], int[], double[][][]> p = documentToDataAndLabels(doc); return getSequenceModel(p, doc); }
/** * returns the log probability for the given labels, where the last label * corresponds to the label at the specified position. For instance if you * called logProb(5, {"O", "PER", "ORG"}) it will return the marginal log prob * that the label at position 3 is "O", the label at position 4 is "PER" and * the label at position 5 is "ORG". */ public double logProb(int position, E[] labels) { return logProb(position, objectArrayToIntArray(labels)); }
public void printLabelInformation(String testFile, DocumentReaderAndWriter<IN> readerAndWriter) throws Exception { ObjectBank<List<IN>> documents = makeObjectBankFromFile(testFile, readerAndWriter); for (List<IN> document : documents) { printLabelValue(document); } }
@SuppressWarnings("WeakerAccess") public CRFCliqueTree<String> getCliqueTree(List<IN> document) { Triple<int[][][], int[], double[][][]> p = documentToDataAndLabels(document); return getCliqueTree(p); }
private SequenceModel getSequenceModel(Triple<int[][][], int[], double[][][]> documentDataAndLabels, List<IN> document) { return labelDictionary == null ? new TestSequenceModel(getCliqueTree(documentDataAndLabels)) : new TestSequenceModel(getCliqueTree(documentDataAndLabels), labelDictionary, document); }
@Override protected CliquePotentialFunction getCliquePotentialFunctionForTest() { if (cliquePotentialFunction == null) { if (flags.secondOrderNonLinear) cliquePotentialFunction = new NonLinearSecondOrderCliquePotentialFunction(inputLayerWeights4Edge, outputLayerWeights4Edge, inputLayerWeights, outputLayerWeights, flags); else cliquePotentialFunction = new NonLinearCliquePotentialFunction(linearWeights, inputLayerWeights, outputLayerWeights, flags); } return cliquePotentialFunction; }
public void setValue(int[] label, double value) { // try{ table[indexOf(label)] = value; // } catch (Exception e) { // e.printStackTrace(); // log.info("Table length: " + table.length + " indexOf(label): " // + indexOf(label)); // throw new ArrayIndexOutOfBoundsException(e.toString()); // // System.exit(1); // } }
public CRFClassifierEvaluator(String description, CRFClassifier<IN> classifier, Collection<List<IN>> data, List<Triple<int[][][], int[], double[][][]>> featurizedData) { this.description = description; this.classifier = classifier; this.data = data; this.featurizedData = featurizedData; cmd = getCmd(cmdStr); saveOutput = true; }
@Override public double[] initial() { return initial(rand); } public double[] initial(boolean useRandomSeed) {
/** Beware: this changes the input weights array in place. */ public double[][] to2D(double[] weights1D, double wScale) { for (int i = 0; i < weights1D.length; i++) weights1D[i] = weights1D[i] * wScale; return to2D(weights1D, this.labelIndices, this.map); }
public double[][][] separateLopExpertWeights2D(double[] learnedParams) { double[][][] learnedWeights2D = empty2D(); for (int paramIndex = numLopExpert; paramIndex < learnedParams.length; paramIndex++) { int[] mapping = learnedParamsMapping[paramIndex]; learnedWeights2D[mapping[0]][mapping[1]][mapping[2]] = learnedParams[paramIndex]; } return learnedWeights2D; }
@Override public int[] getPossibleValues(int pos) { if (pos < leftWindow()) { return backgroundTag; } int realPos = pos - window + 1; return allowedTagsAtPosition == null ? allTags : allowedTagsAtPosition[realPos]; }
protected CliquePotentialFunction getCliquePotentialFunctionForTest() { if (cliquePotentialFunction == null) { cliquePotentialFunction = new LinearCliquePotentialFunction(weights); } return cliquePotentialFunction; }
public static <INN extends CoreMap> CRFClassifier<INN> getClassifier(ObjectInputStream ois, Properties props) throws IOException, ClassCastException, ClassNotFoundException { CRFClassifier<INN> crf = new CRFClassifier<>(); crf.loadClassifier(ois, props); return crf; }
public static <INN extends CoreMap> CRFClassifier<INN> getClassifier(String loadPath, Properties props) throws IOException, ClassCastException, ClassNotFoundException { CRFClassifier<INN> crf = new CRFClassifier<>(); crf.loadClassifier(loadPath, props); return crf; }