blob: cc08e4b85cff4e351de294f0eadda101bcafad78 [file] [log] [blame]
Marc Kupietzdc22b982015-10-09 09:19:34 +02001#!/usr/local/bin/perl
2use Inline C;
3use Mojolicious::Lite;
Marc Kupietzc4893362016-02-25 08:04:46 +01004use Mojo::JSON qw(decode_json encode_json to_json);
Marc Kupietz247500f2015-10-09 11:29:01 +02005use Encode qw(decode encode);
Marc Kupietz7bc85fd2016-02-24 11:42:41 +01006use Mojo::Server::Daemon;
Marc Kupietzdc22b982015-10-09 09:19:34 +02007
Marc Kupietzc5990da2016-02-26 08:47:12 +01008print STDERR $ARGV[0];
Marc Kupietz7bc85fd2016-02-24 11:42:41 +01009# -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -threads 40 -binary 1 -iter 15
Marc Kupietz44bee3c2016-02-25 16:26:29 +010010init_net("vectors15.bin");
Marc Kupietzdc22b982015-10-09 09:19:34 +020011
12get '/' => sub {
13 my $c = shift;
14 my $word=$c->param('word');
Marc Kupietz44bee3c2016-02-25 16:26:29 +010015 my $no_nbs=$c->param('n') || 100;
16 my $no_iterations=$c->param('N') || 2000;
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +010017 my @lists;
Marc Kupietz7bc85fd2016-02-24 11:42:41 +010018 if(defined($word) && $word !~ /^\s*$/) {
19 $c->inactivity_timeout(300);
Marc Kupietz44bee3c2016-02-25 16:26:29 +010020 $word =~ s/\s+/ /g;
21 for my $w (split(' *\| *', $word)) {
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +010022 $c->app->log->debug('Looking for neighbours of '.$w);
23 push(@lists, get_neighbours(encode("iso-8859-1", $w), $no_nbs));
24 }
Marc Kupietz247500f2015-10-09 11:29:01 +020025 }
Marc Kupietz44bee3c2016-02-25 16:26:29 +010026 $c->render(template=>"index", word=>$word, no_nbs=>$no_nbs, no_iterations => $no_iterations, lists=> \@lists);
Marc Kupietzdc22b982015-10-09 09:19:34 +020027};
28
29app->start;
30
31exit;
32
33__END__
34
35__C__
36#include <stdio.h>
37#include <string.h>
38#include <math.h>
39#include <malloc.h>
40#include <stdlib.h> //strlen
Marc Kupietzf0809762016-02-26 10:13:47 +010041#include <sys/mman.h>
Marc Kupietzdc22b982015-10-09 09:19:34 +020042
43#define max_size 2000
44#define max_w 50
Marc Kupietz7bc85fd2016-02-24 11:42:41 +010045#define MAX_NEIGHBOURS 1000
Marc Kupietz44bee3c2016-02-25 16:26:29 +010046#define MAX_WORDS -1
Marc Kupietzdc22b982015-10-09 09:19:34 +020047
48//the thread function
49void *connection_handler(void *);
50
Marc Kupietz7bc85fd2016-02-24 11:42:41 +010051char *bestw[MAX_NEIGHBOURS];
Marc Kupietzdc22b982015-10-09 09:19:34 +020052char file_name[max_size], st[100][max_size];
Marc Kupietz7bc85fd2016-02-24 11:42:41 +010053float dist, len, bestd[MAX_NEIGHBOURS], vec[max_size];
Marc Kupietzc4893362016-02-25 08:04:46 +010054long long words, size, a, b, c, d, cn, bi[100], besti[MAX_NEIGHBOURS];
Marc Kupietzdc22b982015-10-09 09:19:34 +020055char ch;
56float *M;
57char *vocab;
58char *stringBuffer;
59
60int init_net(char *file_name) {
Marc Kupietz67c20282016-02-26 09:42:00 +010061 FILE *f, *binvecs, *binwords;
Marc Kupietzf0809762016-02-26 10:13:47 +010062 int binwords_fd, binvecs_fd;
Marc Kupietz67c20282016-02-26 09:42:00 +010063 char binvecs_fname[256], binwords_fname[256];
64 strcpy(binwords_fname, file_name);
65 strcat(binwords_fname, ".words");
66 strcpy(binvecs_fname, file_name);
67 strcat(binvecs_fname, ".vecs");
Marc Kupietzdc22b982015-10-09 09:19:34 +020068
69 stringBuffer = malloc(64000);
70 f = fopen(file_name, "rb");
71 if (f == NULL) {
72 printf("Input file %s not found\n", file_name);
73 return -1;
74 }
75 fscanf(f, "%lld", &words);
Marc Kupietz44bee3c2016-02-25 16:26:29 +010076 if(MAX_WORDS > 0 && words > MAX_WORDS) words = MAX_WORDS;
Marc Kupietzdc22b982015-10-09 09:19:34 +020077 fscanf(f, "%lld", &size);
Marc Kupietz7bc85fd2016-02-24 11:42:41 +010078 for (a = 0; a < MAX_NEIGHBOURS; a++) bestw[a] = (char *)malloc(max_size * sizeof(char));
Marc Kupietzf0809762016-02-26 10:13:47 +010079 if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) >= 0 && (binwords_fd = open(binwords_fname, O_RDONLY)) >= 0) {
80 M = mmap(0, sizeof(float) * (long long)words * (long long)size, PROT_READ, MAP_PRIVATE, binvecs_fd, 0);
81 vocab = mmap(0, sizeof(char) * (long long)words * max_w, PROT_READ, MAP_PRIVATE, binwords_fd, 0);
82 if (M == MAP_FAILED || vocab == MAP_FAILED) {
83 close(binvecs_fd);
84 close(binwords_fd);
85 fprintf(stderr, "Cannot mmap %s or %s\n", binwords_fname, binvecs_fname);
86 exit(-1);
87 }
Marc Kupietz67c20282016-02-26 09:42:00 +010088 } else {
Marc Kupietzf0809762016-02-26 10:13:47 +010089 vocab = (char *)malloc((long long)words * max_w * sizeof(char));
90 M = (float *)malloc((long long)words * (long long)size * sizeof(float));
91 if (M == NULL) {
92 printf("Cannot allocate memory: %lld MB %lld %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size);
93 return -1;
94 }
Marc Kupietz67c20282016-02-26 09:42:00 +010095 for (b = 0; b < words; b++) {
96 a = 0;
97 while (1) {
98 vocab[b * max_w + a] = fgetc(f);
99 if (feof(f) || (vocab[b * max_w + a] == ' ')) break;
100 if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++;
101 }
102 vocab[b * max_w + a] = 0;
103 fread(&M[b * size], sizeof(float), size, f);
104 len = 0;
105 for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size];
106 len = sqrt(len);
107 for (a = 0; a < size; a++) M[a + b * size] /= len;
108 }
109 if( (binvecs = fopen(binvecs_fname, "wb")) != NULL && (binwords = fopen(binwords_fname, "wb")) != NULL) {
110 fwrite(M, sizeof(float), (long long)words * (long long)size, binvecs);
111 fclose(binvecs);
112 fwrite(vocab, sizeof(char), (long long)words * max_w, binwords);
113 fclose(binwords);
114 }
115 }
Marc Kupietzdc22b982015-10-09 09:19:34 +0200116 fclose(f);
117 return 0;
118}
119
Marc Kupietz7bc85fd2016-02-24 11:42:41 +0100120SV *get_neighbours(char *st1, int N) {
121 if(N>MAX_NEIGHBOURS) N=MAX_NEIGHBOURS;
122
Marc Kupietzdc22b982015-10-09 09:19:34 +0200123 FILE *out=stdout;
124 *stringBuffer=0;
125
126 for (a = 0; a < N; a++) bestd[a] = 0;
127 for (a = 0; a < N; a++) bestw[a][0] = 0;
128 a = 0;
129 cn = 0;
130 b = 0;
131 c = 0;
132 while (1) {
133 st[cn][b] = st1[c];
134 b++;
135 c++;
136 st[cn][b] = 0;
137 if (st1[c] == 0) break;
138 if (st1[c] == ' ') {
139 cn++;
140 b = 0;
141 c++;
142 }
143 }
144 cn++;
145 for (a = 0; a < cn; a++) {
146 for (b = 0; b < words; b++) if (!strcmp(&vocab[b * max_w], st[a])) break;
147 if (b == words) b = -1;
148 bi[a] = b;
Marc Kupietze8da3062016-02-25 08:37:53 +0100149 fprintf(stderr, "Word: \"%s\" Position in vocabulary: %lld\n", st[a], bi[a]);
Marc Kupietzdc22b982015-10-09 09:19:34 +0200150 if (b == -1) {
Marc Kupietze8da3062016-02-25 08:37:53 +0100151 fprintf(stderr, "Out of dictionary word!\n");
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100152 cn--;
Marc Kupietzdc22b982015-10-09 09:19:34 +0200153 break;
154 }
155 }
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100156 if (b == -1 && cn <= 0) {
157 N = 0;
158 goto end;
159 }
Marc Kupietzdc22b982015-10-09 09:19:34 +0200160 for (a = 0; a < size; a++) vec[a] = 0;
161 for (b = 0; b < cn; b++) {
162 if (bi[b] == -1) continue;
163 for (a = 0; a < size; a++) vec[a] += M[a + bi[b] * size];
164 }
165 len = 0;
166 for (a = 0; a < size; a++) len += vec[a] * vec[a];
167 len = sqrt(len);
168 for (a = 0; a < size; a++) vec[a] /= len;
169 for (a = 0; a < N; a++) bestd[a] = -1;
170 for (a = 0; a < N; a++) bestw[a][0] = 0;
171 for (c = 0; c < words; c++) {
172 a = 0;
Marc Kupietz34020dc2016-02-25 08:44:19 +0100173// do not skip taget word
Marc Kupietze8da3062016-02-25 08:37:53 +0100174// for (b = 0; b < cn; b++) if (bi[b] == c) a = 1;
175// if (a == 1) continue;
Marc Kupietzdc22b982015-10-09 09:19:34 +0200176 dist = 0;
177 for (a = 0; a < size; a++) dist += vec[a] * M[a + c * size];
178 for (a = 0; a < N; a++) {
179 if (dist > bestd[a]) {
180 for (d = N - 1; d > a; d--) {
181 bestd[d] = bestd[d - 1];
Marc Kupietz34020dc2016-02-25 08:44:19 +0100182 besti[d] = besti[d - 1];
Marc Kupietzdc22b982015-10-09 09:19:34 +0200183 }
184 bestd[a] = dist;
Marc Kupietzc4893362016-02-25 08:04:46 +0100185 besti[a] = c;
Marc Kupietzdc22b982015-10-09 09:19:34 +0200186 break;
187 }
188 }
189 }
Marc Kupietz34020dc2016-02-25 08:44:19 +0100190
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100191end:
192 a=0;
Marc Kupietz247500f2015-10-09 11:29:01 +0200193 AV* array = newAV();
194 for (a = 0; a < N; a++) {
Marc Kupietz34020dc2016-02-25 08:44:19 +0100195 strcpy(bestw[a], &vocab[besti[a] * max_w]);
Marc Kupietz247500f2015-10-09 11:29:01 +0200196 HV* hash = newHV();
197 hv_store(hash, "word", strlen("word"), newSVpvf(bestw[a], 0), 0);
198 hv_store(hash, "dist", strlen("dist"), newSVnv(bestd[a]), 0);
Marc Kupietz5f780672016-02-25 17:15:54 +0100199 hv_store(hash, "rank", strlen("rank"), newSVuv(besti[a]), 0);
Marc Kupietzc4893362016-02-25 08:04:46 +0100200 AV *vector = newAV();
201 for (b = 0; b < size; b++) {
202 av_push(vector, newSVnv(M[b + besti[a] * size]));
203 }
204 hv_store(hash, "vector", strlen("vector"), newRV_noinc((SV*)vector), 0);
Marc Kupietz247500f2015-10-09 11:29:01 +0200205 av_push(array, newRV_noinc((SV*)hash));
206 }
Marc Kupietz247500f2015-10-09 11:29:01 +0200207 return newRV_noinc((SV*)array);
Marc Kupietzdc22b982015-10-09 09:19:34 +0200208}
209
Marc Kupietz7bc85fd2016-02-24 11:42:41 +0100210
Marc Kupietzdc22b982015-10-09 09:19:34 +0200211__DATA__
212
213@@ index.html.ep
214<!DOCTYPE html>
215<html>
Marc Kupietzc4893362016-02-25 08:04:46 +0100216<head>
217 <title>DeReKo-Word-Vector-Distances</title>
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100218 <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
Marc Kupietzc4893362016-02-25 08:04:46 +0100219 <script src="http://code.jquery.com/jquery-latest.min.js"></script>
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100220 <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
221 <script>
222 $(function() {
Marc Kupietz5f780672016-02-25 17:15:54 +0100223 $( document ).tooltip({
224 content: function() {
225 return $(this).attr('title');
226 }}
227 )
228 })
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100229 </script>
Marc Kupietzc4893362016-02-25 08:04:46 +0100230 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
231 <script src="http://klinux10/word2vec/tsne.js"></script>
Marc Kupietzc5990da2016-02-26 08:47:12 +0100232 <script src="http://klinux10/word2vec/labeler.js"></script>
Marc Kupietzc4893362016-02-25 08:04:46 +0100233<style>
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100234body, input {
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100235 font-family: Arial, sans-serif;
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100236 font-size: 11pt;
237}
238
239.ui-tooltip-content {
240 font-size: 9pt;
241 colour: #222222;
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100242}
Marc Kupietz5f780672016-02-25 17:15:54 +0100243
244svg > .ui-tooltip-content {
245 font-size: 7pt;
246 colour: #222222;
247}
248
Marc Kupietzc4893362016-02-25 08:04:46 +0100249svg {
250// border: 1px solid #333;
Marc Kupietz4aa62172016-02-25 10:39:27 +0100251 margin-right: 10px;
252 margin-bottom:10px;
Marc Kupietzc4893362016-02-25 08:04:46 +0100253}
254#wrapper {
255 width: 100%;
256// border: 1px solid red;
257 overflow: hidden; /* will contain if #first is longer than #second */
258}
259#first {
Marc Kupietzc4893362016-02-25 08:04:46 +0100260 margin-right: 20px;
261 float:left; /* add this */
262// border: 1px solid green;
263}
264#second {
265 border: 1px solid #333;
Marc Kupietz4aa62172016-02-25 10:39:27 +0100266 height: 850px;
Marc Kupietzc4893362016-02-25 08:04:46 +0100267 overflow: hidden; /* if you don't want #second to wrap below #first */
268}
Marc Kupietz4aa62172016-02-25 10:39:27 +0100269#cost {
270 z-index: 1;
271 position: fixed;
272 font-size: 10px;
273 color: #222222;
274 margin-bottom: 10px;
275}
Marc Kupietzc4893362016-02-25 08:04:46 +0100276</style>
277<script>
278
Marc Kupietz4aa62172016-02-25 10:39:27 +0100279var opt = {epsilon: 1, perplexity: 20};
Marc Kupietzc4893362016-02-25 08:04:46 +0100280var T = new tsnejs.tSNE(opt); // create a tSNE instance
281
282var Y;
283
284var data;
Marc Kupietzc5990da2016-02-26 08:47:12 +0100285var labeler;
Marc Kupietzc4893362016-02-25 08:04:46 +0100286
Marc Kupietzc5990da2016-02-26 08:47:12 +0100287
288function applyJitter() {
289 svg.selectAll('.u')
290 .data(labels)
291 .transition()
292 .duration(50)
293 .attr("transform", function(d, i) {
294 T.Y[i][0] = (d.x - 400 - tx)/ss/20;
295 T.Y[i][1] = (d.y - 400 - ty)/ss/20;
296 return "translate(" +
297 (d.x) + "," +
298 (d.y) + ")";
299 });
300}
301
Marc Kupietzc4893362016-02-25 08:04:46 +0100302function updateEmbedding() {
303 var Y = T.getSolution();
304 svg.selectAll('.u')
305 .data(data.words)
Marc Kupietzc5990da2016-02-26 08:47:12 +0100306 .attr("transform", function(d, i) {
307 return "translate(" +
308 ((Y[i][0]*20*ss + tx) + 400) + "," +
309 ((Y[i][1]*20*ss + ty) + 400) + ")"; });
Marc Kupietzc4893362016-02-25 08:04:46 +0100310}
311
312var svg;
Marc Kupietzc5990da2016-02-26 08:47:12 +0100313var labels = [];
314var anchor_array = [];
315var text;
316
Marc Kupietzc4893362016-02-25 08:04:46 +0100317function drawEmbedding() {
Marc Kupietza350bce2016-02-25 09:34:25 +0100318 $("#embed").empty();
319 var div = d3.select("#embed");
320
321 // get min and max in each column of Y
322 var Y = T.Y;
323
324 svg = div.append("svg") // svg is global
325 .attr("width", 800)
326 .attr("height", 800);
327
328 var g = svg.selectAll(".b")
329 .data(data.words)
330 .enter().append("g")
331 .attr("class", "u");
332
333 g.append("a")
334 .attr("xlink:href", function(word) {return "/?word="+word;})
Marc Kupietz5f780672016-02-25 17:15:54 +0100335 .attr("title", function(d, i) {
336 return "rank: "+i +" "+"freq. rank: "+data.ranks[i];
337 })
Marc Kupietza350bce2016-02-25 09:34:25 +0100338 .append("text")
339 .attr("text-anchor", "top")
340 .attr("font-size", 12)
341 .attr("fill", function(d) {
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100342 if(data.target.indexOf(" "+d+" ") >= 0) {
Marc Kupietza350bce2016-02-25 09:34:25 +0100343 return "red";
344 } else {
345 return "#333"
Marc Kupietzc4893362016-02-25 08:04:46 +0100346 }
Marc Kupietza350bce2016-02-25 09:34:25 +0100347 })
348 .text(function(d) { return d; });
349
350 var zoomListener = d3.behavior.zoom()
351 .scaleExtent([0.1, 10])
352 .center([0,0])
353 .on("zoom", zoomHandler);
354 zoomListener(svg);
355 }
356
357 var tx=0, ty=0;
358 var ss=1;
359 var iter_id=-1;
360
361 function zoomHandler() {
362 tx = d3.event.translate[0];
363 ty = d3.event.translate[1];
364 ss = d3.event.scale;
365 updateEmbedding();
366 }
367
368 var stepnum = 0;
Marc Kupietzc5990da2016-02-26 08:47:12 +0100369
Marc Kupietza350bce2016-02-25 09:34:25 +0100370 function stopStep() {
371 clearInterval(iter_id);
Marc Kupietzc5990da2016-02-26 08:47:12 +0100372 text = svg.selectAll("text");
373
374 labels = d3.range(data.words.length).map(function(i) {
375 var x = (T.Y[i][0]*20*ss + tx) + 400;
376 var y = (T.Y[i][1]*20*ss + ty) + 400;
377 anchor_array.push({x: x, y: y, r: 5});
378 return {
379 x: x,
380 y: y,
381 name: data.words[i]
382 };
383 });
384
385 var index = 0;
386 text.each(function() {
387 labels[index].width = this.getBBox().width;
388 labels[index].height = this.getBBox().height;
389 index += 1;
390 });
391
392
393// setTimeout(updateEmbedding, 1);
394// setTimeout(
395 labeler = d3.labeler()
396 .label(labels)
397 .anchor(anchor_array)
398 .width(800)
399 .height(800)
400 .update(applyJitter);
401// .start(1000);
402
403 iter_id = setInterval(jitterStep, 1);
404
Marc Kupietza350bce2016-02-25 09:34:25 +0100405 }
Marc Kupietzc5990da2016-02-26 08:47:12 +0100406
407var jitter_i=0;;
408
409function jitterStep() {
410 if(jitter_i++ > 100) {
411 clearInterval(iter_id);
412 } else {
413 labeler.start2(10);
414 applyJitter();
415 }
416}
Marc Kupietza350bce2016-02-25 09:34:25 +0100417
418 function step() {
419 var i = T.iter;
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100420 if(i > <%= $no_iterations %>) {
Marc Kupietza350bce2016-02-25 09:34:25 +0100421 stopStep();
422 } else {
Marc Kupietz4aa62172016-02-25 10:39:27 +0100423 var cost = Math.round(T.step() *1000) / 1000; // do a few steps
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100424 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(3));
Marc Kupietza350bce2016-02-25 09:34:25 +0100425 updateEmbedding();
426 }
427 }
Marc Kupietzc5990da2016-02-26 08:47:12 +0100428
Marc Kupietza350bce2016-02-25 09:34:25 +0100429 function showMap(j) {
430 data=j;
431 T.iter=0;
432 T.initDataRaw(data.vecs); // init embedding
433 drawEmbedding(); // draw initial embedding
434
435 if(iter_id >= 0) {
436 clearInterval(iter_id);
437 }
438 //T.debugGrad();
439 iter_id = setInterval(step, 1);
440 //step();
441 }
442
Marc Kupietzc5990da2016-02-26 08:47:12 +0100443 function update() {
444
445 text.transition().duration(800)
446 .attr("transform", transform);
447 }
448
449
Marc Kupietzc4893362016-02-25 08:04:46 +0100450</script>
451</head>
Marc Kupietzdc22b982015-10-09 09:19:34 +0200452<body>
Marc Kupietz4aa62172016-02-25 10:39:27 +0100453 <form action="<%=url_for('/')->to_abs%>" method="GET">
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100454 word(s):
455 <input type="text" name="word" size="20" value="<%= $word %>" 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.">
456 max. neighbours: <input type="text" size="8" name="n" value="<%= $no_nbs %>">
457 iterations: <input type="text" name="N" size="8" value="<%= $no_iterations %>">
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100458 <input type="submit" value="Show">
Marc Kupietz4aa62172016-02-25 10:39:27 +0100459 </form>
460 <br>
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100461 % if($lists) {
Marc Kupietz4aa62172016-02-25 10:39:27 +0100462 <div id="wrapper">
463 <table id="first">
464 <tr>
Marc Kupietz5f780672016-02-25 17:15:54 +0100465 <th align="right">Pos.</th><th align="left">Word</th><th align="right">Cosine dist.</th><th>Freq. rank</th>
Marc Kupietz4aa62172016-02-25 10:39:27 +0100466 </tr>
Marc Kupietz5f780672016-02-25 17:15:54 +0100467 % my $j=0; my @words; my @vecs; my @ranks; for my $list (@$lists) {
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100468 % my $i=1; for my $item (@$list) {
469 % if(!grep{$_ eq $item->{word}} @words) {
470 % push @vecs, $item->{vector};
471 % push @words, $item->{word};
Marc Kupietz5f780672016-02-25 17:15:54 +0100472 % push @ranks, $item->{rank};
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100473 % }
Marc Kupietz4aa62172016-02-25 10:39:27 +0100474 <tr>
475 <td align="right">
476 <%= $i++ %>.
477 </td>
478 <td>
479 <a href="/?word=<%= $item->{word} %>">
480 <%= $item->{word} %>
481 </a>
482 </td>
483 <td align="right">
484 <%= sprintf("%.3f", $item->{dist}) %>
485 </td>
Marc Kupietz5f780672016-02-25 17:15:54 +0100486 <td align="right">
487 <%= $item->{rank} %>
488 </td>
Marc Kupietz4aa62172016-02-25 10:39:27 +0100489 </tr>
490 % }
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100491 % }
Marc Kupietz4aa62172016-02-25 10:39:27 +0100492 </table>
493 <script>
494 % use Mojo::ByteStream 'b';
495 $(window).load(function() {
Marc Kupietz5f780672016-02-25 17:15:54 +0100496 showMap(<%= b(Mojo::JSON::to_json({target => " $word ", words => \@words, vecs => \@vecs, ranks => \@ranks})); %>);
Marc Kupietz4aa62172016-02-25 10:39:27 +0100497 });
498 </script>
499 % }
500 <div id="second" style="width:800px; height:800px; font-family: arial;">
501 <div id="embed">
502 </div>
503 <div id="cost"></div>
504 </div>
505 </div>
506 <p>
507 Word vector model based on DeReKo-2015-II. Trained with <a href="https://code.google.com/p/word2vec/">word2vec</a> using the following parameters:</p>
Marc Kupietz247500f2015-10-09 11:29:01 +0200508 <pre>
Marc Kupietz7bc85fd2016-02-24 11:42:41 +0100509-cbow 1 -size 300 -window 7 -negative 5 -hs 0 -sample 1e-5 -threads 44 -binary 1 -iter 5
Marc Kupietz4aa62172016-02-25 10:39:27 +0100510 </pre>
511 </p>
512</body>
Marc Kupietzdc22b982015-10-09 09:19:34 +0200513</html>
514