1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml"
4 lang=
"en" xml:
lang=
"en">
6 <title>DMV/CCM
– todo-list / progress
</title>
7 <meta http-equiv=
"Content-Type" content=
"text/html;charset=utf-8"/>
8 <meta name=
"generator" content=
"Org-mode"/>
9 <meta name=
"generated" content=
"2008/07/25 14:16:20"/>
10 <meta name=
"author" content=
"Kevin Brubeck Unhammer"/>
11 <link rel=
"stylesheet" type=
"text/css" href=
"http://www.student.uib.no/~kun041/org.css">
12 <!-- override with local style.css: -->
13 <link rel=
"stylesheet" type=
"text/css" href=
"./style.css">
15 <h1 class=
"title">DMV/CCM
– todo-list / progress
</h1>
16 <div id=
"table-of-contents">
17 <h2>Table of Contents
</h2>
18 <div id=
"text-table-of-contents">
20 <li><a href=
"#sec-1">1 DMV/CCM report and project
</a></li>
21 <li><a href=
"#sec-2">2 Notation
</a></li>
22 <li><a href=
"#sec-3">3 Testing the dependency parsed WSJ
</a>
24 <li><a href=
"#sec-3.1">3.1 [#A] Add
<code>(('ROOT',-
1), ('sentence_head', loc_h))
</code> to
<code>dep_parse
</code></a></li>
25 <li><a href=
"#sec-3.2">3.2 [#A]
<code>def evaluate
</code> </a></li>
28 <li><a href=
"#sec-4">4 Combine CCM with DMV
</a></li>
29 <li><a href=
"#sec-5">5 Reestimate P_ORDER ?
</a></li>
30 <li><a href=
"#sec-6">6 Most Probable Parse
</a>
32 <li><a href=
"#sec-6.1">6.1 Find MPP with CCM
</a></li>
33 <li><a href=
"#sec-6.2">6.2 Find Most Probable Parse of given test sentence, in DMV
</a></li>
36 <li><a href=
"#sec-7">7 [#C] Alternative CNF for DMV
</a>
38 <li><a href=
"#sec-7.1">7.1 move as much as possible into common_dmv.py
</a></li>
39 <li><a href=
"#sec-7.2">7.2 dmv2cnf re-estimation formulas
</a></li>
40 <li><a href=
"#sec-7.3">7.3 dmv2cnf IO formulas
</a></li>
41 <li><a href=
"#sec-7.4">7.4 complete programming the dmv2cnf versions of dmv.py and harmonic.py
</a></li>
44 <li><a href=
"#sec-8">8 Initialization
</a>
46 <li><a href=
"#sec-8.1">8.1 CCM Initialization
</a></li>
49 <li><a href=
"#sec-9">9 [#C] Deferred
</a>
51 <li><a href=
"#sec-9.1">9.1 Clean up reestimation code
</a></li>
52 <li><a href=
"#sec-9.2">9.2 [#A] compare speed of w_left/right(
…) and w(LEFT/RIGHT,
…)
</a></li>
53 <li><a href=
"#sec-9.3">9.3 when reestimating P_STOP etc, remove rules with p
< epsilon
</a></li>
54 <li><a href=
"#sec-9.4">9.4 inner_dmv, short ranges and impossible attachment
</a></li>
55 <li><a href=
"#sec-9.5">9.5 clean up the module files
</a></li>
56 <li><a href=
"#sec-9.6">9.6 Some (tagged) sentences are bound to come twice
</a></li>
57 <li><a href=
"#sec-9.7">9.7 tags as numbers or tags as strings?
</a></li>
60 <li><a href=
"#sec-10">10 Adjacency and combining it with the inside-outside algorithm
</a>
62 <li><a href=
"#sec-10.1">10.1 Possible alternate type of adjacency
</a></li>
65 <li><a href=
"#sec-11">11 Python-stuff
</a></li>
66 <li><a href=
"#sec-12">12 Git
</a></li>
71 <div id=
"outline-container-1" class=
"outline-2">
72 <h2 id=
"sec-1">1 DMV/CCM report and project
</h2>
77 DMV-
<a href=
"tex/formulas.pdf">formulas.pdf
</a> – <i>clear
</i> information =D
81 <a href=
"src/io.py">io.py
</a>
84 <a href=
"src/loc_h_harmonic.py">loc_h_harmonic.py
</a>
87 <a href=
"src/loc_h_dmv.py">loc_h_dmv.py
</a>
90 <a href=
"src/common_dmv.py">common_dmv.py
</a>
93 <a href=
"src/wsjdep.py">wsjdep.py
</a>
96 <a href=
"src/main.py">main.py
</a>
102 <p><a href=
"http://www.student.uib.no/~kun041/dmvccm/DMVCCM_archive.html">Archived entries
</a> from this file.
107 <div id=
"outline-container-2" class=
"outline-2">
108 <h2 id=
"sec-2">2 Notation
</h2>
112 old notes: new notes: in tex/code (constants): in Klein thesis:
113 --------------------------------------------------------------------------------------
114 _h_ _h_ SEAL bar over h
115 h_ h
>< RGOL right-under-left-arrow over h
116 h h
> GOR right-arrow over h
118 ><h LGOR left-under-right-arrow over h
119 <h GOL left-arrow over h
121 These are represented in the code as pairs
<code>(s_h,h)
</code>, where
<code>h
</code> is an
122 integer (POS-tag) and
<code>s_h
</code> ∈ <code>{SEAL,RGOL,GOR,LGOR,GOL}
</code>.
125 <code>P_ATTACH
</code> and
<code>P_CHOOSE
</code> are synonymous, I try to use the
128 P_GO_AT(a|h,dir,adj) := P_ATTACH(a|h,dir)*(
1-P_STOP(STOP|h,dir,adj)
132 (precalculated after each reestimation with
<code>g.p_GO_AT = make_GO_AT(g.p_STOP,g.p_ATTACH)
</code>)
138 <div id=
"outline-container-3" class=
"outline-2">
139 <h2 id=
"sec-3">3 Testing the dependency parsed WSJ
</h2>
142 <p><a href=
"src/wsjdep.py">wsjdep.py
</a> uses NLTK (sort of) to get a dependency parsed version of
143 WSJ10 into the format used in mpp() in loc_h_dmv.py.
146 As a default,
<code>WSJDepCorpusReader
</code> looks for the file
<code>wsj.combined
.10.dep
</code> in
147 <code>../corpus/wsjdep
</code>.
150 Only
<code>sents()
</code>,
<code>tagged_sents()
</code> and
<code>parsed_sents()
</code> (plus a new function
151 <code>tagonly_sents()
</code>) are implemented, the other NLTK corpus functions are
152 ..um.. undefined
…
156 <div id=
"outline-container-3.1" class=
"outline-3">
157 <h3 id=
"sec-3.1">3.1 <span class=
"todo">TODO
</span> [#A] Add
<code>(('ROOT',-
1), ('sentence_head', loc_h))
</code> to
<code>dep_parse
</code></h3>
160 <p><a href=
"src/wsjdep.py">wsjdep.py
</a>
165 <div id=
"outline-container-3.2" class=
"outline-3">
166 <h3 id=
"sec-3.2">3.2 <span class=
"todo">TODO
</span> [#A]
<code>def evaluate
</code> </h3>
169 <p><a href=
"src/main.py">main.py
</a>
172 (just has to count how many pairs are in there; Precision and Recall)
178 <div id=
"outline-container-4" class=
"outline-2">
179 <h2 id=
"sec-4">4 <span class=
"todo">TOGROK
</span> Combine CCM with DMV
</h2>
184 <a name=
"comboquestions"> </a>
187 Questions about the
<code>P_COMBO
</code> info in
<a href=
"http://www.eecs.berkeley.edu/~klein/papers/klein_thesis.pdf">Klein's thesis
</a>:
190 Page
109 (pdf:
125): We have to premultiply
"all our probabilities"
191 by the CCM base product
<i>Π<sub><i,j
></sub> P
<sub>SPAN
</sub>(
α(i,j,s)|false)P
<sub>CONTEXT
</sub>(
β(i,j,s)|false)
</i>; which
192 probabilities are included under
"all"? I'm assuming this includes
193 <code>P_ATTACH
</code> since each time
<code>P_ATTACH
</code> is used,
<i>φ</i> is multiplied in
194 (pp
.110-
111 ibid.); but
<i>φ</i> is not used for STOPs, so should we not
195 have our CCM product multiplied in there? How about
<code>P_ROOT
</code>?
196 (Guessing
<code>P_ORDER
</code> is way out of the question
…)
199 For the outside probabilities, is it correct to assume we multiply
200 in
<i>φ(j,k)
</i> or
<i>φ(k,i)
</i> when calculating
<code>inner(i,j...)
</code>? (Eg., only
201 for the outside part, not for the whole range.) I don't understand
202 the notation in
<code>O()
</code> on p
.103.
209 <div id=
"outline-container-5" class=
"outline-2">
210 <h2 id=
"sec-5">5 <span class=
"todo">TOGROK
</span> Reestimate P_ORDER ?
</h2>
217 <div id=
"outline-container-6" class=
"outline-2">
218 <h2 id=
"sec-6">6 Most Probable Parse
</h2>
224 <div id=
"outline-container-6.1" class=
"outline-3">
225 <h3 id=
"sec-6.1">6.1 <span class=
"todo">TOGROK
</span> Find MPP with CCM
</h3>
232 <div id=
"outline-container-6.2" class=
"outline-3">
233 <h3 id=
"sec-6.2">6.2 <span class=
"done">DONE
</span> Find Most Probable Parse of given test sentence, in DMV
</h3>
236 <p><span class=
"timestamp-kwd">CLOSED:
</span> <span class=
"timestamp">2008-
07-
23 Wed
10:
56</span><br/>
237 inner() optionally keeps track of the highest probability children of
238 any node in
<code>mpptree
</code>. Say we're looking for
<code>inner(i,j,(s_h,h),loc_h)
</code> in
239 a certain sentence, and we find some possible left and right children,
240 we add to
<code>mpptree[i,j,(s_h,h),loc_h]
</code> the triple
<code>(p, L, R)
</code> where
<code>L
</code> and
241 <code>R
</code> are of the same form as the key (
<code>i,j,(s_h,h),loc_h
</code>) and
<code>p
</code> is the
242 probability of this node rewriting to
<code>L
</code> and
<code>R
</code>,
243 eg.
<code>inner(L)*inner(R)*p_GO_AT
</code> or
<code>p_STOP
</code> or whatever. We only add this
244 entry to
<code>mpptree
</code> if there wasn't a higher-probability entry there
248 Then, after
<code>inner_sent
</code> makes an
<code>mpptree
</code>, we find the
<i>relevant
</i>
249 head-argument pairs by searching through the tree using a queue,
250 adding the
<code>L
</code> and
<code>R
</code> keys of any entry to the queue as we find them
251 (skipping
<code>STOP
</code> keys), and adding any attachment entries to a set of
252 triples
<code>(head,argument,dir)
</code>. Thus we have our most probable parse,
255 set([( ROOT, (vbd,
2),RIGHT),
256 ((vbd,
2),(nn,
1),LEFT),
257 ((vbd,
2),(nn,
3),RIGHT),
258 ((nn,
1),(det,
0),LEFT)])
265 <div id=
"outline-container-7" class=
"outline-2">
266 <h2 id=
"sec-7">7 <span class=
"todo">TOGROK
</span> [#C] Alternative CNF for DMV
</h2>
269 <p>Alternatively; use rules of this form:
270 <a name=
"dmv2cnf"> </a>
273 h[RA] Non-Terminal, attaching for the first time to the right
274 h[RN] Non-Terminal, attaching non-adjacently to the right
275 h_[RA] Non-Terminal, stopping to the right adjacently
276 h_[RN] Non-Terminal, stopping to the right non-adjacently
277 h_[LA] Non-Terminal, attaching for the first time to the left
278 h_[LN] Non-Terminal, attaching non-adjacently to the left
279 _h_[LA] Non-Terminal, stopping to the left adjacently
280 _h_[LN] Non-Terminal, stopping to the left non-adjacently
285 h[RA] -
> h _a_[LA] # adjacent right attachment must go to
"terminal"
286 h[RA] -
> h _a_[LN] # adjacent right attachment must go to
"terminal"
288 h[RN] -
> h[RA] _a_[LA] # already attached to right
289 h[RN] -
> h[RN] _a_[LN]
291 h_[RA] -
> h STOP # adjacent right stop must go to
"terminal"
292 h_[RN] -
> h[RN] STOP # o/w non-adjacent
293 h_[RN] -
> h[RA] STOP
295 h_[LA] -
> _a_[LA] h_[RA] # adjacent left attachment must
296 h_[LA] -
> _a_[LN] h_[RN] # go to mothers of stop rules
298 h_[LN] -
> _a_[LA] h_[LN] # already attached to left
299 h_[LN] -
> _a_[LN] h_[LA]
301 _h_[LA] -
> STOP h_[RA] # adjacent left stop goes
302 _h_[LA] -
> STOP h_[RN] # straight to a right stop
304 _h_[LN] -
> STOP h_[LA] # non-adjacent left stop
305 _h_[LN] -
> STOP h_[LN] # goes to a left attachment rule
309 The reestimation function still has to sum over the various
310 possibilities of N's and A's; but it seems to be simpler than the
311 loc_h-method altogether.
314 One might reduce the number of rules a tiny bit, by having eg. unary rules
319 etc. (although that might just make it all more confusing)
324 <div id=
"outline-container-7.1" class=
"outline-3">
325 <h3 id=
"sec-7.1">7.1 <span class=
"todo">TODO
</span> move as much as possible into common_dmv.py
</h3>
328 <p><a href=
"src/common_dmv.py">common_dmv.py
</a>
331 …and improve cnf vs loc_h classes (at
<i>least
</i> give them different names)
336 <div id=
"outline-container-7.2" class=
"outline-3">
337 <h3 id=
"sec-7.2">7.2 <span class=
"todo">TODO
</span> dmv2cnf re-estimation formulas
</h3>
340 <p><a href=
"tex/formulas.tex">tex
</a>
345 <div id=
"outline-container-7.3" class=
"outline-3">
346 <h3 id=
"sec-7.3">7.3 <span class=
"todo">TODO
</span> dmv2cnf IO formulas
</h3>
349 <p><a href=
"tex/formulas.tex">tex
</a>
350 draw some trees first? Or, they should be the same as L
&Y apart
351 from also having the STOP rules
356 <div id=
"outline-container-7.4" class=
"outline-3">
357 <h3 id=
"sec-7.4">7.4 <span class=
"todo">TODO
</span> complete programming the dmv2cnf versions of dmv.py and harmonic.py
</h3>
365 <div id=
"outline-container-8" class=
"outline-2">
366 <h2 id=
"sec-8">8 Initialization
</h2>
369 <p><a href=
"/Users/kiwibird/Documents/Skole/V08/Probability/dmvccm/src/dmv.py">dmv-inits
</a>
372 We go through the corpus, since the probabilities are based on how far
373 away in the sentence arguments are from their heads.
377 <div id=
"outline-container-8.1" class=
"outline-3">
378 <h3 id=
"sec-8.1">8.1 <span class=
"todo">TOGROK
</span> CCM Initialization
</h3>
381 <p>P
<sub>SPLIT
</sub> used here
… how, again?
387 <div id=
"outline-container-9" class=
"outline-2">
388 <h2 id=
"sec-9">9 [#C] Deferred
</h2>
391 <p><a href=
"http://wiki.python.org/moin/PythonSpeed/PerformanceTips">http://wiki.python.org/moin/PythonSpeed/PerformanceTips
</a> Eg., use
392 map/reduce/filter/[i for i in [i's]]/(i for i in [i's]) instead of
393 for-loops; use local variables for globals (global variables or or
398 <div id=
"outline-container-9.1" class=
"outline-3">
399 <h3 id=
"sec-9.1">9.1 <span class=
"todo">TODO
</span> Clean up reestimation code
<span class=
"tag">PRETTIER
</span></h3>
406 <div id=
"outline-container-9.2" class=
"outline-3">
407 <h3 id=
"sec-9.2">9.2 <span class=
"todo">TODO
</span> [#A] compare speed of w_left/right(
…) and w(LEFT/RIGHT,
…)
<span class=
"tag">OPTIMIZE
</span></h3>
414 <div id=
"outline-container-9.3" class=
"outline-3">
415 <h3 id=
"sec-9.3">9.3 <span class=
"todo">TODO
</span> when reestimating P_STOP etc, remove rules with p
< epsilon
<span class=
"tag">OPTIMIZE
</span></h3>
422 <div id=
"outline-container-9.4" class=
"outline-3">
423 <h3 id=
"sec-9.4">9.4 <span class=
"todo">TODO
</span> inner_dmv, short ranges and impossible attachment
<span class=
"tag">OPTIMIZE
</span></h3>
426 <p>If s-t
<=
2, there can be only one attachment below, so don't recurse
427 with both Lattach=True and Rattach=True.
430 If s-t
<=
1, there can be no attachment below, so only recurse with
431 Lattach=False, Rattach=False.
434 Put this in the loop under rewrite rules (could also do it in the STOP
435 section, but that would only have an effect on very short sentences).
440 <div id=
"outline-container-9.5" class=
"outline-3">
441 <h3 id=
"sec-9.5">9.5 <span class=
"todo">TODO
</span> clean up the module files
<span class=
"tag">PRETTIER
</span></h3>
444 <p>Is there better way to divide dmv and harmonic? There's a two-way
445 dependency between the modules. Guess there could be a third file that
446 imports both the initialization and the actual EM stuff, while a file
447 containing constants and classes could be imported by all others:
449 dmv.py imports dmv_EM.py imports dmv_classes.py
450 dmv.py imports dmv_inits.py imports dmv_classes.py
457 <div id=
"outline-container-9.6" class=
"outline-3">
458 <h3 id=
"sec-9.6">9.6 <span class=
"todo">TOGROK
</span> Some (tagged) sentences are bound to come twice
<span class=
"tag">OPTIMIZE
</span></h3>
461 <p>Eg, first sort and count, so that the corpus
462 [['nn','vbd','det','nn'],
463 ['vbd','nn','det','nn'],
464 ['nn','vbd','det','nn']]
466 [(['nn','vbd','det','nn'],
2),
467 (['vbd','nn','det','nn'],
1)]
468 and then in each loop through sentences, make sure we handle the
472 Is there much to gain here?
478 <div id=
"outline-container-9.7" class=
"outline-3">
479 <h3 id=
"sec-9.7">9.7 <span class=
"todo">TOGROK
</span> tags as numbers or tags as strings?
<span class=
"tag">OPTIMIZE
</span></h3>
482 <p>Need to clean up the representation.
485 Stick with tag-strings in initialization then switch to numbers for
486 IO-algorithm perhaps? Can probably afford more string-matching in
493 <div id=
"outline-container-10" class=
"outline-2">
494 <h2 id=
"sec-10">10 Adjacency and combining it with the inside-outside algorithm
</h2>
497 <p>Each DMV_Rule has both a probN and a probA, for adjacencies. inner()
498 and outer() needs the correct one in each case.
501 In each inner() call, loc_h is the location of the head of this
502 dependency structure. In each outer() call, it's the head of the
<i>Node
</i>,
503 the structure we're looking outside of.
506 We call inner() for each location of a head, and on each terminal,
507 loc_h must equal
<code>i
</code> (and
<code>loc_h+
1</code> equal
<code>j
</code>). In the recursive attachment
508 calls, we use the locations (sentence indices) of words to the left or
509 right of the head in calls to inner().
<i>loc_h lets us check whether we need probN or probA
</i>.
513 <div id=
"outline-container-10.1" class=
"outline-3">
514 <h3 id=
"sec-10.1">10.1 Possible alternate type of adjacency
</h3>
517 <p>K
&M's adjacency is just whether or not an argument has been generated
518 in the current direction yet. One could also make a stronger type of
519 adjacency, where h and a are not adjacent if b is in between, eg. with
520 the sentence
"a b h" and the structure ((h-
>a), (a-
>b)), h is
521 K
&M-adjacent to a, but not next to a, since b is in between. It's easy
522 to check this type of adjacency in inner(), but it needs new rules for
529 <div id=
"outline-container-11" class=
"outline-2">
530 <h2 id=
"sec-11">11 Python-stuff
</h2>
533 <p>Make those debug statements steal a bit less attention in emacs:
535 (font-lock-add-keywords
536 'python-mode ; not really regexp, a bit slow
537 '((
"^\\( *\\)\\(\\if +'.+' +in +io.DEBUG. *\\(
538 \\1 .+$\\)+\\)" 2 font-lock-preprocessor-face t)))
539 (font-lock-add-keywords
541 '((
"\\<\\(\\(io\\.\\)?debug(.+)\\)" 1 font-lock-preprocessor-face t)))
546 <a href=
"src/pseudo.py">pseudo.py
</a>
549 <a href=
"http://nltk.org/doc/en/structured-programming.html">http://nltk.org/doc/en/structured-programming.html
</a> recursive dynamic
552 <a href=
"http://nltk.org/doc/en/advanced-parsing.html">http://nltk.org/doc/en/advanced-parsing.html
</a>
555 <a href=
"http://jaynes.colorado.edu/PythonIdioms.html">http://jaynes.colorado.edu/PythonIdioms.html
</a>
565 <div id=
"outline-container-12" class=
"outline-2">
566 <h2 id=
"sec-12">12 Git
</h2>
569 <p>Repository web page:
<a href=
"http://repo.or.cz/w/dmvccm.git">http://repo.or.cz/w/dmvccm.git
</a>
572 Setting up a new project:
576 git commit -m
"first release"
580 Later on: (
<code>-a
</code> does
<code>git rm
</code> and
<code>git add
</code> automatically)
583 git commit -a -m
"some subsequent release"
587 Then push stuff up to the remote server:
589 git push git+ssh://username@repo.or.cz/srv/git/dmvccm.git master
593 (
<code>eval `ssh-agent`
</code> and
<code>ssh-add
</code> to avoid having to type in keyphrase all
597 Make a copy of the (remote) master branch:
599 git clone git://repo.or.cz/dmvccm.git
603 Make and name a new branch in this folder
605 git checkout -b mybranch
609 To save changes in
<code>mybranch
</code>:
615 Go back to the master branch (uncommitted changes from
<code>mybranch
</code> are
624 git add --interactive
629 <a href=
"http://www-cs-students.stanford.edu/~blynn//gitmagic/">http://www-cs-students.stanford.edu/~blynn//gitmagic/
</a>
632 <div id=
"postamble"><p class=
"author"> Author: Kevin Brubeck Unhammer
633 <a href=
"mailto:K.BrubeckUnhammer at student uva nl "><K.BrubeckUnhammer at student uva nl
></a>
635 <p class=
"date"> Date:
2008/
07/
25 14:
16:
20</p>
636 </div><p class=
"nn-postamble">Skrive vha. emacs +
<a href='http://orgmode.org/'
>org-mode
</a></p></body>