Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>DeReKo-Word-Vector-Distances: <%= $word %></title> |
Marc Kupietz | 80bd7b9 | 2017-07-04 16:25:54 +0200 | [diff] [blame] | 5 | <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 Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 7 | <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 Kupietz | 80bd7b9 | 2017-07-04 16:25:54 +0200 | [diff] [blame] | 10 | <script |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 11 | src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js" |
| 12 | integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" |
| 13 | crossorigin="anonymous"></script> |
Marc Kupietz | 80bd7b9 | 2017-07-04 16:25:54 +0200 | [diff] [blame] | 14 | <script> |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 15 | $('#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 Kupietz | 694610d | 2017-11-25 18:30:03 +0100 | [diff] [blame] | 25 | |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 26 | $("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 Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 37 | $(".selector").tabs({ active: 1 }); |
Marc Kupietz | 0af83e3 | 2017-11-27 09:31:37 +0100 | [diff] [blame] | 38 | |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 39 | $('#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 Kupietz | 0af83e3 | 2017-11-27 09:31:37 +0100 | [diff] [blame] | 49 | |
| 50 | $('#secondtable').DataTable({ |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 51 | "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 Kupietz | 0af83e3 | 2017-11-27 09:31:37 +0100 | [diff] [blame] | 61 | |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 62 | $(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 Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 100 | $( 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 Kupietz | 3305b0a | 2017-11-27 10:46:20 +0100 | [diff] [blame] | 113 | |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 114 | $( 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 Kupietz | 4fcda0c | 2017-11-29 09:00:31 +0100 | [diff] [blame] | 143 | $( "#tabs" ).tabs(); // .addClass('ui-helper-clearfix tabs-left-vertical'); |
| 144 | } ); |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 145 | |
| 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 Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 158 | }) |
Marc Kupietz | 694610d | 2017-11-25 18:30:03 +0100 | [diff] [blame] | 159 | |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 160 | </script> |
| 161 | <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> |
Marc Kupietz | 554aff5 | 2017-11-09 14:42:09 +0100 | [diff] [blame] | 162 | <script src="/derekovecs/js/tsne.js"></script> |
| 163 | <script src="/derekovecs/js/som.js"></script> |
| 164 | <script src="/derekovecs/js/labeler.js"></script> |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 165 | <style> |
| 166 | body, input { |
| 167 | font-family: Arial, sans-serif; |
| 168 | font-size: 11pt; |
| 169 | } |
Marc Kupietz | 30ca434 | 2017-11-22 21:21:20 +0100 | [diff] [blame] | 170 | |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 171 | .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 Kupietz | 4fcda0c | 2017-11-29 09:00:31 +0100 | [diff] [blame] | 177 | |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 178 | .tabs-left-vertical .ui-tabs-nav li { |
| 179 | float: right; |
| 180 | } |
Marc Kupietz | 4fcda0c | 2017-11-29 09:00:31 +0100 | [diff] [blame] | 181 | |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 182 | .tabs-left-vertical .ui-tabs-panel { |
| 183 | padding-left: 3.5em; |
| 184 | } |
| 185 | |
| 186 | .tabs-left-vertical .ui-tabs-panel { |
| 187 | height: 20em; |
Marc Kupietz | 4fcda0c | 2017-11-29 09:00:31 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Marc Kupietz | 30ca434 | 2017-11-22 21:21:20 +0100 | [diff] [blame] | 190 | .mono { |
| 191 | font-family: "DejaVu Sans Mono", Inconsolata, SourceCodePro, Courier; |
| 192 | } |
| 193 | |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 194 | .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 Kupietz | f4b4939 | 2016-04-28 10:49:56 +0200 | [diff] [blame] | 216 | |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 217 | a.target { |
| 218 | color: red; |
| 219 | fill: red; |
| 220 | } |
Marc Kupietz | 694610d | 2017-11-25 18:30:03 +0100 | [diff] [blame] | 221 | |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 222 | 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 Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 230 | #collocators { |
| 231 | margin-bottom: 15px; |
| 232 | } |
| 233 | |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 234 | #topwrapper { |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 235 | width: 100%; |
| 236 | // border: 1px solid red; |
| 237 | overflow: hidden; /* will contain if #first is longer than #second */ |
| 238 | } |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 239 | |
| 240 | #wrapper { |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 241 | // 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 Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 252 | #first { |
| 253 | margin-right: 20px; |
| 254 | float: left; |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 255 | overflow: hidden; /* if you don't want #second to wrap below #first */ |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 256 | // border: 1px solid green; |
| 257 | } |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 258 | #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 Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 268 | #second { |
Marc Kupietz | b0173f1 | 2017-11-29 10:00:23 +0100 | [diff] [blame] | 269 | min-width: 800px; |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 270 | // border: 1px solid #333; |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 271 | 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 Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 316 | 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 Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 324 | (d.x) + "," + |
| 325 | (d.y) + ")"; |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 326 | }); |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | function updateEmbedding() { |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 330 | var Y = T.getSolution(); |
| 331 | svg.selectAll('.tsnet') |
| 332 | .data(data.words) |
| 333 | .attr("transform", function(d, i) { |
| 334 | return "translate(" + |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 335 | ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," + |
| 336 | ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; }); |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | var svg; |
| 340 | var labels = []; |
| 341 | var anchor_array = []; |
| 342 | var text; |
| 343 | |
| 344 | function drawEmbedding() { |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 345 | $("#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 Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | var tx=0, ty=0; |
| 400 | var ss=1; |
| 401 | var iter_id=-1; |
| 402 | |
| 403 | function zoomHandler() { |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 404 | tx = d3.event.translate[0]; |
| 405 | ty = d3.event.translate[1]; |
| 406 | ss = d3.event.scale; |
| 407 | updateEmbedding(); |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | var stepnum = 0; |
| 411 | |
| 412 | function stopStep() { |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 413 | 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 Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 435 | |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 436 | |
| 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 Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 446 | |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 447 | iter_id = setInterval(jitterStep, 1); |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | var jitter_i=0; |
| 451 | |
| 452 | function jitterStep() { |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 453 | if(jitter_i++ > 100) { |
| 454 | clearInterval(iter_id); |
| 455 | } else { |
| 456 | labeler.start2(10); |
| 457 | applyJitter(); |
| 458 | } |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | var last_cost=1000; |
| 462 | |
| 463 | function step() { |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 464 | 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 Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | function showMap(j) { |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 481 | 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 Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 494 | } |
Marc Kupietz | 39179ab | 2017-07-04 16:28:06 +0200 | [diff] [blame] | 495 | var queryword; |
| 496 | |
| 497 | function onload() { |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 498 | queryword = document.getElementById('word'); |
Marc Kupietz | 39179ab | 2017-07-04 16:28:06 +0200 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | function queryKorAP() { |
| 502 | window.open('http://korap.ids-mannheim.de/kalamar/?q='+queryword.value, 'KorAP'); |
| 503 | } |
Marc Kupietz | 4dc270c | 2017-11-24 10:17:12 +0100 | [diff] [blame] | 504 | |
| 505 | function queryKorAPCII(query) { |
| 506 | window.open('http://korap.ids-mannheim.de/kalamar/?ql=cosmas2&q='+query, 'KorAP'); |
| 507 | } |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 508 | </script> |
| 509 | </head> |
Marc Kupietz | 39179ab | 2017-07-04 16:28:06 +0200 | [diff] [blame] | 510 | <body onload="onload()"> |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 511 | <div id="topwrapper"> |
| 512 | <div id="options" class="widget"> |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 513 | <form id="queryform"> |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 514 | <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 Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 516 | <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 Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 521 | <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 Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 544 | <input type="button" value="→ KorAP" onclick="queryKorAP();" title="query word with KorAP"/> |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 545 | </div> |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 546 | </form> |
| 547 | </div> |
Marc Kupietz | 0af83e3 | 2017-11-27 09:31:37 +0100 | [diff] [blame] | 548 | </div> |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 549 | <div id="tabs"> |
| 550 | <ul> |
Marc Kupietz | 4fcda0c | 2017-11-29 09:00:31 +0100 | [diff] [blame] | 551 | <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 Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 554 | </ul> |
| 555 | <div id="tabs-1"> |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 556 | % 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 Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 582 | % } |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 583 | <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 Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 603 | % } |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 604 | </tr> |
| 605 | % last if($i >= 100); |
| 606 | % } |
| 607 | % } |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 608 | </tbody> |
| 609 | </table> |
| 610 | </div> |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 611 | <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 Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 618 | % } 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 Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 630 | </div> |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 631 | </div> |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 632 | </div> |
Marc Kupietz | 4fcda0c | 2017-11-29 09:00:31 +0100 | [diff] [blame] | 633 | <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 Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 640 | <div id="second" style="width:500px"> |
| 641 | <table class="display compact nowrap" id="secondtable"> |
| 642 | <thead> |
| 643 | <tr> |
| 644 | % if($collocators) { |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 645 | <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 Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 651 | % } |
| 652 | </tr> |
Marc Kupietz | dab9f22 | 2017-11-29 14:22:59 +0100 | [diff] [blame^] | 653 | </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 Kupietz | 4fcda0c | 2017-11-29 09:00:31 +0100 | [diff] [blame] | 688 | </div> <!-- tabs --> |
| 689 | </div> |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 690 | </div> <!-- topwrapper --> |
| 691 | <div style="clear: both;"></div> |
Marc Kupietz | 0af83e3 | 2017-11-27 09:31:37 +0100 | [diff] [blame] | 692 | </div> |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 693 | % 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 Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 697 | % } |
Marc Kupietz | 4abcd68 | 2017-11-28 20:51:08 +0100 | [diff] [blame] | 698 | </body> |
Marc Kupietz | 8330522 | 2016-04-28 09:57:22 +0200 | [diff] [blame] | 699 | </html> |