Skip to content

Commit ccc185f

Browse files
committed
update parser test to use present models
1 parent 69a082a commit ccc185f

File tree

2 files changed

+37
-55
lines changed

2 files changed

+37
-55
lines changed

itest/src/edu/stanford/nlp/parser/nndep/DependencyParserITest.java

Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import edu.stanford.nlp.trees.TypedDependency;
2626
import edu.stanford.nlp.trees.UniversalEnglishGrammaticalRelations;
2727
import edu.stanford.nlp.util.CoreMap;
28+
import edu.stanford.nlp.util.Pair;
2829
import edu.stanford.nlp.util.PropertiesUtils;
2930
import edu.stanford.nlp.util.StringUtils;
3031
import edu.stanford.nlp.util.TestPaths;
@@ -36,65 +37,39 @@
3637
*/
3738
public class DependencyParserITest {
3839

39-
private static final double EnglishSdLas = 89.55236534222574; // was until Sept 2016: 89.46997859637266;
40-
41-
/**
42-
* Test that the NN dependency parser performance doesn't change.
43-
*/
44-
@Test
45-
public void testDependencyParserEnglishSD() {
46-
DependencyParser parser = new DependencyParser();
47-
parser.loadModelFile(String.format("%s/depparser/nn/distrib-2014-10-26/PTB_Stanford_params.txt.gz", TestPaths.testHome()));
48-
double las = parser.testCoNLL(String.format("%s/depparser/nn/data/dependency_treebanks/PTB/Stanford_3_3_0/dev.conll", TestPaths.testHome()), null);
49-
assertEquals(String.format("English SD LAS should be %.2f but was %.2f",
50-
EnglishSdLas, las), EnglishSdLas, las, 1e-4);
51-
}
52-
53-
// Lower because we're evaluating on PTB + extraDevTest, not just PTB
54-
private static final double EnglishUdLas = 88.84021929576669; // was until Sept 2016: 88.72648417258083;
55-
56-
/**
57-
* Test that the NN dependency parser performance doesn't change.
58-
*/
59-
@Test
60-
public void testDependencyParserEnglishUD() {
61-
DependencyParser parser = new DependencyParser();
62-
parser.loadModelFile(String.format("%s/depparser/nn/distrib-2015-04-16/english_UD.gz", TestPaths.testHome()));
63-
double las = parser.testCoNLL(String.format("%s/depparser/nn/data/dependency_treebanks/UD-converted/dev.conll", TestPaths.testHome()), null);
64-
assertEquals(String.format("English UD LAS should be %.2f but was %.2f",
65-
EnglishUdLas, las), EnglishUdLas, las, 1e-4);
66-
}
67-
68-
private static final double EnglishConll2008Las = 90.97206578058122;
69-
70-
/**
71-
* Test that the NN dependency parser performance doesn't change.
72-
*/
7340
@Test
74-
public void testDependencyParserEnglishCoNLL2008() {
75-
DependencyParser parser = new DependencyParser();
76-
parser.loadModelFile(String.format("%s/depparser/nn/distrib-2014-10-26/PTB_CoNLL_params.txt.gz", TestPaths.testHome()));
77-
double las = parser.testCoNLL(String.format("%s/depparser/nn/data/dependency_treebanks/PTB/CoNLL/dev.conll", TestPaths.testHome()), null);
78-
assertEquals(String.format("English CoNLL2008 LAS should be %.2f but was %.2f",
79-
EnglishConll2008Las, las), EnglishConll2008Las, las, 1e-4);
41+
public void testEnglishOnWSJDev() {
42+
Properties props = new Properties();
43+
props.put("testFile", String.format("%s/depparser/nn/benchmark/wsj-dev.conllu", TestPaths.testHome()));
44+
props.put("model", "edu/stanford/nlp/models/parser/nndep/english_UD.gz");
45+
props.put("outFile", "tmp.conll");
46+
DependencyParser parser = new DependencyParser(props);
47+
parser.loadModelFile(props.getProperty("model"));
48+
Pair<Double, Double> scores =
49+
parser.testCoNLLReturnScores(props.getProperty("testFile"), props.getProperty("outFile"));
50+
double uas = scores.first;
51+
double las = scores.second;
52+
assertTrue(uas >= 93.4);
53+
assertTrue(las >= 91.9);
8054
}
8155

82-
private static final double ChineseConllxGoldTagsLas = 82.42855503270974;
83-
84-
/**
85-
* Test that the NN dependency parser performance doesn't change.
86-
*/
8756
@Test
88-
public void testDependencyParserChineseCoNLLX() {
89-
Properties props = StringUtils.stringToProperties("language=Chinese");
57+
public void testEnglishOnWSJTest() {
58+
Properties props = new Properties();
59+
props.put("testFile", String.format("%s/depparser/nn/benchmark/wsj-test.conllu", TestPaths.testHome()));
60+
props.put("model", "edu/stanford/nlp/models/parser/nndep/english_UD.gz");
61+
props.put("outFile", "tmp.conll");
9062
DependencyParser parser = new DependencyParser(props);
91-
parser.loadModelFile(String.format("%s/depparser/nn/distrib-2014-10-26/CTB_CoNLL_params.txt.gz", TestPaths.testHome()));
92-
// [was but now no such file:] double las = parser.testCoNLL(String.format("%s/depparser/nn/data/dependency_treebanks/CTB/ctb5.1/dev.gold.conll", TestPaths.testHome()), null);
93-
double las = parser.testCoNLL(String.format("%s/depparser/nn/data/dependency_treebanks/CTB/dev.gold.conll", TestPaths.testHome()), null);
94-
assertEquals(String.format("Chinese CoNLLX gold tags LAS should be %.2f but was %.2f",
95-
ChineseConllxGoldTagsLas, las), ChineseConllxGoldTagsLas, las, 1e-4);
63+
parser.loadModelFile(props.getProperty("model"));
64+
Pair<Double, Double> scores =
65+
parser.testCoNLLReturnScores(props.getProperty("testFile"), props.getProperty("outFile"));
66+
double uas = scores.first;
67+
double las = scores.second;
68+
assertTrue(uas >= 93.4);
69+
assertTrue(las >= 92.09);
9670
}
9771

72+
9873
/**
9974
* Test that postprocessing like CC-processing can handle the parser
10075
* output properly

src/edu/stanford/nlp/parser/nndep/DependencyParser.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,15 +1086,22 @@ public GrammaticalStructure predict(List<? extends HasWord> sentence) {
10861086
return predict(sentenceLabel);
10871087
}
10881088

1089+
/**
1090+
* Legacy version of testCoNLLReturnScores that only returns LAS for backwards compatibility
1091+
*/
1092+
public double testCoNLL(String testFile, String outFile) {
1093+
return testCoNLLReturnScores(testFile, outFile).second;
1094+
}
1095+
10891096
//TODO: support sentence-only files as input
10901097

10911098
/** Run the parser in the modelFile on a testFile and perhaps save output.
10921099
*
10931100
* @param testFile File to parse. In CoNLL-X format. Assumed to have gold answers included.
10941101
* @param outFile File to write results to in CoNLL-X format. If null, no output is written
1095-
* @return The LAS score on the dataset
1102+
* @return The UAS and LAS score on the dataset
10961103
*/
1097-
public double testCoNLL(String testFile, String outFile) {
1104+
public Pair<Double, Double> testCoNLLReturnScores(String testFile, String outFile) {
10981105
log.info("Test File: " + testFile);
10991106
Timing timer = new Timing();
11001107
List<CoreMap> testSents = new ArrayList<>();
@@ -1134,7 +1141,7 @@ public double testCoNLL(String testFile, String outFile) {
11341141
if (outFile != null) {
11351142
Util.writeConllFile(outFile, testSents, predicted);
11361143
}
1137-
return las;
1144+
return new Pair<>(uas, las);
11381145
}
11391146

11401147
private void parseTextFile(BufferedReader input, PrintWriter output) {

0 commit comments

Comments
 (0)