started on pure cnf version, see sec6 of formulas.pdf
[dmvccm.git] / DMVCCM.org.~9~
bloba3f2ad332a75385541ecf1a85145358d10a7b8fc
1 # -*- coding: mule-utf-8-unix -*-
2 #+STARTUP: overview
3 #+TAGS: OPTIMIZE PRETTIER
4 #+STARTUP: hidestars
5 #+TITLE: DMV/CCM
6 #+AUTHOR: Kevin Brubeck Unhammer
7 #+EMAIL: K.BrubeckUnhammer at student uva nl 
8 #+LANGUAGE: en
9 #+SEQ_TODO: TOGROK TODO DONE
10 #+OPTIONS: H:4 toc:3
12 * dmvccm
13   DEADLINE: <2008-06-30 Mon>
14 (But absolute, extended, really-quite-dead-now deadline: August 31...)
15 [[file:src/dmv.py][dmv.py]]
16 [[file:src/io.py][io.py]]
17 ** TODO Adjacency and combining it with inner()
18 Each DMV_Rule now has both a probN and a probA, for
19 adjacencies. inner() needs the correct one in each case.
21 Adjacency gives a problem with duplicate words/tags, eg. in the
22 sentence "a a b". If this has the dependency structure b->a_0->a_1,
23 then b is non-adjacent to a_0 and should use probN (for the LRStop and
24 the attachment of a_0), while the other rules should all use
25 probA. But within the e(0,2,b) we can't just say "oh, a has index 0
26 so it's not adjacent to 2", since there's also an a at index 1, and
27 there's also a dependency structure b->a_1->a_0 for that. We want
28 both. And in possibly much more complex versions.
30 Ideas:
31 - I first thought of decorating the individual words/tags in a
32   sentence with their indices, and perhaps just duplicating the
33   relevant rules (one for each index of the duplicate tags). But this
34   gives an explosion in attachment rules (although a contained
35   explosion, within the rules used in a sentence; but most sentences
36   will have at least two NN's so it will be a problem).
37 - Then, I had a /brilliant/ idea. Just let e(), the helper function of
38   inner(), parametrize for an extra pair of boolean values for whether
39   or not we've attached anything to the left or right yet. So now, e()
40   has a chart of the form [s, t, LHS, Lattach, Rattach], and of course
41   e(s,t,LHS) is the sum of the four possible values for
42   (Lattach,Rattach). This makes e() lots more complex and DMV-specific
43   though, so it's been rewritten in inner_dmv() in dmv.py.
44 *** TODO document this adjacency stuff better
45 *** TODO test and debug my brilliant idea
46 *** DONE implement my brilliant idea.
47     CLOSED: [2008-06-01 Sun 17:19]
48 [[file:src/dmv.py::def%20e%20s%20t%20LHS%20Lattach%20Rattach][e(sti) in dmv.py]]
50 *** DONE [#A] test inner() on sentences with duplicate words
51 Works with eg. the sentence "h h h"
54 ** TODO [#A] P_STOP for IO/EM
55 [[file:src/dmv.py::DMV%20probabilities][dmv-P_STOP]]
56 Remember: The P_STOP formula is upside-down (left-to-right also).
57 (In the article..not the thesis)
58 *** How is the P_STOP formula different given other values for dir and adj?
59 (Presumably, the P_STOP formula where STOP is True is just the
60 rule-probability of _h_ -> STOP h_ or h_ -> h STOP, but how does
61 adjacency fit in here?)
63 (And P_STOP(-STOP|...) = 1 - P_STOP(STOP|...) )
64 ** TODO P_CHOOSE for IO/EM
65 Write the formulas! should be easy?
66 ** Initialization   
67 [[file:~/Documents/Skole/V08/Probability/dmvccm/src/dmv.py::Initialization%20todo][dmv-inits]]
69 We do have to go through the corpus, since the probabilities are based
70 on how far away in the sentence arguments are from their heads.
71 *** TODO Separate initialization to another file?                     :PRETTIER:
72 (It's rather messy.)
73 *** TOGROK CCM Initialization    
74 P_SPLIT used here... how, again?
75 *** DONE DMV Initialization probabilities
76 (from initialization frequency)
77 *** DONE DMV Initialization frequencies    
78     CLOSED: [2008-05-27 Tue 20:04]
79 **** P_STOP    
80 P_STOP is not well defined by K&M. One possible interpretation given
81 the sentence [det nn vb nn] is
82 - f_STOP( STOP|det, L, adj) +1
83 - f_STOP(-STOP|det, L, adj) +0  
84 - f_STOP( STOP|det, L, non_adj) +1
85 - f_STOP(-STOP|det, L, non_adj) +0
86 - f_STOP( STOP|det, R, adj) +0
87 - f_STOP(-STOP|det, R, adj) +1
89 - f_STOP( STOP|nn, L, adj) +0
90 - f_STOP(-STOP|nn, L, adj) +1
91 - f_STOP( STOP|nn, L, non_adj) +1  # since there's at least one to the left
92 - f_STOP(-STOP|nn, L, non_adj) +0
94 **** P_CHOOSE
95 Go through the corpus, counting distances between heads and
96 arguments. In [det nn vb nn], we give 
97 - f_CHOOSE(nn|det, R) +1/1 + C
98 - f_CHOOSE(vb|det, R) +1/2 + C
99 - f_CHOOSE(nn|det, R) +1/3 + C
100   - If this were the full corpus, P_CHOOSE(nn|det, R) would have
101     (1+1/3+2C) / sum_a f_CHOOSE(a|det, R)
103 The ROOT gets "each argument with equal probability", so in a sentence
104 of three words, 1/3 for each (in [nn vb nn], 'nn' gets 2/3). Basically
105 just a frequency count of the corpus...
106 ** [#C] Deferred
107 *** TOGROK Some (tagged) sentences are bound to come twice            :OPTIMIZE:
108 Eg, first sort and count, so that the corpus
109 [['nn','vbd','det','nn'],
110  ['vbd','nn','det','nn'],
111  ['nn','vbd','det','nn']]
112 becomes
113 [(['nn','vbd','det','nn'],2),
114  (['vbd','nn','det','nn'],1)]
115 and then in each loop through sentences, make sure we handle the
116 frequency correctly.
117           
118 Is there much to gain here?
120 *** TOGROK tags as numbers or tags as strings?                        :OPTIMIZE:
121 Need to clean up the representation.
123 Stick with tag-strings in initialization then switch to numbers for
124 IO-algorithm perhaps? Can probably afford more string-matching in
125 initialization..
126 *** TOGROK Is the E-step in DMV just inner() on the full sentence? 
127 and What exactly is the M-step of DMV? 
128 *** COMMENT 
129 E: «For the initial symbols, I think we're supposed to
130 implement someone-or-other's POS tagger and use the parts of speech as
131 our tags. (K&M say they used parts of speech, anyway, and we can't use
132 the ones from the annotated corpus or else we won't be unsupervised
133 anymore.) I think you're right about how the tree is formed. The only
134 thing I'm not sure about is whether those left and right marks are
135 supposed to be part of the tree. I guess not because in a well-formed
136 tree, every word needs a stop on both sides, so actually all nodes
137 would be left and right marked in the end, which is the same as not
138 using them at all. So I guess they're relevant in the E step of EM,
139 but not the M step.» [[https://mail.google.com/mail/%3Ffs%3D1&tf%3D1&source%3Datom&view%3Dcv&search%3Dall&th%3D119b3e3d7d8f1d1f&shva%3D1&ui%3D1&disablechatbrowsercheck%3D1][gmail]]
141 K: About initialization, when they say they start with an M-step and get
142 a harmonic distribution (where close dependencies have higher
143 probabilities than far-away ones), I guess we could do this either in
144 a function of its own, or as a special case of the IO-algorithm -- I'm
145 not sure how different the harmonizing step will be from the regular
146 M-step. But I'm pretty sure harmonizing means having to go through the
147 whole corpus, since that's the only way we can find out distances for
148 each dependency (without having actual distance-numbers in the rules
149 in the first place). If sentence s is ABCD, rules from A to B should
150 have higher probability than rules from A to D. Assuming we find some
151 average distance between A and B, and A and D, etc. throughout the
152 corpus, we then have to turn those numbers into probabilities that sum
153 to 1; do you have any idea how to do that?
155 E: I think what it means to start with an M step is that we set the
156 probabilities without regard for the initial corpus. They say that
157 they start with an initial guess at "posterior distributions". I bet
158 the word "posterior" is important, but I don't know what it means
159 here. Do you?
160 *** TODO Corpus access
161 *** TOGROK sentences or rules as the "outer loop"?                    :OPTIMIZE:
162 In regard to the E/M-step, finding P_STOP, P_CHOOSE.
165 * Python-stuff
166 - [[file:src/pseudo.py][pseudo.py]]
167 - http://nltk.org/doc/en/structured-programming.html recursive dynamic
168 - http://nltk.org/doc/en/advanced-parsing.html 
169 - http://jaynes.colorado.edu/PythonIdioms.html