@Override public int length() { return cliqueTree.length(); }
/** * Returns the log probability of this sequence given the CRF. Does so by * computing the marginal of the first windowSize tags, and then computing the * conditional probability for the rest of them, conditioned on the previous * tags. * * @param sequence The sequence to compute a score for * @return the score for the sequence */ @Override public double scoreOf(int[] sequence) { int[] given = new int[window() - 1]; Arrays.fill(given, classIndex.indexOf(backgroundSymbol)); double logProb = 0.0; for (int i = 0, length = length(); i < length; i++) { int label = sequence[i]; logProb += condLogProbGivenPrevious(i, label, given); System.arraycopy(given, 1, given, 0, given.length - 1); given[given.length - 1] = label; } return logProb; }
for (int i = 0; i < cliqueTree.length(); i++) { IN wi = document.get(i); System.out.print(wi.get(CoreAnnotations.TextAnnotation.class) + '\t');
public List<Counter<String>> zeroOrderProbabilities(List<IN> document) { List<Counter<String>> ret = new ArrayList<>(); Triple<int[][][], int[], double[][][]> p = documentToDataAndLabels(document); CRFCliqueTree<String> cliqueTree = getCliqueTree(p); for (int i = 0; i < cliqueTree.length(); i++) { Counter<String> ctr = new ClassicCounter<>(); for (String label : classIndex) { int index = classIndex.indexOf(label); double prob = cliqueTree.prob(i, index); ctr.setCount(label, prob); } ret.add(ctr); } return ret; }
int[] sequence = new int[cliqueTree.length()];
for (int i = 0; i < cliqueTree.length(); i++) { IN wi = document.get(i); String token = wi.get(CoreAnnotations.TextAnnotation.class);
@Override public int length() { return cliqueTree.length(); }
@Override public int length() { return cliqueTree.length(); }
public int length() { return cliqueTree.length(); }
/** * Returns the log probability of this sequence given the CRF. * Does so by computing the marginal of the first windowSize tags, and * then computing the conditional probability for the rest of them, conditioned on the previous * tags. * @param sequence the sequence to compute a score for * @return the score for the sequence */ public double scoreOf(int[] sequence) { int[] given = new int[window() - 1]; Arrays.fill(given, classIndex.indexOf(backgroundSymbol)); double logProb = 0; for (int i=0; i<length(); i++) { int label = sequence[i]; logProb += condLogProbGivenPrevious(i, label, given); System.arraycopy(given, 1, given, 0, given.length - 1); given[given.length - 1] = label; } return logProb; }
/** * Returns the log probability of this sequence given the CRF. Does so by * computing the marginal of the first windowSize tags, and then computing the * conditional probability for the rest of them, conditioned on the previous * tags. * * @param sequence The sequence to compute a score for * @return the score for the sequence */ @Override public double scoreOf(int[] sequence) { int[] given = new int[window() - 1]; Arrays.fill(given, classIndex.indexOf(backgroundSymbol)); double logProb = 0.0; for (int i = 0, length = length(); i < length; i++) { int label = sequence[i]; logProb += condLogProbGivenPrevious(i, label, given); System.arraycopy(given, 1, given, 0, given.length - 1); given[given.length - 1] = label; } return logProb; }
/** * Returns the log probability of this sequence given the CRF. Does so by * computing the marginal of the first windowSize tags, and then computing the * conditional probability for the rest of them, conditioned on the previous * tags. * * @param sequence The sequence to compute a score for * @return the score for the sequence */ @Override public double scoreOf(int[] sequence) { int[] given = new int[window() - 1]; Arrays.fill(given, classIndex.indexOf(backgroundSymbol)); double logProb = 0.0; for (int i = 0, length = length(); i < length; i++) { int label = sequence[i]; logProb += condLogProbGivenPrevious(i, label, given); System.arraycopy(given, 1, given, 0, given.length - 1); given[given.length - 1] = label; } return logProb; }
/** * Takes a {@link List} of something that extends {@link CoreMap} and prints * the likelihood of each possible label at each point. * * @param document * A {@link List} of something that extends CoreMap. */ @Override public void printProbsDocument(List<IN> document) { Triple<int[][][], int[], double[][][]> p = documentToDataAndLabels(document); CRFCliqueTree<String> cliqueTree = getCliqueTree(p); // for (int i = 0; i < factorTables.length; i++) { for (int i = 0; i < cliqueTree.length(); i++) { IN wi = document.get(i); System.out.print(wi.get(CoreAnnotations.TextAnnotation.class) + '\t'); for (Iterator<String> iter = classIndex.iterator(); iter.hasNext();) { String label = iter.next(); int index = classIndex.indexOf(label); // double prob = Math.pow(Math.E, factorTables[i].logProbEnd(index)); double prob = cliqueTree.prob(i, index); System.out.print(label + '=' + prob); if (iter.hasNext()) { System.out.print("\t"); } else { System.out.print("\n"); } } } }
/** * Takes a {@link List} of something that extends {@link CoreMap} and prints the likelihood * of each possible label at each point. * * @param document A {@link List} of something that extends CoreMap. */ @Override public void printProbsDocument(List<IN> document) { Pair<int[][][],int[]> p = documentToDataAndLabels(document); int[][][] data = p.first(); //FactorTable[] factorTables = CRFLogConditionalObjectiveFunction.getCalibratedCliqueTree(weights, data, labelIndices, classIndex.size()); CRFCliqueTree cliqueTree = CRFCliqueTree.getCalibratedCliqueTree(weights, data, labelIndices, classIndex.size(), classIndex, flags.backgroundSymbol); // for (int i = 0; i < factorTables.length; i++) { for (int i = 0; i < cliqueTree.length(); i++) { IN wi = document.get(i); System.out.print(wi.get(CoreAnnotations.TextAnnotation.class) + '\t'); for (Iterator<String> iter = classIndex.iterator(); iter.hasNext();) { String label = iter.next(); int index = classIndex.indexOf(label); // double prob = Math.pow(Math.E, factorTables[i].logProbEnd(index)); double prob = cliqueTree.prob(i, index); System.out.print(label + '=' + prob); if (iter.hasNext()) { System.out.print("\t"); } else { System.out.print("\n"); } } } }
public List<Counter<String>> zeroOrderProbabilities(List<IN> document) { List<Counter<String>> ret = new ArrayList<>(); Triple<int[][][], int[], double[][][]> p = documentToDataAndLabels(document); CRFCliqueTree<String> cliqueTree = getCliqueTree(p); for (int i = 0; i < cliqueTree.length(); i++) { Counter<String> ctr = new ClassicCounter<>(); for (String label : classIndex) { int index = classIndex.indexOf(label); double prob = cliqueTree.prob(i, index); ctr.setCount(label, prob); } ret.add(ctr); } return ret; }
int[] sequence = new int[cliqueTree.length()];