Skip to content

Commit 2725b06

Browse files
committed
Add the f1 scores for each tree to the parser protobuf responses
1 parent a80772d commit 2725b06

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/edu/stanford/nlp/parser/metrics/EvaluateExternalParser.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,17 @@ public List<Pair<ParserQuery, Tree>> convertDataset(List<Tree> goldTrees, List<L
9494
}
9595

9696

97-
public CoreNLPProtos.EvaluateParserResponse buildResponse(double f1, Double kbestF1) {
97+
public CoreNLPProtos.EvaluateParserResponse buildResponse(double f1, Double kbestF1, List<Double> f1History) {
9898
CoreNLPProtos.EvaluateParserResponse.Builder responseBuilder = CoreNLPProtos.EvaluateParserResponse.newBuilder();
9999
responseBuilder.setF1(f1);
100100
if (kbestF1 != null) {
101101
responseBuilder.setKbestF1(kbestF1);
102102
}
103+
if (f1History != null) {
104+
for (Double treeF1 : f1History) {
105+
responseBuilder.addTreeF1(treeF1);
106+
}
107+
}
103108
CoreNLPProtos.EvaluateParserResponse response = responseBuilder.build();
104109
return response;
105110
}
@@ -116,7 +121,8 @@ public CoreNLPProtos.EvaluateParserResponse scoreDataset(List<Tree> goldTrees, L
116121
if (evaluator.hasPCFGTopKF1()) {
117122
kbestF1 = evaluator.getPCFGTopKF1();
118123
}
119-
return buildResponse(f1, kbestF1);
124+
List<Double> f1History = evaluator.getF1History();
125+
return buildResponse(f1, kbestF1, f1History);
120126
}
121127

122128
public CoreNLPProtos.EvaluateParserResponse processRequest(CoreNLPProtos.EvaluateParserRequest parses) throws IOException {

src/edu/stanford/nlp/parser/metrics/EvaluateTreebank.java

+8
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public class EvaluateTreebank {
9191
AbstractEval.ScoreEval factLL = null;
9292
AbstractEval kGoodLB = null;
9393

94+
List<Double> factLBHistory = null;
95+
9496
BestOfTopKEval pcfgTopK = null;
9597
private final List<BestOfTopKEval> topKEvals = new ArrayList<>();
9698

@@ -182,6 +184,7 @@ public EvaluateTreebank(Options op, Lexicon lex, ParserQueryFactory pqFactory, F
182184
}
183185
if (Boolean.parseBoolean(op.testOptions.evals.getProperty("factLB"))) {
184186
factLB = new Evalb("factor LP/LR", runningAverages);
187+
factLBHistory = new ArrayList<>();
185188
}
186189
if (op.testOptions.evals.getProperty("factChildSpecific") != null) {
187190
String filter = op.testOptions.evals.getProperty("factChildSpecific");
@@ -268,6 +271,10 @@ public boolean hasPCFGTopKF1() {
268271
return pcfgTopK != null;
269272
}
270273

274+
public List<Double> getF1History() {
275+
return Collections.unmodifiableList(factLBHistory);
276+
}
277+
271278
/**
272279
* Remove tree scores, so they don't print.
273280
* <br>
@@ -524,6 +531,7 @@ else if(pwFileOut != null) {
524531
//Factored parser (1best) eval
525532
if (factLB != null) {
526533
factLB.evaluate(treeFact, transGoldTree, pwErr);
534+
factLBHistory.add(factLB.getLastF1());
527535
}
528536
if (factChildSpecific != null) {
529537
factChildSpecific.evaluate(treeFact, transGoldTree, pwErr);

0 commit comments

Comments
 (0)