blob: f4f83f617504a4bbf5dcfecac235d5764801e35c [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
41
42#define max_size 2000
43#define max_w 50
Marc Kupietz7bc85fd2016-02-24 11:42:41 +010044#define MAX_NEIGHBOURS 1000
Marc Kupietz44bee3c2016-02-25 16:26:29 +010045#define MAX_WORDS -1
Marc Kupietzdc22b982015-10-09 09:19:34 +020046
47//the thread function
48void *connection_handler(void *);
49
Marc Kupietz7bc85fd2016-02-24 11:42:41 +010050char *bestw[MAX_NEIGHBOURS];
Marc Kupietzdc22b982015-10-09 09:19:34 +020051char file_name[max_size], st[100][max_size];
Marc Kupietz7bc85fd2016-02-24 11:42:41 +010052float dist, len, bestd[MAX_NEIGHBOURS], vec[max_size];
Marc Kupietzc4893362016-02-25 08:04:46 +010053long long words, size, a, b, c, d, cn, bi[100], besti[MAX_NEIGHBOURS];
Marc Kupietzdc22b982015-10-09 09:19:34 +020054char ch;
55float *M;
56char *vocab;
57char *stringBuffer;
58
59int init_net(char *file_name) {
Marc Kupietz67c20282016-02-26 09:42:00 +010060 FILE *f, *binvecs, *binwords;
61 char binvecs_fname[256], binwords_fname[256];
62 strcpy(binwords_fname, file_name);
63 strcat(binwords_fname, ".words");
64 strcpy(binvecs_fname, file_name);
65 strcat(binvecs_fname, ".vecs");
Marc Kupietzdc22b982015-10-09 09:19:34 +020066
67 stringBuffer = malloc(64000);
68 f = fopen(file_name, "rb");
69 if (f == NULL) {
70 printf("Input file %s not found\n", file_name);
71 return -1;
72 }
73 fscanf(f, "%lld", &words);
Marc Kupietz44bee3c2016-02-25 16:26:29 +010074 if(MAX_WORDS > 0 && words > MAX_WORDS) words = MAX_WORDS;
Marc Kupietzdc22b982015-10-09 09:19:34 +020075 fscanf(f, "%lld", &size);
76 vocab = (char *)malloc((long long)words * max_w * sizeof(char));
Marc Kupietz7bc85fd2016-02-24 11:42:41 +010077 for (a = 0; a < MAX_NEIGHBOURS; a++) bestw[a] = (char *)malloc(max_size * sizeof(char));
Marc Kupietzdc22b982015-10-09 09:19:34 +020078 M = (float *)malloc((long long)words * (long long)size * sizeof(float));
79 if (M == NULL) {
80 printf("Cannot allocate memory: %lld MB %lld %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size);
81 return -1;
82 }
Marc Kupietz67c20282016-02-26 09:42:00 +010083 if( (binvecs = fopen(binvecs_fname, "rb")) != NULL && (binwords = fopen(binwords_fname, "rb")) != NULL) {
84 fread(M, sizeof(float), (long long)words * (long long)size, binvecs);
85 fclose(binvecs);
86 fread(vocab, sizeof(char), (long long)words * max_w, binwords);
87 fclose(binwords);
88 } else {
89 for (b = 0; b < words; b++) {
90 a = 0;
91 while (1) {
92 vocab[b * max_w + a] = fgetc(f);
93 if (feof(f) || (vocab[b * max_w + a] == ' ')) break;
94 if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++;
95 }
96 vocab[b * max_w + a] = 0;
97 fread(&M[b * size], sizeof(float), size, f);
98 len = 0;
99 for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size];
100 len = sqrt(len);
101 for (a = 0; a < size; a++) M[a + b * size] /= len;
102 }
103 if( (binvecs = fopen(binvecs_fname, "wb")) != NULL && (binwords = fopen(binwords_fname, "wb")) != NULL) {
104 fwrite(M, sizeof(float), (long long)words * (long long)size, binvecs);
105 fclose(binvecs);
106 fwrite(vocab, sizeof(char), (long long)words * max_w, binwords);
107 fclose(binwords);
108 }
109 }
Marc Kupietzdc22b982015-10-09 09:19:34 +0200110 fclose(f);
111 return 0;
112}
113
Marc Kupietz7bc85fd2016-02-24 11:42:41 +0100114SV *get_neighbours(char *st1, int N) {
115 if(N>MAX_NEIGHBOURS) N=MAX_NEIGHBOURS;
116
Marc Kupietzdc22b982015-10-09 09:19:34 +0200117 FILE *out=stdout;
118 *stringBuffer=0;
119
120 for (a = 0; a < N; a++) bestd[a] = 0;
121 for (a = 0; a < N; a++) bestw[a][0] = 0;
122 a = 0;
123 cn = 0;
124 b = 0;
125 c = 0;
126 while (1) {
127 st[cn][b] = st1[c];
128 b++;
129 c++;
130 st[cn][b] = 0;
131 if (st1[c] == 0) break;
132 if (st1[c] == ' ') {
133 cn++;
134 b = 0;
135 c++;
136 }
137 }
138 cn++;
139 for (a = 0; a < cn; a++) {
140 for (b = 0; b < words; b++) if (!strcmp(&vocab[b * max_w], st[a])) break;
141 if (b == words) b = -1;
142 bi[a] = b;
Marc Kupietze8da3062016-02-25 08:37:53 +0100143 fprintf(stderr, "Word: \"%s\" Position in vocabulary: %lld\n", st[a], bi[a]);
Marc Kupietzdc22b982015-10-09 09:19:34 +0200144 if (b == -1) {
Marc Kupietze8da3062016-02-25 08:37:53 +0100145 fprintf(stderr, "Out of dictionary word!\n");
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100146 cn--;
Marc Kupietzdc22b982015-10-09 09:19:34 +0200147 break;
148 }
149 }
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100150 if (b == -1 && cn <= 0) {
151 N = 0;
152 goto end;
153 }
Marc Kupietzdc22b982015-10-09 09:19:34 +0200154 for (a = 0; a < size; a++) vec[a] = 0;
155 for (b = 0; b < cn; b++) {
156 if (bi[b] == -1) continue;
157 for (a = 0; a < size; a++) vec[a] += M[a + bi[b] * size];
158 }
159 len = 0;
160 for (a = 0; a < size; a++) len += vec[a] * vec[a];
161 len = sqrt(len);
162 for (a = 0; a < size; a++) vec[a] /= len;
163 for (a = 0; a < N; a++) bestd[a] = -1;
164 for (a = 0; a < N; a++) bestw[a][0] = 0;
165 for (c = 0; c < words; c++) {
166 a = 0;
Marc Kupietz34020dc2016-02-25 08:44:19 +0100167// do not skip taget word
Marc Kupietze8da3062016-02-25 08:37:53 +0100168// for (b = 0; b < cn; b++) if (bi[b] == c) a = 1;
169// if (a == 1) continue;
Marc Kupietzdc22b982015-10-09 09:19:34 +0200170 dist = 0;
171 for (a = 0; a < size; a++) dist += vec[a] * M[a + c * size];
172 for (a = 0; a < N; a++) {
173 if (dist > bestd[a]) {
174 for (d = N - 1; d > a; d--) {
175 bestd[d] = bestd[d - 1];
Marc Kupietz34020dc2016-02-25 08:44:19 +0100176 besti[d] = besti[d - 1];
Marc Kupietzdc22b982015-10-09 09:19:34 +0200177 }
178 bestd[a] = dist;
Marc Kupietzc4893362016-02-25 08:04:46 +0100179 besti[a] = c;
Marc Kupietzdc22b982015-10-09 09:19:34 +0200180 break;
181 }
182 }
183 }
Marc Kupietz34020dc2016-02-25 08:44:19 +0100184
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100185end:
186 a=0;
Marc Kupietz247500f2015-10-09 11:29:01 +0200187 AV* array = newAV();
188 for (a = 0; a < N; a++) {
Marc Kupietz34020dc2016-02-25 08:44:19 +0100189 strcpy(bestw[a], &vocab[besti[a] * max_w]);
Marc Kupietz247500f2015-10-09 11:29:01 +0200190 HV* hash = newHV();
191 hv_store(hash, "word", strlen("word"), newSVpvf(bestw[a], 0), 0);
192 hv_store(hash, "dist", strlen("dist"), newSVnv(bestd[a]), 0);
Marc Kupietz5f780672016-02-25 17:15:54 +0100193 hv_store(hash, "rank", strlen("rank"), newSVuv(besti[a]), 0);
Marc Kupietzc4893362016-02-25 08:04:46 +0100194 AV *vector = newAV();
195 for (b = 0; b < size; b++) {
196 av_push(vector, newSVnv(M[b + besti[a] * size]));
197 }
198 hv_store(hash, "vector", strlen("vector"), newRV_noinc((SV*)vector), 0);
Marc Kupietz247500f2015-10-09 11:29:01 +0200199 av_push(array, newRV_noinc((SV*)hash));
200 }
Marc Kupietz247500f2015-10-09 11:29:01 +0200201 return newRV_noinc((SV*)array);
Marc Kupietzdc22b982015-10-09 09:19:34 +0200202}
203
Marc Kupietz7bc85fd2016-02-24 11:42:41 +0100204
Marc Kupietzdc22b982015-10-09 09:19:34 +0200205__DATA__
206
207@@ index.html.ep
208<!DOCTYPE html>
209<html>
Marc Kupietzc4893362016-02-25 08:04:46 +0100210<head>
211 <title>DeReKo-Word-Vector-Distances</title>
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100212 <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
Marc Kupietzc4893362016-02-25 08:04:46 +0100213 <script src="http://code.jquery.com/jquery-latest.min.js"></script>
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100214 <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
215 <script>
216 $(function() {
Marc Kupietz5f780672016-02-25 17:15:54 +0100217 $( document ).tooltip({
218 content: function() {
219 return $(this).attr('title');
220 }}
221 )
222 })
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100223 </script>
Marc Kupietzc4893362016-02-25 08:04:46 +0100224 <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
225 <script src="http://klinux10/word2vec/tsne.js"></script>
Marc Kupietzc5990da2016-02-26 08:47:12 +0100226 <script src="http://klinux10/word2vec/labeler.js"></script>
Marc Kupietzc4893362016-02-25 08:04:46 +0100227<style>
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100228body, input {
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100229 font-family: Arial, sans-serif;
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100230 font-size: 11pt;
231}
232
233.ui-tooltip-content {
234 font-size: 9pt;
235 colour: #222222;
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100236}
Marc Kupietz5f780672016-02-25 17:15:54 +0100237
238svg > .ui-tooltip-content {
239 font-size: 7pt;
240 colour: #222222;
241}
242
Marc Kupietzc4893362016-02-25 08:04:46 +0100243svg {
244// border: 1px solid #333;
Marc Kupietz4aa62172016-02-25 10:39:27 +0100245 margin-right: 10px;
246 margin-bottom:10px;
Marc Kupietzc4893362016-02-25 08:04:46 +0100247}
248#wrapper {
249 width: 100%;
250// border: 1px solid red;
251 overflow: hidden; /* will contain if #first is longer than #second */
252}
253#first {
Marc Kupietzc4893362016-02-25 08:04:46 +0100254 margin-right: 20px;
255 float:left; /* add this */
256// border: 1px solid green;
257}
258#second {
259 border: 1px solid #333;
Marc Kupietz4aa62172016-02-25 10:39:27 +0100260 height: 850px;
Marc Kupietzc4893362016-02-25 08:04:46 +0100261 overflow: hidden; /* if you don't want #second to wrap below #first */
262}
Marc Kupietz4aa62172016-02-25 10:39:27 +0100263#cost {
264 z-index: 1;
265 position: fixed;
266 font-size: 10px;
267 color: #222222;
268 margin-bottom: 10px;
269}
Marc Kupietzc4893362016-02-25 08:04:46 +0100270</style>
271<script>
272
Marc Kupietz4aa62172016-02-25 10:39:27 +0100273var opt = {epsilon: 1, perplexity: 20};
Marc Kupietzc4893362016-02-25 08:04:46 +0100274var T = new tsnejs.tSNE(opt); // create a tSNE instance
275
276var Y;
277
278var data;
Marc Kupietzc5990da2016-02-26 08:47:12 +0100279var labeler;
Marc Kupietzc4893362016-02-25 08:04:46 +0100280
Marc Kupietzc5990da2016-02-26 08:47:12 +0100281
282function applyJitter() {
283 svg.selectAll('.u')
284 .data(labels)
285 .transition()
286 .duration(50)
287 .attr("transform", function(d, i) {
288 T.Y[i][0] = (d.x - 400 - tx)/ss/20;
289 T.Y[i][1] = (d.y - 400 - ty)/ss/20;
290 return "translate(" +
291 (d.x) + "," +
292 (d.y) + ")";
293 });
294}
295
Marc Kupietzc4893362016-02-25 08:04:46 +0100296function updateEmbedding() {
297 var Y = T.getSolution();
298 svg.selectAll('.u')
299 .data(data.words)
Marc Kupietzc5990da2016-02-26 08:47:12 +0100300 .attr("transform", function(d, i) {
301 return "translate(" +
302 ((Y[i][0]*20*ss + tx) + 400) + "," +
303 ((Y[i][1]*20*ss + ty) + 400) + ")"; });
Marc Kupietzc4893362016-02-25 08:04:46 +0100304}
305
306var svg;
Marc Kupietzc5990da2016-02-26 08:47:12 +0100307var labels = [];
308var anchor_array = [];
309var text;
310
Marc Kupietzc4893362016-02-25 08:04:46 +0100311function drawEmbedding() {
Marc Kupietza350bce2016-02-25 09:34:25 +0100312 $("#embed").empty();
313 var div = d3.select("#embed");
314
315 // get min and max in each column of Y
316 var Y = T.Y;
317
318 svg = div.append("svg") // svg is global
319 .attr("width", 800)
320 .attr("height", 800);
321
322 var g = svg.selectAll(".b")
323 .data(data.words)
324 .enter().append("g")
325 .attr("class", "u");
326
327 g.append("a")
328 .attr("xlink:href", function(word) {return "/?word="+word;})
Marc Kupietz5f780672016-02-25 17:15:54 +0100329 .attr("title", function(d, i) {
330 return "rank: "+i +" "+"freq. rank: "+data.ranks[i];
331 })
Marc Kupietza350bce2016-02-25 09:34:25 +0100332 .append("text")
333 .attr("text-anchor", "top")
334 .attr("font-size", 12)
335 .attr("fill", function(d) {
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100336 if(data.target.indexOf(" "+d+" ") >= 0) {
Marc Kupietza350bce2016-02-25 09:34:25 +0100337 return "red";
338 } else {
339 return "#333"
Marc Kupietzc4893362016-02-25 08:04:46 +0100340 }
Marc Kupietza350bce2016-02-25 09:34:25 +0100341 })
342 .text(function(d) { return d; });
343
344 var zoomListener = d3.behavior.zoom()
345 .scaleExtent([0.1, 10])
346 .center([0,0])
347 .on("zoom", zoomHandler);
348 zoomListener(svg);
349 }
350
351 var tx=0, ty=0;
352 var ss=1;
353 var iter_id=-1;
354
355 function zoomHandler() {
356 tx = d3.event.translate[0];
357 ty = d3.event.translate[1];
358 ss = d3.event.scale;
359 updateEmbedding();
360 }
361
362 var stepnum = 0;
Marc Kupietzc5990da2016-02-26 08:47:12 +0100363
Marc Kupietza350bce2016-02-25 09:34:25 +0100364 function stopStep() {
365 clearInterval(iter_id);
Marc Kupietzc5990da2016-02-26 08:47:12 +0100366 text = svg.selectAll("text");
367
368 labels = d3.range(data.words.length).map(function(i) {
369 var x = (T.Y[i][0]*20*ss + tx) + 400;
370 var y = (T.Y[i][1]*20*ss + ty) + 400;
371 anchor_array.push({x: x, y: y, r: 5});
372 return {
373 x: x,
374 y: y,
375 name: data.words[i]
376 };
377 });
378
379 var index = 0;
380 text.each(function() {
381 labels[index].width = this.getBBox().width;
382 labels[index].height = this.getBBox().height;
383 index += 1;
384 });
385
386
387// setTimeout(updateEmbedding, 1);
388// setTimeout(
389 labeler = d3.labeler()
390 .label(labels)
391 .anchor(anchor_array)
392 .width(800)
393 .height(800)
394 .update(applyJitter);
395// .start(1000);
396
397 iter_id = setInterval(jitterStep, 1);
398
Marc Kupietza350bce2016-02-25 09:34:25 +0100399 }
Marc Kupietzc5990da2016-02-26 08:47:12 +0100400
401var jitter_i=0;;
402
403function jitterStep() {
404 if(jitter_i++ > 100) {
405 clearInterval(iter_id);
406 } else {
407 labeler.start2(10);
408 applyJitter();
409 }
410}
Marc Kupietza350bce2016-02-25 09:34:25 +0100411
412 function step() {
413 var i = T.iter;
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100414 if(i > <%= $no_iterations %>) {
Marc Kupietza350bce2016-02-25 09:34:25 +0100415 stopStep();
416 } else {
Marc Kupietz4aa62172016-02-25 10:39:27 +0100417 var cost = Math.round(T.step() *1000) / 1000; // do a few steps
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100418 $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(3));
Marc Kupietza350bce2016-02-25 09:34:25 +0100419 updateEmbedding();
420 }
421 }
Marc Kupietzc5990da2016-02-26 08:47:12 +0100422
Marc Kupietza350bce2016-02-25 09:34:25 +0100423 function showMap(j) {
424 data=j;
425 T.iter=0;
426 T.initDataRaw(data.vecs); // init embedding
427 drawEmbedding(); // draw initial embedding
428
429 if(iter_id >= 0) {
430 clearInterval(iter_id);
431 }
432 //T.debugGrad();
433 iter_id = setInterval(step, 1);
434 //step();
435 }
436
Marc Kupietzc5990da2016-02-26 08:47:12 +0100437 function update() {
438
439 text.transition().duration(800)
440 .attr("transform", transform);
441 }
442
443
Marc Kupietzc4893362016-02-25 08:04:46 +0100444</script>
445</head>
Marc Kupietzdc22b982015-10-09 09:19:34 +0200446<body>
Marc Kupietz4aa62172016-02-25 10:39:27 +0100447 <form action="<%=url_for('/')->to_abs%>" method="GET">
Marc Kupietz44bee3c2016-02-25 16:26:29 +0100448 word(s):
449 <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.">
450 max. neighbours: <input type="text" size="8" name="n" value="<%= $no_nbs %>">
451 iterations: <input type="text" name="N" size="8" value="<%= $no_iterations %>">
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100452 <input type="submit" value="Show">
Marc Kupietz4aa62172016-02-25 10:39:27 +0100453 </form>
454 <br>
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100455 % if($lists) {
Marc Kupietz4aa62172016-02-25 10:39:27 +0100456 <div id="wrapper">
457 <table id="first">
458 <tr>
Marc Kupietz5f780672016-02-25 17:15:54 +0100459 <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 +0100460 </tr>
Marc Kupietz5f780672016-02-25 17:15:54 +0100461 % my $j=0; my @words; my @vecs; my @ranks; for my $list (@$lists) {
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100462 % my $i=1; for my $item (@$list) {
463 % if(!grep{$_ eq $item->{word}} @words) {
464 % push @vecs, $item->{vector};
465 % push @words, $item->{word};
Marc Kupietz5f780672016-02-25 17:15:54 +0100466 % push @ranks, $item->{rank};
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100467 % }
Marc Kupietz4aa62172016-02-25 10:39:27 +0100468 <tr>
469 <td align="right">
470 <%= $i++ %>.
471 </td>
472 <td>
473 <a href="/?word=<%= $item->{word} %>">
474 <%= $item->{word} %>
475 </a>
476 </td>
477 <td align="right">
478 <%= sprintf("%.3f", $item->{dist}) %>
479 </td>
Marc Kupietz5f780672016-02-25 17:15:54 +0100480 <td align="right">
481 <%= $item->{rank} %>
482 </td>
Marc Kupietz4aa62172016-02-25 10:39:27 +0100483 </tr>
484 % }
Marc Kupietz7b2cbeb2016-02-25 11:22:00 +0100485 % }
Marc Kupietz4aa62172016-02-25 10:39:27 +0100486 </table>
487 <script>
488 % use Mojo::ByteStream 'b';
489 $(window).load(function() {
Marc Kupietz5f780672016-02-25 17:15:54 +0100490 showMap(<%= b(Mojo::JSON::to_json({target => " $word ", words => \@words, vecs => \@vecs, ranks => \@ranks})); %>);
Marc Kupietz4aa62172016-02-25 10:39:27 +0100491 });
492 </script>
493 % }
494 <div id="second" style="width:800px; height:800px; font-family: arial;">
495 <div id="embed">
496 </div>
497 <div id="cost"></div>
498 </div>
499 </div>
500 <p>
501 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 +0200502 <pre>
Marc Kupietz7bc85fd2016-02-24 11:42:41 +0100503-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 +0100504 </pre>
505 </p>
506</body>
Marc Kupietzdc22b982015-10-09 09:19:34 +0200507</html>
508