/
README
282 lines (203 loc) · 10.4 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// README
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright 2004-2013 Brian Roark
// Author: roarkbr@gmail.com (Brian Roark)
Incremental Top-Down Parser README
The incremental top-down parser is a statistical syntactic parser that
processes input strings from left-to-right, producing partial
derivations in a top-down manner, using beam search as detailed in
Roark (2001) and Roark (2004). It can output parser state statistics
of utility for psycholinguistic studies, as detailed in Roark et al.
(2009).
Note that this code is research code, provided to the community
without promise of additional technical support. Many researchers have
used this code in their research, and were able to successfully
compile and use the code on linux and Mac OS X systems. If you follow
the instructions below, you should be able to use it as well, but if
you encounter problems you are pretty much on your own.
In addition to the parser and the model training code, a model trained
on sections 2-21 of the Penn WSJ treebank has been included. For those
who want to train their own models, there are some scripts for
converting Penn Treebank files from the 'pretty-print' representation
provided by the LDC to the format expected by the model training
routine: one parse per line, with no function tags or empty nodes,
etc. You are free to change your non-terminal labels (e.g., changing
VBs to AUXs, etc.) but the code assumes that POS-tags and non-POS-tag
non-terminals are disjoint.
====== INSTALLATION =======
To compile, you will need to change the install directory in Makedefs,
then cd to the bin directory and call make all. Linux requires -lm
flag, Mac OSX doesn't. Copy Makefile.MAC to Makefile for Mac OSX; copy
Makefile.linux to Makefile for linux systems.
====== USAGE =======
Parsing:
To get information on usage, type the following on the command line:
bin/tdparse -?
The following is standard usage for parsing a file of strings
'mystrings.txt':
bin/tdparse -v -F parse.output parse.model.wsj.slc.p05 mystrings.txt
The strings file 'mystrings.txt' should have one string per line (see
the file data/test.test.txt).
The parser output comes with three numbers before the parse:
cand tot-cands -logCondProb (TOP...
This is for distinguishing between candidates in k-best parsing.
To evaluate with just one candidate:
sed 's/.*(TOP/(TOP/g' parse.output >parse.best
Then:
evalb -p data/evalb/COLLINS.prm mytrees.gold.txt parse.best >parse.eval
Training models:
To train a model, you must first prepare a training treebank. Scripts
have been provided to assist in converting Penn Treebank style parses
from their raw format as distributed by the LDC to the format expected
by the model training code. Briefly, that code expects: 1) 1 parse per
line in the text file; 2) no empty nodes; 3) a single TOP category,
with only unary productions to the root non-terminal of the tree; 4)
disjoint POS-tag and non-POS-tag non-terminal sets. Our scripts make
use of tsurgeon available here:
http://nlp.stanford.edu/software/tregex.shtml
Once that has been installed, modify the data/tbnorm/tbnorm.sh script
to include the path to the tsurgeon directory. Then, cd to data/tbnorm
and:
./tbnorm.sh raw.treebank.file >normalized.treebank.file
This script does not guarantee condition 4 above, that the POS-tags
are disjoint from the other non-terminals. The tbtest.sh script tests
that this is the case:
./tbtest.sh normalized.treebank.file
This will report non-terminals used as both POS-tags and non-POS-tag
non-terminals in the given treebank file.
See data/test.train.txt to see a small, fake treebank in the required
format.
To get information on usage, type the following on the command line:
bin/tdptrain -?
The following is standard usage for training a model from a given
treebank:
bin/tdptrain -t0.05 -p -s"(SINV(S" -v -F parse.model.slc.p05 -m data/tree.functs.sfile normalized.treebank.file
Please see the usage from the command line for further options.
====================
new verbose output:
If you run with the -p command line switch, it outputs word-by-word
scores that are available from standard running of the parser,
including the surprisal measures and other internal state statistics.
There are column headers, and I'll explain each of them in turn:
pfix header
In this column, we get some info on the particular row. For each word
w, this will read 'pfix#w' where # can range over three symbols: '-'
are tokens which 'belong' to the previous token, such as punctuation
or contractions or end-of-string; '+' are closed class lexical items;
and ':' are anything else. non-lexical and closed class words can are
identified by including the following switch when parsing:
-c data/closed.class.words
and that file can be modified as you like. In that file, 0 following
the word means punct. or contraction; 1 following the word means
closed class.
prefix
This column gives prefix probability, sum of probs over the beam.
srprsl nolex lex
These three columns give total surprisal, syntactic surprisal, and
lexical surprisal, as defined in the paper.
ambig
This column gives the entropy over the current beam, essentially a
measure of ambiguity. If p is the conditional probability of each
analysis in the normalized beam, then this is -\sum p log p over the
beam.
open
This column gives the weighted average open brackets over the beam.
(Easy to derive from the parser, not of any particular utility so
far.)
rernk toprr
These two columns examine what happens to the previously top-ranked
parses. I'll explain this informally by abusing notation. Let T_i be
the best scoring parse after word i, and let T^+_i be the set of
parses after word i+1 that are extensions of parse T_i. Then rernk is
p(T^+_i)/p(T_i) where the p in this case is normalized over the beam
(hence ratio can be greater than 1). A score of 1 means that these
analyses occupy about the same amount of conditional probability mass
in the beam after one step; a score greater than 1 means they are now
occupying more of the conditional probability mass; and less than 1
means they occupy less. A score of zero means it has fallen out of the
beam.
The second column here just looks at the top ranked parse at time i+1.
If it is an extension of the top ranked parse at time i, then the
ratio of conditional prob is provided; otherwise zero.
stps
Finally, we look at the weighted average (over the normalized beam) of
derivation steps from the previous word.
Part II: measures that cannot be derived from standard operation of
the parser. These include the entropy measures, which are calculated
by extending the current parse to all possible following words (hence
running with this switch is slllllloooooowwwwww). To get the entropy
scores, run with the -a switch, and it will provide additional scores
related to entropy.
afix header
just like prefix header, with closed class coding, etc.
entropy noLexH LexH
total entropy, Syntactic entropy and lexical entropy, as described in
the paper.
rank log10(rank)
These two columns show the rank of the actual next word within the
vocabulary, in terms of the conditional prob of the word given the
left context. Since we are calculating the probability of every word
in the lexicon, we can straightforwardly rank and report where the
actual word falls in the rank (and the log).
log(p*/p)
This score compares the probability of the top ranked word in the
lexicon versus the actual next word. Thus if rank is 1, this score
will be zero, otherwise greater than zero.
One last thing. There are scores attached to each output tree (by
default the 1-best, but use -k to retrieve more), and those scores
are:
candidate rank
total number of candidates in list
tree score (without norm constant)
tree negative log prob
purely syntactic contribution to that total neg log prob
lexical contribution to the neg log prob (from POS -> word)
=========== CITING ================
The basic citation for the parsing approach is:
Brian Roark. 2001. Probabilistic top-down parsing and language
modeling. In Computational Linguistics, 27(2), pages 249-276.
If using the parser to derive parser state statistics for
psycholinguistic modeling, it's also a good idea to cite:
Brian Roark, Asaf Bachrach, Carlos Cardenas and Christophe Pallier.
2009. Deriving lexical and syntactic expectation-based measures for
psycholinguistic modeling via incremental top-down parsing. In
Proceedings of the Conference on Empirical Methods in Natural Language
Processing (EMNLP), pp. 324-333.
=========== REFERENCES ================
Brian Roark. 2011. Expected surprisal and entropy. Technical
Report #CSLU-11-004, Center for Spoken Language Processing, Oregon
Health & Science University.
Brian Roark, Asaf Bachrach, Carlos Cardenas and Christophe Pallier.
2009. Deriving lexical and syntactic expectation-based measures for
psycholinguistic modeling via incremental top-down parsing. In
Proceedings of the Conference on Empirical Methods in Natural Language
Processing (EMNLP), pp. 324-333.
Michael Collins and Brian Roark. 2004. Incremental Parsing with the
Perceptron Algorithm. In Proceedings of the 42nd Annual Meeting of the
Association for Computational Linguistics (ACL), pages 111-118.
Brian Roark. 2004. Robust garden path parsing. Natural Language
Engineering, 10(1), pages 1-24.
Brian Roark. 2001. Robust Probabilistic Predictive Syntactic
Processing: Motivations, Models, and Applications. Ph.D. Thesis,
Department of Cognitive and Linguistic Sciences, Brown University.
Brian Roark. 2001. Probabilistic top-down parsing and language
modeling. In Computational Linguistics, 27(2), pages 249-276.
Mark Johnson and Brian Roark. 2000. Compact non-left-recursive
grammars using the selective left-corner transform and factoring. In
Proceedings of the 18th International Conference on Computational
Linguistics (COLING), pages 355-361.
Brian Roark and Mark Johnson. 1999. Efficient probabilistic top-down
and left-corner parsing. In Proceedings of the 37th Annual Meeting of
the Association for Computational Linguistics, pages 421-428.