|
25 | 25 | import edu.stanford.nlp.trees.TypedDependency; |
26 | 26 | import edu.stanford.nlp.trees.UniversalEnglishGrammaticalRelations; |
27 | 27 | import edu.stanford.nlp.util.CoreMap; |
| 28 | +import edu.stanford.nlp.util.Pair; |
28 | 29 | import edu.stanford.nlp.util.PropertiesUtils; |
29 | 30 | import edu.stanford.nlp.util.StringUtils; |
30 | 31 | import edu.stanford.nlp.util.TestPaths; |
|
36 | 37 | */ |
37 | 38 | public class DependencyParserITest { |
38 | 39 |
|
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 | | - */ |
73 | 40 | @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); |
80 | 54 | } |
81 | 55 |
|
82 | | - private static final double ChineseConllxGoldTagsLas = 82.42855503270974; |
83 | | - |
84 | | - /** |
85 | | - * Test that the NN dependency parser performance doesn't change. |
86 | | - */ |
87 | 56 | @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"); |
90 | 62 | 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); |
96 | 70 | } |
97 | 71 |
|
| 72 | + |
98 | 73 | /** |
99 | 74 | * Test that postprocessing like CC-processing can handle the parser |
100 | 75 | * output properly |
|
0 commit comments