public double score(BufferedReader br, String delimiter, String boundary) throws IOException { int TOKEN_INDEX = 0; int ANSWER_INDEX = 1; int GUESS_INDEX = 2; String line; Pattern delimPattern = Pattern.compile(delimiter); clearCounts(); while ((line = br.readLine()) != null) { line = line.trim(); if (line.length() > 0) { String[] fields = delimPattern.split(line); if (boundary != null && boundary.equals(fields[TOKEN_INDEX])) { markBoundary(); } else { L answer = stringConverter.apply(fields[ANSWER_INDEX]); L guess = stringConverter.apply(fields[GUESS_INDEX]); addGuess(guess, answer); } } else { markBoundary(); } } finalizeCounts(); return getFMeasure(); }
/** * Returns the score (F1) for the given list of guesses * @param guesses - Guesses by classifier * @param trueLabels - Gold labels to compare guesses against * @return F1 score */ public double score(List<L> guesses, List<L> trueLabels) { clearCounts(); addGuesses(guesses, trueLabels); finalizeCounts(); return getFMeasure(); }
private String getConllEvalString(List<L> orderedLabels, boolean ignoreNegLabel) { StringBuilder sb = new StringBuilder(); int correctPhrases = getCorrect() - getCorrect(negLabel); Triple<Double,Integer,Integer> accuracyInfo = getAccuracyInfo(); int totalCount = accuracyInfo.second() + accuracyInfo.third(); sb.append("processed " + totalCount + " tokens with " + getRelevant() + " phrases; "); sb.append("found: " + getRetrieved() + " phrases; correct: " + correctPhrases + "\n"); Formatter formatter = new Formatter(sb, Locale.US); formatter.format("accuracy: %6.2f%%; ", accuracyInfo.first() * 100); formatter.format("precision: %6.2f%%; ", getPrecision() * 100); formatter.format("recall: %6.2f%%; ", getRecall() * 100); formatter.format("FB1: %6.2f\n", getFMeasure() * 100); for (L label: orderedLabels) { if (ignoreNegLabel && label.equals(negLabel)) { continue; } formatter.format("%17s: ", label); formatter.format("precision: %6.2f%%; ", getPrecision(label) * 100); formatter.format("recall: %6.2f%%; ", getRecall(label) * 100); formatter.format("FB1: %6.2f %d\n", getFMeasure(label) * 100, getRetrieved(label)); } return sb.toString(); }
public double score() { finalizeCounts(); return getFMeasure(); }
public String getConllEvalString(boolean ignoreNegLabel) { List<L> labels = getLabels(); if (labels.size() > 1 && labels.get(0) instanceof Comparable) { List<Comparable> sortedLabels = (List<Comparable>) labels; Collections.sort(sortedLabels); } return getConllEvalString(labels, ignoreNegLabel); }
stats.score(filename, delimiter, boundary); } else { stats.score(new BufferedReader(new InputStreamReader(System.in)), delimiter, boundary); System.out.println(stats.getConllEvalString()); } else { System.out.println(stats.getDescription(6));
public double getAccuracy() { return getAccuracyInfo().first(); }
protected void addGuess(L guess, L label) { addGuess(guess, label, true); }
public String getConllEvalString() { return getConllEvalString(true); }
stats.score(filename, delimiter, boundary); } else { stats.score(new BufferedReader(new InputStreamReader(System.in)), delimiter, boundary); System.out.println(stats.getConllEvalString()); } else { System.out.println(stats.getDescription(6));
public double score() { finalizeCounts(); return getFMeasure(); }
public String getConllEvalString(boolean ignoreNegLabel) { List<L> labels = getLabels(); if (labels.size() > 1 && labels.get(0) instanceof Comparable) { List<Comparable> sortedLabels = (List<Comparable>) labels; Collections.sort(sortedLabels); } return getConllEvalString(labels, ignoreNegLabel); }
/** * Returns a String summarizing overall accuracy that will print nicely. */ public String getAccuracyDescription(int numDigits) { NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(numDigits); Triple<Double, Integer, Integer> accu = getAccuracyInfo(); return nf.format(accu.first()) + " (" + accu.second() + "/" + (accu.second() + accu.third()) + ")"; }
public void addGuesses(List<L> guesses, List<L> trueLabels) { for (int i=0; i < guesses.size(); ++i) { L guess = guesses.get(i); L label = trueLabels.get(i); addGuess(guess, label); } }
public String getConllEvalString() { return getConllEvalString(true); }
public <F> double score(Classifier<L,F> classifier, GeneralDataset<L,F> data) { labelIndex = new HashIndex<>(); labelIndex.addAll(classifier.labels()); labelIndex.addAll(data.labelIndex.objectsList()); clearCounts(); int[] labelsArr = data.getLabelsArray(); for (int i = 0; i < data.size(); i++) { Datum<L, F> d = data.getRVFDatum(i); L guess = classifier.classOf(d); addGuess(guess, labelIndex.get(labelsArr[i])); } finalizeCounts(); return getFMeasure(); }
private String getConllEvalString(List<L> orderedLabels, boolean ignoreNegLabel) { StringBuilder sb = new StringBuilder(); int correctPhrases = getCorrect() - getCorrect(negLabel); Triple<Double,Integer,Integer> accuracyInfo = getAccuracyInfo(); int totalCount = accuracyInfo.second() + accuracyInfo.third(); sb.append("processed " + totalCount + " tokens with " + getRelevant() + " phrases; "); sb.append("found: " + getRetrieved() + " phrases; correct: " + correctPhrases + "\n"); Formatter formatter = new Formatter(sb, Locale.US); formatter.format("accuracy: %6.2f%%; ", accuracyInfo.first() * 100); formatter.format("precision: %6.2f%%; ", getPrecision() * 100); formatter.format("recall: %6.2f%%; ", getRecall() * 100); formatter.format("FB1: %6.2f\n", getFMeasure() * 100); for (L label: orderedLabels) { if (ignoreNegLabel && label.equals(negLabel)) { continue; } formatter.format("%17s: ", label); formatter.format("precision: %6.2f%%; ", getPrecision(label) * 100); formatter.format("recall: %6.2f%%; ", getRecall(label) * 100); formatter.format("FB1: %6.2f %d\n", getFMeasure(label) * 100, getRetrieved(label)); } return sb.toString(); }
/** * Returns the score (F1) for the given list of guesses * @param guesses - Guesses by classifier * @param trueLabels - Gold labels to compare guesses against * @return F1 score */ public double score(List<L> guesses, List<L> trueLabels) { clearCounts(); addGuesses(guesses, trueLabels); finalizeCounts(); return getFMeasure(); }
stats.score(filename, delimiter, boundary); } else { stats.score(new BufferedReader(new InputStreamReader(System.in)), delimiter, boundary); System.out.println(stats.getConllEvalString()); } else { System.out.println(stats.getDescription(6));
public double score() { finalizeCounts(); return getFMeasure(); }