blob: 86ca47a6de195bca307419ebda7a956047837616 [file] [log] [blame]
Marc Kupietz83305222016-04-28 09:57:22 +02001<!DOCTYPE html>
2<html>
3 <head>
4 <title>DeReKo-Word-Vector-Distances: <%= $word %></title>
Marc Kupietz80bd7b92017-07-04 16:25:54 +02005 <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
6 <script src="http://code.jquery.com/jquery-latest.min.js"></script>
Marc Kupietz4abcd682017-11-28 20:51:08 +01007 <script src = "https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
8 <script src = "https://cdn.datatables.net/fixedcolumns/3.2.3/js/dataTables.fixedColumns.min.js"></script>
9 <link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">
Marc Kupietz80bd7b92017-07-04 16:25:54 +020010 <script
Marc Kupietzdab9f222017-11-29 14:22:59 +010011 src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
12 integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
13 crossorigin="anonymous"></script>
Marc Kupietz80bd7b92017-07-04 16:25:54 +020014 <script>
Marc Kupietz4abcd682017-11-28 20:51:08 +010015 $('#firstable').hide();
16 $(document).ready(function() {
17 $("#xxxtabs").tabs( {
18 "show": function(event, ui) {
19 var oTable = $('div.dataTables_scrollBody>table.display', ui.panel).dataTable();
20 if ( oTable.length > 0 ) {
21 oTable.fnAdjustColumnSizing();
22 }
23 }
24 } );
Marc Kupietz694610d2017-11-25 18:30:03 +010025
Marc Kupietzdab9f222017-11-29 14:22:59 +010026 $("input").bind("keydown", function(event) {
27 // track enter key
28 var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
29 if (keycode == 13) { // keycode for enter key
30 // force the 'Enter Key' to implicitly click the Update button
31 document.getElementById('SEARCH').click();
32 return false;
33 } else {
34 return true;
35 }});
36
Marc Kupietz4abcd682017-11-28 20:51:08 +010037 $(".selector").tabs({ active: 1 });
Marc Kupietz0af83e32017-11-27 09:31:37 +010038
Marc Kupietz4abcd682017-11-28 20:51:08 +010039 $('#firsttable').DataTable({
40 "sScrollY": "780px",
41 "bScrollCollapse": true,
42 "bPaginate": false,
43 "bJQueryUI": true,
44 "dom": '<"top">rt<"bottom"flp><"clear">',
45 "aoColumnDefs": [
46 { "sWidth": "10%", "aTargets": [ -1 ] }
47 ]
48 } );
Marc Kupietz0af83e32017-11-27 09:31:37 +010049
50 $('#secondtable').DataTable({
Marc Kupietz4abcd682017-11-28 20:51:08 +010051 "sScrollY": "800px",
52 "bScrollCollapse": true,
53 "bPaginate": false,
54 "bJQueryUI": true,
55 "dom": '<"top">rt<"bottom"flp><"clear">',
56 "aoColumnDefs": [
57 { "sWidth": "10%", "aTargets": [ -1 ] }
58 ]
59 } );
60 });
Marc Kupietz0af83e32017-11-27 09:31:37 +010061
Marc Kupietzdab9f222017-11-29 14:22:59 +010062 $(function(){
63 $("#dropdownoptions").dialog({
64 title: "Options",
65 autoOpen: false,
66 modal: false,
67 draggable: false,
68 height: "auto",
69 width: "auto",
70 resizable: false,
71 buttons: {
72 "Cancel": function() {
73 $( this ).dialog( "close" );
74 },
75 "Apply": function() {
76 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
77 }
78 }
79 });
80 });
81
82 $(function(){
83 $("#SEARCH").click(function() {
84 window.open($(location).attr('pathname')+'?'+$('form').serialize(), "_self");
85 });
86 });
87
88 $(function(){
89 $("#showoptions").click(function(){
90 $("#dropdownoptions").dialog("open");
91 var target = $(this);
92 $("#dropdownoptions").dialog("widget").position({
93 my: 'left bottom',
94 at: 'left bottom',
95 of: target
96 });
97 });
98 });
99
Marc Kupietz4abcd682017-11-28 20:51:08 +0100100 $( function() {
101 $( "#iterations" ).spinner({
102 spin: function( event, ui ) {
103 if ( ui.value < 1000 ) {
104 $( this ).spinner( "value", 1000 );
105 return false;
106 } else if ( ui.value > 10000 ) {
107 $( this ).spinner( "value", 10000 );
108 return false;
109 }
110 }
111 });
112 } );
Marc Kupietz3305b0a2017-11-27 10:46:20 +0100113
Marc Kupietz4abcd682017-11-28 20:51:08 +0100114 $( function() {
115 $( "#neighbours" ).spinner({
116 spin: function( event, ui ) {
117 if ( ui.value < 0 ) {
118 $( this ).spinner( "value", 0 );
119 return false;
120 } else if ( ui.value > 200 ) {
121 $( this ).spinner( "value", 200 );
122 return false;
123 }
124 }
125 });
126 } );
127
128 $( function() {
129 $( "#cutoff" ).spinner({
130 spin: function( event, ui ) {
131 if ( ui.value < 100000 ) {
132 $( this ).spinner( "value", 100000 );
133 return false;
134 } else if ( ui.value > 2000000 ) {
135 $( this ).spinner( "value", 2000000 );
136 return false;
137 }
138 }
139 });
140 } );
141
142 $( function() {
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100143 $( "#tabs" ).tabs(); // .addClass('ui-helper-clearfix tabs-left-vertical');
144 } );
Marc Kupietz4abcd682017-11-28 20:51:08 +0100145
146 $( function() {
147 $( ".controlgroup-vertical" ).controlgroup({
148 "direction": "vertical"
149 });
150 } );
151
152 $(function() {
153 $( document ).tooltip({
154 content: function() {
155 return $(this).attr('title');
156 }}
157 )
Marc Kupietz83305222016-04-28 09:57:22 +0200158 })
Marc Kupietz694610d2017-11-25 18:30:03 +0100159
Marc Kupietz83305222016-04-28 09:57:22 +0200160 </script>
161 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
Marc Kupietz554aff52017-11-09 14:42:09 +0100162 <script src="/derekovecs/js/tsne.js"></script>
163 <script src="/derekovecs/js/som.js"></script>
164 <script src="/derekovecs/js/labeler.js"></script>
Marc Kupietz83305222016-04-28 09:57:22 +0200165 <style>
166 body, input {
167 font-family: Arial, sans-serif;
168 font-size: 11pt;
169 }
Marc Kupietz30ca4342017-11-22 21:21:20 +0100170
Marc Kupietzdab9f222017-11-29 14:22:59 +0100171 .tabs-left-vertical .ui-tabs-nav {
172 position: absolute;
173 width: 21em;
174 transform: translate(-100%,0%) rotate(-90deg);
175 transform-origin: 100% 0%;
176 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100177
Marc Kupietzdab9f222017-11-29 14:22:59 +0100178 .tabs-left-vertical .ui-tabs-nav li {
179 float: right;
180 }
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100181
Marc Kupietzdab9f222017-11-29 14:22:59 +0100182 .tabs-left-vertical .ui-tabs-panel {
183 padding-left: 3.5em;
184 }
185
186 .tabs-left-vertical .ui-tabs-panel {
187 height: 20em;
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100188 }
189
Marc Kupietz30ca4342017-11-22 21:21:20 +0100190 .mono {
191 font-family: "DejaVu Sans Mono", Inconsolata, SourceCodePro, Courier;
192 }
193
Marc Kupietz83305222016-04-28 09:57:22 +0200194 .ui-tooltip-content {
195 font-size: 9pt;
196 color: #222222;
197 }
198
199 svg > .ui-tooltip-content {
200 font-size: 8pt;
201 color: #222222;
202 }
203
204 a.merged {
205 color: green;
206 fill: green;
207 }
208
209 #first a {
210 text-decoration: none;
211 }
212
213 a.marked, #first a.marked {
214 text-decoration: underline;
215 }
Marc Kupietzf4b49392016-04-28 10:49:56 +0200216
Marc Kupietz83305222016-04-28 09:57:22 +0200217 a.target {
218 color: red;
219 fill: red;
220 }
Marc Kupietz694610d2017-11-25 18:30:03 +0100221
Marc Kupietz4abcd682017-11-28 20:51:08 +0100222 table.display {
223 width: 40% important!;
224 margin: 1; /* <- works for me this way ****/
225 }
226 table.dataTable thead th, table.dataTable thead td, table.dataTable tbody td {
227 padding: 2px 2px;
228 // border-bottom: 1px solid #111;
229 }
Marc Kupietz83305222016-04-28 09:57:22 +0200230 #collocators {
231 margin-bottom: 15px;
232 }
233
Marc Kupietz4abcd682017-11-28 20:51:08 +0100234 #topwrapper {
Marc Kupietz83305222016-04-28 09:57:22 +0200235 width: 100%;
236 // border: 1px solid red;
237 overflow: hidden; /* will contain if #first is longer than #second */
238 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100239
240 #wrapper {
Marc Kupietz4abcd682017-11-28 20:51:08 +0100241 // border: 1px solid red;
242 overflow: hidden; /* will contain if #first is longer than #second */
243 }
244
245 #options {
246 float: right;
247 margin: 20px;
248 max-width: 280px;
249 overflow: hidden; /* if you don't want #second to wrap below #first */
250 }
251
Marc Kupietz83305222016-04-28 09:57:22 +0200252 #first {
253 margin-right: 20px;
254 float: left;
Marc Kupietz4abcd682017-11-28 20:51:08 +0100255 overflow: hidden; /* if you don't want #second to wrap below #first */
Marc Kupietz83305222016-04-28 09:57:22 +0200256 // border: 1px solid green;
257 }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100258 #tabs {
259 margin-right: 20px;
260 overflow: hidden; /* if you don't want #second to wrap below #first */
261 }
262
263 #embed {
264 max-width: 802px;
265 border: 1px solid #333;
266 }
267
Marc Kupietz83305222016-04-28 09:57:22 +0200268 #second {
Marc Kupietzb0173f12017-11-29 10:00:23 +0100269 min-width: 800px;
Marc Kupietzdab9f222017-11-29 14:22:59 +0100270 // border: 1px solid #333;
Marc Kupietz83305222016-04-28 09:57:22 +0200271 overflow: hidden; /* if you don't want #second to wrap below #first */
272 }
273 #som2 svg {
274 border: 1px solid #333;
275 }
276
277 #cost {
278 font-size: 8pt;
279 color: #222222;
280 margin-top: 4px;
281 margin-bottom: 12px;
282 }
283
284 #sominfo1, #sominfo {
285 font-size: 8pt;
286 color: #222222;
287 margin-top: 0px;
288 }
289
290 #somcolor1, #somcolor2, #somcolor3 {
291 display: inline-block;
292 height: 10px;
293 width: 10px;
294 }
295
296 #third {
297 border: 1px solid #333;
298 }
299
300 </style>
301 <script>
302
303 var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>},
304 mapWidth = 800, // width map
305 mapHeight = 800,
306 jitterRadius = 7;
307
308 var T = new tsnejs.tSNE(opt); // create a tSNE instance
309
310 var Y;
311
312 var data;
313 var labeler;
314
315 function applyJitter() {
Marc Kupietz4abcd682017-11-28 20:51:08 +0100316 svg.selectAll('.tsnet')
317 .data(labels)
318 .transition()
319 .duration(50)
320 .attr("transform", function(d, i) {
321 T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20;
322 T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20;
323 return "translate(" +
Marc Kupietzdab9f222017-11-29 14:22:59 +0100324 (d.x) + "," +
325 (d.y) + ")";
Marc Kupietz4abcd682017-11-28 20:51:08 +0100326 });
Marc Kupietz83305222016-04-28 09:57:22 +0200327 }
328
329 function updateEmbedding() {
Marc Kupietz4abcd682017-11-28 20:51:08 +0100330 var Y = T.getSolution();
331 svg.selectAll('.tsnet')
332 .data(data.words)
333 .attr("transform", function(d, i) {
334 return "translate(" +
Marc Kupietzdab9f222017-11-29 14:22:59 +0100335 ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," +
336 ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; });
Marc Kupietz83305222016-04-28 09:57:22 +0200337 }
338
339 var svg;
340 var labels = [];
341 var anchor_array = [];
342 var text;
343
344 function drawEmbedding() {
Marc Kupietz4abcd682017-11-28 20:51:08 +0100345 $("#embed").empty();
346 var div = d3.select("#embed");
347
348 // get min and max in each column of Y
349 var Y = T.Y;
350
351 svg = div.append("svg") // svg is global
352 .attr("width", mapWidth)
353 .attr("height", mapHeight);
354
355 var g = svg.selectAll(".b")
356 .data(data.words)
357 .enter().append("g")
358 .attr("class", "tsnet");
359
360 g.append("a")
361 .attr("xlink:href", function(word) {
362 return (data.urlprefix+word);})
363 .attr("class", function(d, i) {
364 var res="";
365 if(data.marked[i]) {
366 res="marked ";
367 }
368 if(data.target.indexOf(" "+d+" ") >= 0) {
369 return res+"target";
370 } else if(data.ranks[i] < data.mergedEnd) {
371 return res+"merged";
372 } else {
373 return res;
374 }
375 })
376 .attr("title", function(d, i) {
377 if(data.mergedEnd > 0) {
378 if(data.ranks[i] >= data.mergedEnd) {
379 return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
380 } else {
381 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)";
382 }
383 } else {
384 return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
385 }
386 })
387 .append("text")
388 .attr("text-anchor", "top")
389 .attr("font-size", 12)
390 .text(function(d) { return d; });
391
392 var zoomListener = d3.behavior.zoom()
393 .scaleExtent([0.1, 10])
394 .center([0,0])
395 .on("zoom", zoomHandler);
396 zoomListener(svg);
Marc Kupietz83305222016-04-28 09:57:22 +0200397 }
398
399 var tx=0, ty=0;
400 var ss=1;
401 var iter_id=-1;
402
403 function zoomHandler() {
Marc Kupietz4abcd682017-11-28 20:51:08 +0100404 tx = d3.event.translate[0];
405 ty = d3.event.translate[1];
406 ss = d3.event.scale;
407 updateEmbedding();
Marc Kupietz83305222016-04-28 09:57:22 +0200408 }
409
410 var stepnum = 0;
411
412 function stopStep() {
Marc Kupietz4abcd682017-11-28 20:51:08 +0100413 clearInterval(iter_id);
414 text = svg.selectAll("text");
415
416 // jitter function needs different data and co-ordinate representation
417 labels = d3.range(data.words.length).map(function(i) {
418 var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2;
419 var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2;
420 anchor_array.push({x: x, y: y, r: jitterRadius});
421 return {
422 x: x,
423 y: y,
424 name: data.words[i]
425 };
426 });
427
428 // get the actual label bounding boxes for the jitter function
429 var index = 0;
430 text.each(function() {
431 labels[index].width = this.getBBox().width;
432 labels[index].height = this.getBBox().height;
433 index += 1;
434 });
Marc Kupietz83305222016-04-28 09:57:22 +0200435
Marc Kupietz4abcd682017-11-28 20:51:08 +0100436
437 // setTimeout(updateEmbedding, 1);
438 // setTimeout(
439 labeler = d3.labeler()
440 .label(labels)
441 .anchor(anchor_array)
442 .width(mapWidth)
443 .height(mapHeight)
444 .update(applyJitter);
445 // .start(1000);
Marc Kupietz83305222016-04-28 09:57:22 +0200446
Marc Kupietz4abcd682017-11-28 20:51:08 +0100447 iter_id = setInterval(jitterStep, 1);
Marc Kupietz83305222016-04-28 09:57:22 +0200448 }
449
450 var jitter_i=0;
451
452 function jitterStep() {
Marc Kupietz4abcd682017-11-28 20:51:08 +0100453 if(jitter_i++ > 100) {
454 clearInterval(iter_id);
455 } else {
456 labeler.start2(10);
457 applyJitter();
458 }
Marc Kupietz83305222016-04-28 09:57:22 +0200459 }
460
461 var last_cost=1000;
462
463 function step() {
Marc Kupietz4abcd682017-11-28 20:51:08 +0100464 var i = T.iter;
465
466 if(i > <%= $no_iterations %>) {
467 stopStep();
468 } else {
469 var cost = Math.round(T.step() * 100000) / 100000; // do a few steps
470 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5));
471 if(i % 250 == 0 && cost >= last_cost) {
472 stopStep();
473 } else {
474 last_cost = cost;
475 updateEmbedding();
476 }
477 }
Marc Kupietz83305222016-04-28 09:57:22 +0200478 }
479
480 function showMap(j) {
Marc Kupietz4abcd682017-11-28 20:51:08 +0100481 data=j;
482 T.iter=0;
483 T.initDataRaw(data.vecs); // init embedding
484 drawEmbedding(); // draw initial embedding
485
486 if(iter_id >= 0) {
487 clearInterval(iter_id);
488 }
489 //T.debugGrad();
490 iter_id = setInterval(step, 1);
491 if(<%= $show_som %>) {
492 makeSOM(j, <%= $no_iterations %>);
493 }
Marc Kupietz83305222016-04-28 09:57:22 +0200494 }
Marc Kupietz39179ab2017-07-04 16:28:06 +0200495 var queryword;
496
497 function onload() {
Marc Kupietz4abcd682017-11-28 20:51:08 +0100498 queryword = document.getElementById('word');
Marc Kupietz39179ab2017-07-04 16:28:06 +0200499 }
500
501 function queryKorAP() {
502 window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP');
503 }
Marc Kupietz4dc270c2017-11-24 10:17:12 +0100504
505 function queryKorAPCII(query) {
506 window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP');
507 }
Marc Kupietz83305222016-04-28 09:57:22 +0200508 </script>
509 </head>
Marc Kupietz39179ab2017-07-04 16:28:06 +0200510 <body onload="onload()">
Marc Kupietz4abcd682017-11-28 20:51:08 +0100511 <div id="topwrapper">
512 <div id="options" class="widget">
Marc Kupietzdab9f222017-11-29 14:22:59 +0100513 <form id="queryform">
Marc Kupietz4abcd682017-11-28 20:51:08 +0100514 <input id="word" type="text" name="word" size="20" placeholder="Word(s) to be searched" value="<%= $word %>"
515 title="When looking for multiple words use spaces as separators to search around the average vector and | as separator to get the neighbours for each word."/>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100516 <input id="SEARCH" type="button" value="SEARCH">
517 <input type="button" id="showoptions" name="showoptions" value="Options" />
518 </form>
519 <div id="dropdownoptions" style="display: hidden">
520 <form id="optionsform">
Marc Kupietz4abcd682017-11-28 20:51:08 +0100521 <div class="controlgroup-vertical">
522 <label for="cutoff">cut-off</label>
523 <input id="cutoff" type="text" name="cutoff" size="10" value="<%= $cutoff %>" title="Only consider the most frequent x word forms.">
524 <label for="dedupe">dedupe</label>
525 <input id="dedupe" type="checkbox" name="dedupe" value="1" <%= ($dedupe ? "checked" : "") %> title="radically filter out any near-duplicates">
526 % if($mergedEnd > 0) {
527 <label for="sbf">backw.</label>
528 <input id="sbf" type="checkbox" name="sbf" value="1" <%= ($searchBaseVocabFirst ? "checked" : "") %> title="If checkecked base vocabulary will be searched first. Otherwise merged vocabulray will be searched first.">
529 % }
530 <label for="neighbours">max. neighbours:</label>
531 <input id="neighbours" size="4" name="n" value="<%= $no_nbs %>">
532 <label for="iterations">max. iterations</label>
533 <input id="iterations" name="N" size="4" value="<%= $no_iterations %>">
534 <label for="dosom">SOM</label>
535 <input id="dosom" type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>>
536 % if($collocators) {
537 <label for="sortby">window/sort</label>
538 <select id="sortby" name="sort">
539 <option value="0" <%= ($sort!=1 && $sort!=2? "selected":"") %>>auto focus</option>
540 <option value="1" <%= ($sort==1? "selected":"") %>>any single position</option>
541 <option value="2" <%= ($sort==2? "selected":"") %>>whole window</option>
542 </select>
543 % }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100544 <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100545 </div>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100546 </form>
547 </div>
Marc Kupietz0af83e32017-11-27 09:31:37 +0100548 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100549 <div id="tabs">
550 <ul>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100551 <li><a href="#tabs-1">Semantics (TSNE-map)</a></li>
552 <li><a href="#tabs-2">Semantics (SOM)</a></li>
553 <li><a href="#tabs-3">Syntagmatic (collocators)</a></li>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100554 </ul>
555 <div id="tabs-1">
Marc Kupietzdab9f222017-11-29 14:22:59 +0100556 % if($lists && (@$lists) > 0 && (@$lists)[0]) {
557 <div id="wrapper">
558 <div id="first" style="width:220px">
559 <table class="display compact nowrap" id="firsttable">
560 <thead>
561 <tr>
562 <th align="right">#</th><th align="right">cos</th><th align="left">paradigmatic</th>
563 </tr>
564 </thead>
565 <tbody>
566 % my $j=0; my @words; my @vecs; my @ranks; my @marked;
567 % for my $list (@$lists) {
568 % my $i=0; while($list) {
569 % my $item = (@$list)[$i];
570 % my $c = ($collocators? (@$collocators)[$i] : 0);
571 % last if(!$c && !$item);
572 <tr>
573 <td align="right">
574 <%= ++$i %>.
575 </td>
576 % if($item) {
577 % if(!grep{$_ eq $item->{word}} @words) {
578 % push @vecs, $item->{vector};
579 % push @words, $item->{word};
580 % push @ranks, $item->{rank};
581 % push @marked, ($marked->{$item->{word}}? 1 : 0);
Marc Kupietz4abcd682017-11-28 20:51:08 +0100582 % }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100583 <td align="right">
584 <%= sprintf("%.3f", $item->{dist}) %>
585 </td>
586 <td>
587 % my $class = ($marked->{$item->{word}}? "marked " : "");
588 % my $r = $item->{rank};
589 % if($r < $mergedEnd) {
590 % $class .= "merged";
591 % $r .= " (merged vocab)";
592 % } elsif($mergedEnd!=0 && $r > $mergedEnd) {
593 % $r -= $mergedEnd;
594 % }
595 <a class="<%= $class =%>"
596 title="freq. rank: <%= $r =%>"
597 href="<%= url_with->query([word => $item->{word}]) =%>">
598 <%= $item->{word} =%>
599 </a>
600 </td>
601 % } else {
602 <td colspan="2"/>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100603 % }
Marc Kupietzdab9f222017-11-29 14:22:59 +0100604 </tr>
605 % last if($i >= 100);
606 % }
607 % }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100608 </tbody>
609 </table>
610 </div>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100611 <script>
612 % use Mojo::ByteStream 'b';
613 % my $urlprefix = url_with->query([word=>'']);
614 $(window).load(function() {
615 showMap(<%= b(Mojo::JSON::to_json({target => " $word ", mergedEnd=> $mergedEnd, words => \@words, vecs => \@vecs, ranks => \@ranks, marked => \@marked, urlprefix => $urlprefix})); %>);
616 });
617 </script>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100618 % } else {
619 <div id="wrapper">
620 <p>
621 ERROR: "<%= $word %>" not found in vocabluary.
622 </p>
623 </div>
624 % }
625 <div id="second">
626 <div id="embed">
627 </div>
628 <div id="cost">
629 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100630 </div>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100631 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100632 </div>
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100633 <div id="tabs-2">
634 <div id="som2" style="width: 800; height: 800px">
635 </div>
636 <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div>
637 <div id="sominfo">SOM iteration <span id="iterations">0</span></div>
638 </div>
639 <div id="tabs-3">
Marc Kupietz4abcd682017-11-28 20:51:08 +0100640 <div id="second" style="width:500px">
641 <table class="display compact nowrap" id="secondtable">
642 <thead>
643 <tr>
644 % if($collocators) {
Marc Kupietzdab9f222017-11-29 14:22:59 +0100645 <th>#</th>
646 <th align="right" title="The window around the target word that is considered for summation.">w'</th>
647 <th align="right" title="Raw (max.) activation of the collocator in the output layers.">a</th>
648 <th title="Σp(c<sub><small>@</small></sub>) – Sum of the probability approximations that the combination of the target word and the collocator at the relative position @ come from the training corpus. Single approximations can be distorted because of sub-sampling frequent words and the sum cannot itself be interpreted as probability." align="right">Σp</th>
649 <th align="right">Σp/|w|</th>
650 <th title="c" align="left">collocator</th>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100651 % }
652 </tr>
Marc Kupietzdab9f222017-11-29 14:22:59 +0100653 </thead>
654 <tbody>
655 % for(my $i=0; $i < 100; $i++) {
656 % my $c = ($collocators? (@$collocators)[$i] : 0);
657 <tr>
658 <td align="right">
659 <%= $i %>
660 </td>
661 % if($c) {
662 <td align="right">
663 <span class="mono"><%= bitvec2window( $c->{pos} ) %></span>
664 </td>
665 <td align="right">
666 <%= sprintf("%.3f", $c->{dist}) %>
667 </td>
668 <td align="right">
669 <%= sprintf("%.3e", $c->{norm}) %>
670 </td>
671 <td align="right">
672 <%= sprintf("%.3e", $c->{sum}) %>
673 </td>
674 <td align="left">
675 <a onclick="<%= sprintf("queryKorAPCII('%s /w5 %s')", $c->{word}, $word) =%>"
676 title="freq. rank: <%= $c->{rank} =%>">
677 <%= $c->{word} %>
678 </a>
679 </td>
680 % } else {
681 <td colspan="5"/>
682 % }
683 </tr>
684 % }
685 </tbody>
686 </table>
687 </div> <!-- - tab2 -->
Marc Kupietz4fcda0c2017-11-29 09:00:31 +0100688 </div> <!-- tabs -->
689 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100690 </div> <!-- topwrapper -->
691 <div style="clear: both;"></div>
Marc Kupietz0af83e32017-11-27 09:31:37 +0100692 </div>
Marc Kupietz4abcd682017-11-28 20:51:08 +0100693 % if($training_args) {
694 <p>
695 Word vector model trained with <a href="https://code.google.com/p/word2vec/">word2vec</a> using the following parameters: <pre><%= $training_args %></pre>
696 </p>
Marc Kupietz83305222016-04-28 09:57:22 +0200697 % }
Marc Kupietz4abcd682017-11-28 20:51:08 +0100698 </body>
Marc Kupietz83305222016-04-28 09:57:22 +0200699</html>