summaryrefslogtreecommitdiff
path: root/views/debug.haml
blob: 616bfeeda0c22d904e621cf4b15f6ef05adf3c0f (plain)
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
- require 'zipf'
!!!
%html
  %head
    %title Debug view (Session ##{session_key})
  %link(rel="stylesheet" type="text/css" href="debug.css")
  %script{:src => "http://postedit.cl.uni-heidelberg.de/js/jquery.min.js"}
  %script{:src => "http://postedit.cl.uni-heidelberg.de/js/jquery.tablesorter.min.js"}
  %script{:src => "http://postedit.cl.uni-heidelberg.de/js/debug.js"}
  %body
    %h1 Debug view
    %div#floater
      - if pairwise_ranking_data["kbest"].empty?
        %p.red
          %strong No data to show!
      %ul
        %li
          %a{ :href => "#controls" } Controls
        %li
          %a{ :href => "#post_edit" } Post-edit
        %li
          %a{ :href => "#grammar" } Grammar
        %li
          %a{ :href => "#weights" } Weights
        %li
          %a{ :href => "#kbest" } K-best

      %p.tiny Session: ##{session_key}

    /=#########################################################################
    %h2#controls Controls
    %h3 Reset
    %p
      %strong [Server reply]
      %span#control_reply
    %ul
      %li
        %a.ajax{:tgt => "/reset_progress",       :href => "#controls"} Reset progress
      %li
        %a.ajax{:tgt => "/reset_weights",        :href => "#controls"} Reset weights
      %li
        %a.ajax{:tgt => "/reset_learning_rates", :href => "#controls"} Reset learning rates
      %li
        %a.ajax{:tgt => "/reset_extractor",       :href => "#controls"} Reset extractor
      %li
        %a.ajax{:tgt => "/reset_new_rules",       :href => "#controls"} Reset new rules
      %li
        %a.ajax{:tgt => "/shutdown",              :href => "#controls"} Initiate shutdown
    %h3 Learning rates & weights
    %p Set default weight or rate for specific features:
    %select#features_type
      %option{ :value => "/set_weights" } Weight
      %option{ :value => "/set_learning_rates" } Rate
    %input#features{ :value => "Feature", :style => "text-align:center; width:20em" }
    %input#features_value{ :value => "1e-05", :style => "text-align:right; width:5em" }
    %button#set_features
      Set
    %p Set rate for feature groups:
    %select#feature_groups
      %option{ :value => "R" } rule ids
      %option{ :value => "RB" } rule bigrams 
      %option{ :value => "Shape" } rule shapes
    %input#feature_groups_value{ :value => "1e-05", :style => "text-align:right; width:5em" }
    %button#set_feature_groups
      Set rate


    /=#########################################################################
    %h2#post_edit Post-edit


    %p#original_svg_b64 #{data["original_svg"][progress]}
    %p Before:
    %div#original_svg

    %p#svg_b64 #{data["svg"][progress]}
    %p After:
    %div#svg

    %table
      %tr
        %td.noborder
          %strong Progress:
        %td.left.noborder #{[0,progress].max}
      %tr
        %td.noborder
          %strong MT Input:
        %td.left.noborder #{data["source_segments"][[0,progress].max]}
      %tr
        %td.noborder
          %strong Raw source:
        %td.left.noborder #{data["raw_source_segments"][[0,progress].max]}
      %tr
        %td.noborder
          %strong Post-edit:
        %td.left.noborder #{data["post_edits_raw"][progress]}
      %tr
        %td.noborder
          %strong Post-edit (processed):
        %td.left.noborder #{data["post_edits"][progress]}
      %tr
        %td.noborder
          %strong Original MT:
        %td.left.noborder #{data["mt_raw"][progress]}
      %tr
        %td.noborder
          %strong Displayed MT:
        %td.left.noborder #{data["mt"][progress]}
      %tr
        %td.noborder
          %strong Best match (BLEU=#{(pairwise_ranking_data["best_match_score"]*100).round(2)}%):
        %td.left.noborder #{pairwise_ranking_data["best_match"]}

    %h3 Metadata
    %p <strong>K:</strong>                      #{pairwise_ranking_data["samples_size"]}
    %p <strong>Number of updates:</strong>      #{pairwise_ranking_data["num_up"]}
    %p <strong>Updated features:</strong>       #{pairwise_ranking_data["updated_features"]}
    %p <strong>Duration:</strong>               #{data["durations"][progress]}ms
    %p <strong>Updated:</strong>                #{data["updated"][progress]}

    %h3 Derivation
    %p
      %a{:onclick => "$('#derivation').toggle()"} Show/hide original raw derivation.
    %pre#derivation{:style => "display:none"} #{data["derivations"][progress]}

    %h3 Client reply
    %p
      %a{:onclick => "$('#client_reply').toggle()"} Show/hide raw JSON client reply.
    - if data["feedback"][progress]
      - client_reply = JSON.parse(data["feedback"][progress])
      - client_reply["svg"] = "omitted"
      - client_reply["original_svg"] = "omitted"
      %pre#client_reply{ :style => "display:none" } #{JSON.pretty_generate(client_reply)}

    %p.up
      %a{ :href => "#" } ^ up

    /=#########################################################################
    %h2#grammar Grammar

    %h3
      New Rules
    %p Including OOV fixes.
    %table.sortable
      %thead
        %th Source
        %th
        %th Target
      %tbody
        - additional_rules.each do |rule_string|
          - nt, src, tgt, f, a = splitpipe(rule_string)
          %tr
            %td #{src}
            %td.big &#8611;
            %td #{tgt}

    %h3
      Known rules
    %table.sortable
      %thead
        %th Source
        %th
        %th Target
      %tbody
        - rejected_rules.each do |rule_string|
          - nt, src, tgt, f, a = splitpipe(rule_string)
          %tr
            %td #{src}
            %td.big &#8611;
            %td #{tgt}

    %p.up
      %a{ :href => "#" } ^ up

    /=#########################################################################
    %h2#weights Weights

    %p N.B. that updates are only done if the post-edit is different from the original 1-best output of the decoder.

    %h3 Weight updates
    %table.sortable
      %thead
        %tr
          %th Feature
          %th Before
          %th After
          %th Diff.
          %th Raw diff.
          %th Rate
      %tbody
        - if pairwise_ranking_data["update_raw"]
          - raw_update = SparseVector.from_kv(pairwise_ranking_data["update_raw"])
          - pairwise_ranking_data["weights_before"].default = 0
          - pairwise_ranking_data["weights_after"].keys.each.sort { |a,b| a <=> b }.each do |k|
            - diff = pairwise_ranking_data["weights_after"][k] - pairwise_ranking_data["weights_before"][k]
            - if diff != 0.0
              %tr
                %td.left <strong> #{k} </strong>
                %td.right #{"%+.3f" % pairwise_ranking_data["weights_before"][k]}
                %td.right #{"%+.3f" % pairwise_ranking_data["weights_after"][k]}
                - rdiff = diff.round 3
                - if diff < 0
                  %td.right.red #{rdiff}
                - elsif diff > 0
                  %td.right.green #{rdiff}
                %td.right #{"%+.1f"%(raw_update[k])}
                %td.right
                  - if pairwise_ranking_data["learning_rates"].has_key? k
                    #{pairwise_ranking_data["learning_rates"][k].round 10}
                  - elsif k.start_with? "R:"
                    #{pairwise_ranking_data["learning_rate_R"].round 10}
                  - elsif k.start_with? "RBS:" or k.start_with? "RBT:"
                    #{pairwise_ranking_data["learning_rate_RB"].round 10}
                  - elsif k.start_with? "Shape_"
                    #{pairwise_ranking_data["learning_rate_Shape"].round 10}
                  - else
                    ERROR: unknown key #{k}

    %p
      %a{ :onclick => "$('#features').toggle()" } Explanations
    %table#features{ :style => "display:none" }
      %tr
        %td EgivenFCoherent
        %td.left -log10[ c(e, f) / sample c(f) ]
      %tr
        %td NewRule
        %td.left New rules extracted from post-edits (this is the only feature of those rules)
      %tr
        %td KnownRule
        %td.left Added to already existing rules if they could be also be extracted from post-edits
      %tr
        %td OOVFix
        %td.left Manually added rules for OOV items
      %tr
        %td Glue
        %td.left Absolute number of rules used from glue grammar
      %tr
        %td IsSingletonF/E
        %td.left true|false (1|0) (sum)
      %tr
        %td IsSingletonFE
        %td.left true|false (1|0) (sum)
      %tr
        %td LanguageModel
        %td.left -log10[ score ]
      %tr
        %td LanguageModel_OOV
        %td.left Absolute count of OOV unigrams
      %tr
        %td MaxLexFgivenE
        %td.left Sum_f -log10(maxScore) (maxScore = max_e(ttable(f))
      %tr
        %td MaxLexEgivenF
        %td.left Sum_e -log10(maxScore) (maxScore = max_f(ttable(e))
      %tr
        %td PassThrough
        %td.left Absolute count of applied PassThrough rules
      %tr
        %td SampleCountF
        %td.left log10 [ sample c(f) ]
      %tr
        %td WordPenalty
        %td.left log_10(e)*|e| = 1/log(10) * |e| (*-1) = -0.43429448190325176*|e|
      %tr
        %td SourceWordPenalty
        %td.left As WordPenalty (|e| <=> |f|)
      %tr
        %td R:*
        %td.left Rule indicator features (sum of rule applications)
      %tr
        %td Shape_*
        %td.left Indicator features for rule shapes (39 in total)
      %tr
        %td IsSupportedOnline
        %td.left Rules with support from local context (Denkowski)

    %p.up
      %a{ :href => "#" } ^ up

    /=#########################################################################
    %h2#kbest K-best list
    %p
      %span.red In red:
      %span Update needed, i.e. "any of the above hypotheses has a lower model score" (in default order).
    %table.sortable
      %thead
        %tr
          %th.center{:style => "width:5%"}  Rank
          %th.center{:style => "width:5%"}  BLEU score
          %th.center{:style => "width:5%"}  Model score
          %th.center{:style => "width:5%"}  Original rank
          %th.center{:style => "width:5%"}  Token count
          %th.center{:style => "width:75%"} Translation
      %tbody
        - kbest = []
        - pairwise_ranking_data["kbest"].each { |i| x=splitpipe(i); kbest << [ x[0].to_f, x[1].to_f, x[2].to_i, x[3], x[4] ] }
        - kbest.sort! { |i,j| j[0] <=> i[0] }
        - kbest.each_with_index do |k,j|
          - add_class = ""
          - if kbest[0,j].map { |l| l[0]>k[0] && l[1]<k[1] }.include? true
            - add_class = "red"
          %tr{:class => "#{add_class}"}
            %td.center #{j+1}
            %td.center #{"%.2f"%(k[0].to_f*100)}
            %td.center #{k[1]}
            %td.center #{k[2]+1}
            %td.center #{k[4].split.size}
            %td
              %p #{k[4]}
              %p.toggle
                %a.tiny Features
              %table.kbest_features.small.mono.black{:style => "display:none"}
                %tr
                  %th Feature
                  %th Value
                - k[3].split.sort.each do |i|
                  - k,_,v = i.rpartition "="
                  %tr
                    %td #{k}
                    %td #{v}

    %p.up
      %a{ :href => "#" } ^ up