Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 1 | #!/usr/local/bin/perl |
| 2 | use Inline C; |
| 3 | use Mojolicious::Lite; |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 4 | use Mojo::JSON qw(decode_json encode_json to_json); |
Marc Kupietz | 247500f | 2015-10-09 11:29:01 +0200 | [diff] [blame] | 5 | use Encode qw(decode encode); |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame^] | 6 | use Getopt::Std; |
Marc Kupietz | 7bc85fd | 2016-02-24 11:42:41 +0100 | [diff] [blame] | 7 | use Mojo::Server::Daemon; |
Marc Kupietz | d422739 | 2016-03-01 16:45:12 +0100 | [diff] [blame] | 8 | plugin 'Log::Access'; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 9 | |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame^] | 10 | our $opt_i = 0; # latin1-input? |
| 11 | our $opt_l = undef; |
| 12 | our $opt_p = 5676; |
| 13 | |
| 14 | getopt('il:p:'); |
| 15 | |
Marc Kupietz | 2cb667e | 2016-03-10 09:44:12 +0100 | [diff] [blame] | 16 | print STDERR $ARGV[1]; |
Marc Kupietz | 7bc85fd | 2016-02-24 11:42:41 +0100 | [diff] [blame] | 17 | # -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -threads 40 -binary 1 -iter 15 |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame^] | 18 | if(!$ARGV[0]) { |
| 19 | init_net("vectors15.bin", ($opt_i? 1 : 0)); |
Marc Kupietz | 2cb667e | 2016-03-10 09:44:12 +0100 | [diff] [blame] | 20 | } else { |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame^] | 21 | init_net($ARGV[0], ($opt_i? 1 : 0)); |
Marc Kupietz | 2cb667e | 2016-03-10 09:44:12 +0100 | [diff] [blame] | 22 | } |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 23 | |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame^] | 24 | my $daemon = Mojo::Server::Daemon->new( |
| 25 | app => app, |
| 26 | listen => ['http://'.($opt_l ? $opt_l : '*').":$opt_p"] |
| 27 | ); |
| 28 | |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 29 | get '/' => sub { |
| 30 | my $c = shift; |
| 31 | my $word=$c->param('word'); |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 32 | my $no_nbs=$c->param('n') || 100; |
| 33 | my $no_iterations=$c->param('N') || 2000; |
Marc Kupietz | d422739 | 2016-03-01 16:45:12 +0100 | [diff] [blame] | 34 | my $perplexity=$c->param('perplexity') || 20; |
Marc Kupietz | c4d62f8 | 2016-03-01 11:04:24 +0100 | [diff] [blame] | 35 | my $epsilon=$c->param('epsilon') || 5; |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 36 | my $som=$c->param('som') || 0; |
Marc Kupietz | d422739 | 2016-03-01 16:45:12 +0100 | [diff] [blame] | 37 | |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 38 | my @lists; |
Marc Kupietz | 7bc85fd | 2016-02-24 11:42:41 +0100 | [diff] [blame] | 39 | if(defined($word) && $word !~ /^\s*$/) { |
| 40 | $c->inactivity_timeout(300); |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 41 | $word =~ s/\s+/ /g; |
| 42 | for my $w (split(' *\| *', $word)) { |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 43 | $c->app->log->debug('Looking for neighbours of '.$w); |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame^] | 44 | if($opt_i) { |
| 45 | push(@lists, get_neighbours(encode("iso-8859-1", $w), $no_nbs)); |
| 46 | } else { |
| 47 | push(@lists, get_neighbours($w, $no_nbs)); |
| 48 | } |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 49 | } |
Marc Kupietz | 247500f | 2015-10-09 11:29:01 +0200 | [diff] [blame] | 50 | } |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 51 | $word =~ s/ *\| */ | /g; |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 52 | $c->render(template=>"index", word=>$word, no_nbs=>$no_nbs, no_iterations => $no_iterations, epsilon=> $epsilon, perplexity=> $perplexity, show_som=>$som, lists=> \@lists); |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame^] | 55 | $daemon->run; # app->start; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 56 | |
| 57 | exit; |
| 58 | |
| 59 | __END__ |
| 60 | |
| 61 | __C__ |
| 62 | #include <stdio.h> |
| 63 | #include <string.h> |
| 64 | #include <math.h> |
| 65 | #include <malloc.h> |
| 66 | #include <stdlib.h> //strlen |
Marc Kupietz | f080976 | 2016-02-26 10:13:47 +0100 | [diff] [blame] | 67 | #include <sys/mman.h> |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 68 | #include <pthread.h> |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 69 | |
| 70 | #define max_size 2000 |
| 71 | #define max_w 50 |
Marc Kupietz | 7bc85fd | 2016-02-24 11:42:41 +0100 | [diff] [blame] | 72 | #define MAX_NEIGHBOURS 1000 |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 73 | #define MAX_WORDS -1 |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 74 | #define MAX_THREADS 100 |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 75 | |
| 76 | //the thread function |
| 77 | void *connection_handler(void *); |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 78 | |
| 79 | typedef struct { |
| 80 | long long *index; |
| 81 | float *dist; |
| 82 | unsigned int length; |
| 83 | } knn; |
| 84 | |
| 85 | |
| 86 | typedef struct { |
| 87 | char *token; |
| 88 | int N; |
| 89 | unsigned long from; |
| 90 | unsigned long upto; |
| 91 | } knnpars; |
| 92 | |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 93 | float *M; |
| 94 | char *vocab; |
Marc Kupietz | 82b0267 | 2016-02-26 12:32:25 +0100 | [diff] [blame] | 95 | long long words, size; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 96 | int num_threads=20; |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame^] | 97 | int latin_enc=0; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 98 | |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame^] | 99 | int init_net(char *file_name, int latin) { |
Marc Kupietz | 67c2028 | 2016-02-26 09:42:00 +0100 | [diff] [blame] | 100 | FILE *f, *binvecs, *binwords; |
Marc Kupietz | f080976 | 2016-02-26 10:13:47 +0100 | [diff] [blame] | 101 | int binwords_fd, binvecs_fd; |
Marc Kupietz | 82b0267 | 2016-02-26 12:32:25 +0100 | [diff] [blame] | 102 | long long a, b, c, d, cn; |
| 103 | float len; |
| 104 | |
Marc Kupietz | 67c2028 | 2016-02-26 09:42:00 +0100 | [diff] [blame] | 105 | char binvecs_fname[256], binwords_fname[256]; |
| 106 | strcpy(binwords_fname, file_name); |
| 107 | strcat(binwords_fname, ".words"); |
| 108 | strcpy(binvecs_fname, file_name); |
| 109 | strcat(binvecs_fname, ".vecs"); |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 110 | |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame^] | 111 | latin_enc = latin; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 112 | f = fopen(file_name, "rb"); |
| 113 | if (f == NULL) { |
| 114 | printf("Input file %s not found\n", file_name); |
| 115 | return -1; |
| 116 | } |
| 117 | fscanf(f, "%lld", &words); |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 118 | if(MAX_WORDS > 0 && words > MAX_WORDS) words = MAX_WORDS; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 119 | fscanf(f, "%lld", &size); |
Marc Kupietz | 2cb667e | 2016-03-10 09:44:12 +0100 | [diff] [blame] | 120 | if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) < 0 || (binwords_fd = open(binwords_fname, O_RDONLY)) < 0) { |
| 121 | printf("Converting %s to memory mappable structures\n", file_name); |
Marc Kupietz | f080976 | 2016-02-26 10:13:47 +0100 | [diff] [blame] | 122 | vocab = (char *)malloc((long long)words * max_w * sizeof(char)); |
| 123 | M = (float *)malloc((long long)words * (long long)size * sizeof(float)); |
| 124 | if (M == NULL) { |
| 125 | printf("Cannot allocate memory: %lld MB %lld %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size); |
| 126 | return -1; |
| 127 | } |
Marc Kupietz | 67c2028 | 2016-02-26 09:42:00 +0100 | [diff] [blame] | 128 | for (b = 0; b < words; b++) { |
| 129 | a = 0; |
| 130 | while (1) { |
| 131 | vocab[b * max_w + a] = fgetc(f); |
| 132 | if (feof(f) || (vocab[b * max_w + a] == ' ')) break; |
| 133 | if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++; |
| 134 | } |
| 135 | vocab[b * max_w + a] = 0; |
| 136 | fread(&M[b * size], sizeof(float), size, f); |
| 137 | len = 0; |
| 138 | for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size]; |
| 139 | len = sqrt(len); |
| 140 | for (a = 0; a < size; a++) M[a + b * size] /= len; |
| 141 | } |
| 142 | if( (binvecs = fopen(binvecs_fname, "wb")) != NULL && (binwords = fopen(binwords_fname, "wb")) != NULL) { |
| 143 | fwrite(M, sizeof(float), (long long)words * (long long)size, binvecs); |
| 144 | fclose(binvecs); |
| 145 | fwrite(vocab, sizeof(char), (long long)words * max_w, binwords); |
| 146 | fclose(binwords); |
| 147 | } |
Marc Kupietz | 2cb667e | 2016-03-10 09:44:12 +0100 | [diff] [blame] | 148 | } |
| 149 | if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) >= 0 && (binwords_fd = open(binwords_fname, O_RDONLY)) >= 0) { |
| 150 | M = mmap(0, sizeof(float) * (long long)words * (long long)size, PROT_READ, MAP_SHARED, binvecs_fd, 0); |
| 151 | vocab = mmap(0, sizeof(char) * (long long)words * max_w, PROT_READ, MAP_SHARED, binwords_fd, 0); |
| 152 | if (M == MAP_FAILED || vocab == MAP_FAILED) { |
| 153 | close(binvecs_fd); |
| 154 | close(binwords_fd); |
| 155 | fprintf(stderr, "Cannot mmap %s or %s\n", binwords_fname, binvecs_fname); |
| 156 | exit(-1); |
| 157 | } |
| 158 | } else { |
| 159 | fprintf(stderr, "Cannot open %s or %s\n", binwords_fname, binvecs_fname); |
| 160 | exit(-1); |
Marc Kupietz | 67c2028 | 2016-02-26 09:42:00 +0100 | [diff] [blame] | 161 | } |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 162 | fclose(f); |
| 163 | return 0; |
| 164 | } |
| 165 | |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 166 | |
| 167 | void *_get_neighbours(knnpars *pars) { |
| 168 | char *st1 = pars->token; |
| 169 | int N = pars->N; |
| 170 | unsigned long from = pars -> from; |
| 171 | unsigned long upto = pars -> upto; |
Marc Kupietz | 95aa1c0 | 2016-03-15 09:40:43 +0100 | [diff] [blame] | 172 | char file_name[max_size], st[100][max_size], sep[100]; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 173 | float dist, len, *bestd, vec[max_size]; |
| 174 | long long a, b, c, d, cn, bi[100], *besti; |
Marc Kupietz | 82b0267 | 2016-02-26 12:32:25 +0100 | [diff] [blame] | 175 | char ch; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 176 | knn *nbs = NULL; |
Marc Kupietz | 34a3ee9 | 2016-02-27 22:43:16 +0100 | [diff] [blame] | 177 | |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 178 | besti = malloc(N * sizeof(long long)); |
| 179 | bestd = malloc(N * sizeof(float)); |
Marc Kupietz | 7bc85fd | 2016-02-24 11:42:41 +0100 | [diff] [blame] | 180 | |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 181 | float worstbest=-1; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 182 | |
| 183 | for (a = 0; a < N; a++) bestd[a] = 0; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 184 | a = 0; |
| 185 | cn = 0; |
| 186 | b = 0; |
| 187 | c = 0; |
| 188 | while (1) { |
| 189 | st[cn][b] = st1[c]; |
| 190 | b++; |
| 191 | c++; |
| 192 | st[cn][b] = 0; |
| 193 | if (st1[c] == 0) break; |
Marc Kupietz | 95aa1c0 | 2016-03-15 09:40:43 +0100 | [diff] [blame] | 194 | if (st1[c] == ' ' || st1[c] == '-') { |
| 195 | sep[cn++] = st1[c]; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 196 | b = 0; |
| 197 | c++; |
| 198 | } |
| 199 | } |
| 200 | cn++; |
| 201 | for (a = 0; a < cn; a++) { |
Marc Kupietz | 34a3ee9 | 2016-02-27 22:43:16 +0100 | [diff] [blame] | 202 | for (b = 0; b < words; b++) if (!strcmp(&vocab[b * max_w], st[a])) break; |
| 203 | if (b == words) b = -1; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 204 | bi[a] = b; |
Marc Kupietz | e8da306 | 2016-02-25 08:37:53 +0100 | [diff] [blame] | 205 | fprintf(stderr, "Word: \"%s\" Position in vocabulary: %lld\n", st[a], bi[a]); |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 206 | if (b == -1) { |
Marc Kupietz | e8da306 | 2016-02-25 08:37:53 +0100 | [diff] [blame] | 207 | fprintf(stderr, "Out of dictionary word!\n"); |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 208 | cn--; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 209 | break; |
| 210 | } |
| 211 | } |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 212 | if (b == -1) { |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 213 | N = 0; |
| 214 | goto end; |
| 215 | } |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 216 | for (a = 0; a < size; a++) vec[a] = 0; |
| 217 | for (b = 0; b < cn; b++) { |
| 218 | if (bi[b] == -1) continue; |
Marc Kupietz | 95aa1c0 | 2016-03-15 09:40:43 +0100 | [diff] [blame] | 219 | if(b>0 && sep[b-1] == '-') |
| 220 | for (a = 0; a < size; a++) vec[a] -= M[a + bi[b] * size]; |
| 221 | else |
| 222 | for (a = 0; a < size; a++) vec[a] += M[a + bi[b] * size]; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 223 | } |
| 224 | len = 0; |
| 225 | for (a = 0; a < size; a++) len += vec[a] * vec[a]; |
| 226 | len = sqrt(len); |
| 227 | for (a = 0; a < size; a++) vec[a] /= len; |
| 228 | for (a = 0; a < N; a++) bestd[a] = -1; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 229 | for (c = from; c < upto; c++) { |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 230 | a = 0; |
Marc Kupietz | 34020dc | 2016-02-25 08:44:19 +0100 | [diff] [blame] | 231 | // do not skip taget word |
Marc Kupietz | e8da306 | 2016-02-25 08:37:53 +0100 | [diff] [blame] | 232 | // for (b = 0; b < cn; b++) if (bi[b] == c) a = 1; |
| 233 | // if (a == 1) continue; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 234 | dist = 0; |
| 235 | for (a = 0; a < size; a++) dist += vec[a] * M[a + c * size]; |
Marc Kupietz | be1b9fc | 2016-02-26 10:34:30 +0100 | [diff] [blame] | 236 | if(dist > worstbest) { |
| 237 | for (a = 0; a < N; a++) { |
| 238 | if (dist > bestd[a]) { |
| 239 | for (d = N - 1; d > a; d--) { |
| 240 | bestd[d] = bestd[d - 1]; |
| 241 | besti[d] = besti[d - 1]; |
| 242 | } |
| 243 | bestd[a] = dist; |
| 244 | besti[a] = c; |
| 245 | break; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 246 | } |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 247 | } |
Marc Kupietz | be1b9fc | 2016-02-26 10:34:30 +0100 | [diff] [blame] | 248 | worstbest = bestd[N-1]; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 249 | } |
| 250 | } |
Marc Kupietz | 34020dc | 2016-02-25 08:44:19 +0100 | [diff] [blame] | 251 | |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 252 | nbs = malloc(sizeof(knn)); |
| 253 | nbs->index = besti; |
| 254 | nbs->dist = bestd; |
| 255 | nbs->length = N; |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 256 | end: |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 257 | pthread_exit(nbs); |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 258 | } |
| 259 | |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 260 | SV *get_neighbours(char *st1, int N) { |
| 261 | float bestd[MAX_NEIGHBOURS], vec[max_size]; |
| 262 | long long besti[MAX_NEIGHBOURS], a, b, c, d, slice; |
| 263 | char *bestw[MAX_NEIGHBOURS]; |
| 264 | knn *nbs[MAX_THREADS]; |
| 265 | knnpars pars[MAX_THREADS]; |
| 266 | pthread_t *pt = (pthread_t *)malloc(num_threads * sizeof(pthread_t)); |
| 267 | AV* array = newAV(); |
| 268 | |
| 269 | if(N>MAX_NEIGHBOURS) N=MAX_NEIGHBOURS; |
| 270 | |
| 271 | slice = words / num_threads; |
| 272 | |
| 273 | for(a=0; a < num_threads; a++) { |
| 274 | pars[a].token = st1; |
| 275 | pars[a].N = N; |
| 276 | pars[a].from = a*slice; |
| 277 | pars[a].upto = ((a+1)*slice > words? words:(a+1)*slice); |
| 278 | pthread_create(&pt[a], NULL, _get_neighbours, (void *) &pars[a]); |
| 279 | } |
| 280 | for (a = 0; a < num_threads; a++) pthread_join(pt[a], &nbs[a]); |
| 281 | |
| 282 | if(!nbs[0]) |
| 283 | goto end; |
| 284 | |
| 285 | for(b=0; b < N; b++) { |
| 286 | besti[b] = nbs[0]->index[b]; |
| 287 | bestd[b] = nbs[0]->dist[b]; |
| 288 | } |
| 289 | |
| 290 | for(a=1; a < num_threads; a++) { |
| 291 | for(b=0; b < N; b++) { |
| 292 | for(c=0; c < N; c++) { |
| 293 | if(nbs[a]->dist[b] > bestd[c]) { |
| 294 | for(d=N-1; d>c; d--) { |
| 295 | bestd[d] = bestd[d-1]; |
| 296 | besti[d] = besti[d-1]; |
| 297 | } |
| 298 | besti[c] = nbs[a]->index[b]; |
| 299 | bestd[c] = nbs[a]->dist[b]; |
| 300 | break; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | if(nbs) { |
| 307 | for (a = 0; a < N; a++) { |
| 308 | bestw[a] = (char *)malloc(max_size * sizeof(char)); |
| 309 | } |
| 310 | for (a = 0; a < N; a++) { |
| 311 | strcpy(bestw[a], &vocab[besti[a] * max_w]); |
| 312 | HV* hash = newHV(); |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame^] | 313 | SV* word = newSVpvf(bestw[a], 0); |
| 314 | if(latin_enc == 0) SvUTF8_on(word); |
| 315 | hv_store(hash, "word", strlen("word"), word , 0); |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 316 | hv_store(hash, "dist", strlen("dist"), newSVnv(bestd[a]), 0); |
| 317 | hv_store(hash, "rank", strlen("rank"), newSVuv(besti[a]), 0); |
| 318 | AV *vector = newAV(); |
| 319 | for (b = 0; b < size; b++) { |
| 320 | av_push(vector, newSVnv(M[b + besti[a] * size])); |
| 321 | } |
| 322 | hv_store(hash, "vector", strlen("vector"), newRV_noinc((SV*)vector), 0); |
| 323 | av_push(array, newRV_noinc((SV*)hash)); |
| 324 | } |
| 325 | } |
| 326 | end: |
| 327 | return newRV_noinc((SV*)array); |
| 328 | } |
Marc Kupietz | 7bc85fd | 2016-02-24 11:42:41 +0100 | [diff] [blame] | 329 | |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 330 | __DATA__ |
| 331 | |
| 332 | @@ index.html.ep |
| 333 | <!DOCTYPE html> |
| 334 | <html> |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 335 | <head> |
| 336 | <title>DeReKo-Word-Vector-Distances</title> |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 337 | <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 338 | <script src="http://code.jquery.com/jquery-latest.min.js"></script> |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 339 | <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> |
| 340 | <script> |
| 341 | $(function() { |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 342 | $( document ).tooltip({ |
| 343 | content: function() { |
| 344 | return $(this).attr('title'); |
| 345 | }} |
| 346 | ) |
| 347 | }) |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 348 | </script> |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 349 | <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> |
| 350 | <script src="http://klinux10/word2vec/tsne.js"></script> |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 351 | <script src="http://klinux10/word2vec/som.js"></script> |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 352 | <script src="http://klinux10/word2vec/labeler.js"></script> |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 353 | <style> |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 354 | body, input { |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 355 | font-family: Arial, sans-serif; |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 356 | font-size: 11pt; |
| 357 | } |
| 358 | |
| 359 | .ui-tooltip-content { |
| 360 | font-size: 9pt; |
| 361 | colour: #222222; |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 362 | } |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 363 | |
| 364 | svg > .ui-tooltip-content { |
Marc Kupietz | b102936 | 2016-02-27 21:38:55 +0100 | [diff] [blame] | 365 | font-size: 8pt; |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 366 | colour: #222222; |
| 367 | } |
| 368 | |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 369 | #wrapper { |
| 370 | width: 100%; |
| 371 | // border: 1px solid red; |
| 372 | overflow: hidden; /* will contain if #first is longer than #second */ |
| 373 | } |
| 374 | #first { |
Marc Kupietz | b102936 | 2016-02-27 21:38:55 +0100 | [diff] [blame] | 375 | margin-right: 20px; |
| 376 | float: left; |
| 377 | // border: 1px solid green; |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 378 | } |
| 379 | #second { |
| 380 | border: 1px solid #333; |
| 381 | overflow: hidden; /* if you don't want #second to wrap below #first */ |
| 382 | } |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 383 | #som2 svg { |
| 384 | border: 1px solid #333; |
| 385 | } |
| 386 | |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 387 | #cost { |
Marc Kupietz | b102936 | 2016-02-27 21:38:55 +0100 | [diff] [blame] | 388 | font-size: 8pt; |
| 389 | color: #222222; |
| 390 | margin-top: 4px; |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 391 | margin-bottom: 12px; |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 392 | } |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 393 | |
Marc Kupietz | 6c1ca44 | 2016-03-03 09:35:18 +0100 | [diff] [blame] | 394 | #sominfo1, #sominfo { |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 395 | font-size: 8pt; |
| 396 | color: #222222; |
| 397 | margin-top: 0px; |
| 398 | } |
| 399 | |
Marc Kupietz | 6c1ca44 | 2016-03-03 09:35:18 +0100 | [diff] [blame] | 400 | #somcolor1, #somcolor2, #somcolor3 { |
| 401 | display: inline-block; |
| 402 | height: 10px; |
| 403 | width: 10px; |
| 404 | } |
| 405 | |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 406 | #third { |
| 407 | border: 1px solid #333; |
| 408 | } |
| 409 | |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 410 | </style> |
| 411 | <script> |
| 412 | |
Marc Kupietz | c4d62f8 | 2016-03-01 11:04:24 +0100 | [diff] [blame] | 413 | var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>}, |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 414 | mapWidth = 800, // width map |
| 415 | mapHeight = 800, |
| 416 | jitterRadius = 7; |
| 417 | |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 418 | var T = new tsnejs.tSNE(opt); // create a tSNE instance |
| 419 | |
| 420 | var Y; |
| 421 | |
| 422 | var data; |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 423 | var labeler; |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 424 | |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 425 | |
| 426 | function applyJitter() { |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 427 | svg.selectAll('.tsnet') |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 428 | .data(labels) |
| 429 | .transition() |
| 430 | .duration(50) |
| 431 | .attr("transform", function(d, i) { |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 432 | T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20; |
| 433 | T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20; |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 434 | return "translate(" + |
| 435 | (d.x) + "," + |
| 436 | (d.y) + ")"; |
| 437 | }); |
| 438 | } |
| 439 | |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 440 | function updateEmbedding() { |
| 441 | var Y = T.getSolution(); |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 442 | svg.selectAll('.tsnet') |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 443 | .data(data.words) |
| 444 | .attr("transform", function(d, i) { |
| 445 | return "translate(" + |
| 446 | ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," + |
| 447 | ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; }); |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | var svg; |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 451 | var labels = []; |
| 452 | var anchor_array = []; |
| 453 | var text; |
| 454 | |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 455 | function drawEmbedding() { |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 456 | $("#embed").empty(); |
| 457 | var div = d3.select("#embed"); |
| 458 | |
| 459 | // get min and max in each column of Y |
| 460 | var Y = T.Y; |
| 461 | |
| 462 | svg = div.append("svg") // svg is global |
| 463 | .attr("width", mapWidth) |
| 464 | .attr("height", mapHeight); |
| 465 | |
| 466 | var g = svg.selectAll(".b") |
| 467 | .data(data.words) |
| 468 | .enter().append("g") |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 469 | .attr("class", "tsnet"); |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 470 | |
| 471 | g.append("a") |
| 472 | .attr("xlink:href", function(word) {return "/?word="+word;}) |
| 473 | .attr("title", function(d, i) { |
Marc Kupietz | e50c816 | 2016-03-01 10:24:43 +0100 | [diff] [blame] | 474 | return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 475 | }) |
Marc Kupietz | a350bce | 2016-02-25 09:34:25 +0100 | [diff] [blame] | 476 | .append("text") |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 477 | .attr("text-anchor", "top") |
| 478 | .attr("font-size", 12) |
| 479 | .attr("fill", function(d) { |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 480 | if(data.target.indexOf(" "+d+" ") >= 0) { |
Marc Kupietz | a350bce | 2016-02-25 09:34:25 +0100 | [diff] [blame] | 481 | return "red"; |
| 482 | } else { |
| 483 | return "#333" |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 484 | } |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 485 | }) |
| 486 | .text(function(d) { return d; }); |
| 487 | |
| 488 | var zoomListener = d3.behavior.zoom() |
| 489 | .scaleExtent([0.1, 10]) |
| 490 | .center([0,0]) |
| 491 | .on("zoom", zoomHandler); |
| 492 | zoomListener(svg); |
| 493 | } |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 494 | |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 495 | var tx=0, ty=0; |
| 496 | var ss=1; |
| 497 | var iter_id=-1; |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 498 | |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 499 | function zoomHandler() { |
| 500 | tx = d3.event.translate[0]; |
| 501 | ty = d3.event.translate[1]; |
| 502 | ss = d3.event.scale; |
| 503 | updateEmbedding(); |
| 504 | } |
| 505 | |
| 506 | var stepnum = 0; |
| 507 | |
| 508 | function stopStep() { |
| 509 | clearInterval(iter_id); |
| 510 | text = svg.selectAll("text"); |
| 511 | |
| 512 | // jitter function needs different data and co-ordinate representation |
| 513 | labels = d3.range(data.words.length).map(function(i) { |
| 514 | var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2; |
| 515 | var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2; |
| 516 | anchor_array.push({x: x, y: y, r: jitterRadius}); |
| 517 | return { |
| 518 | x: x, |
| 519 | y: y, |
| 520 | name: data.words[i] |
| 521 | }; |
| 522 | }); |
| 523 | |
| 524 | // get the actual label bounding boxes for the jitter function |
| 525 | var index = 0; |
| 526 | text.each(function() { |
| 527 | labels[index].width = this.getBBox().width; |
| 528 | labels[index].height = this.getBBox().height; |
| 529 | index += 1; |
| 530 | }); |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 531 | |
| 532 | |
| 533 | // setTimeout(updateEmbedding, 1); |
| 534 | // setTimeout( |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 535 | labeler = d3.labeler() |
| 536 | .label(labels) |
| 537 | .anchor(anchor_array) |
| 538 | .width(mapWidth) |
| 539 | .height(mapHeight) |
| 540 | .update(applyJitter); |
| 541 | // .start(1000); |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 542 | |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 543 | iter_id = setInterval(jitterStep, 1); |
| 544 | } |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 545 | |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 546 | var jitter_i=0; |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 547 | |
| 548 | function jitterStep() { |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 549 | if(jitter_i++ > 100) { |
| 550 | clearInterval(iter_id); |
| 551 | } else { |
| 552 | labeler.start2(10); |
| 553 | applyJitter(); |
| 554 | } |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 555 | } |
Marc Kupietz | b102936 | 2016-02-27 21:38:55 +0100 | [diff] [blame] | 556 | |
| 557 | var last_cost=1000; |
| 558 | |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 559 | function step() { |
| 560 | var i = T.iter; |
| 561 | |
| 562 | if(i > <%= $no_iterations %>) { |
| 563 | stopStep(); |
| 564 | } else { |
| 565 | var cost = Math.round(T.step() * 100000) / 100000; // do a few steps |
| 566 | $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5)); |
| 567 | if(i % 250 == 0 && cost >= last_cost) { |
| 568 | stopStep(); |
| 569 | } else { |
| 570 | last_cost = cost; |
| 571 | updateEmbedding(); |
| 572 | } |
| 573 | } |
| 574 | } |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 575 | |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 576 | function showMap(j) { |
| 577 | data=j; |
| 578 | T.iter=0; |
| 579 | T.initDataRaw(data.vecs); // init embedding |
| 580 | drawEmbedding(); // draw initial embedding |
| 581 | |
| 582 | if(iter_id >= 0) { |
| 583 | clearInterval(iter_id); |
| 584 | } |
| 585 | //T.debugGrad(); |
| 586 | iter_id = setInterval(step, 1); |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 587 | if(<%= $show_som %>) { |
| 588 | makeSOM(j, <%= $no_iterations %>); |
| 589 | } |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 590 | } |
Marc Kupietz | a350bce | 2016-02-25 09:34:25 +0100 | [diff] [blame] | 591 | |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 592 | </script> |
| 593 | </head> |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 594 | <body> |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 595 | <form action="<%=url_for('/')->to_abs%>" method="GET"> |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 596 | word(s): |
| 597 | <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."> |
| 598 | max. neighbours: <input type="text" size="8" name="n" value="<%= $no_nbs %>"> |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 599 | max. iterations: <input type="text" name="N" size="8" value="<%= $no_iterations %>"> |
| 600 | SOM <input type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> |
| 601 | <span> </span><input type="submit" value="Show"> |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 602 | </form> |
| 603 | <br> |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 604 | % if($lists) { |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 605 | <div id="wrapper"> |
| 606 | <table id="first"> |
| 607 | <tr> |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 608 | <th align="right">Pos.</th><th align="left">Word</th><th align="right">Cosine dist.</th><th>Freq. rank</th> |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 609 | </tr> |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 610 | % my $j=0; my @words; my @vecs; my @ranks; for my $list (@$lists) { |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 611 | % my $i=1; for my $item (@$list) { |
| 612 | % if(!grep{$_ eq $item->{word}} @words) { |
| 613 | % push @vecs, $item->{vector}; |
| 614 | % push @words, $item->{word}; |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 615 | % push @ranks, $item->{rank}; |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 616 | % } |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 617 | <tr> |
| 618 | <td align="right"> |
| 619 | <%= $i++ %>. |
| 620 | </td> |
| 621 | <td> |
| 622 | <a href="/?word=<%= $item->{word} %>"> |
| 623 | <%= $item->{word} %> |
| 624 | </a> |
| 625 | </td> |
| 626 | <td align="right"> |
| 627 | <%= sprintf("%.3f", $item->{dist}) %> |
| 628 | </td> |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 629 | <td align="right"> |
| 630 | <%= $item->{rank} %> |
| 631 | </td> |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 632 | </tr> |
| 633 | % } |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 634 | % } |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 635 | </table> |
| 636 | <script> |
| 637 | % use Mojo::ByteStream 'b'; |
| 638 | $(window).load(function() { |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 639 | showMap(<%= b(Mojo::JSON::to_json({target => " $word ", words => \@words, vecs => \@vecs, ranks => \@ranks})); %>); |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 640 | }); |
| 641 | </script> |
| 642 | % } |
| 643 | <div id="second" style="width:800px; height:800px; font-family: arial;"> |
| 644 | <div id="embed"> |
| 645 | </div> |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 646 | </div> |
Marc Kupietz | b102936 | 2016-02-27 21:38:55 +0100 | [diff] [blame] | 647 | <div id="cost"></div> |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 648 | % if($show_som) { |
| 649 | <div id="som2"> |
| 650 | </div> |
Marc Kupietz | 6c1ca44 | 2016-03-03 09:35:18 +0100 | [diff] [blame] | 651 | <div id="sominfo1"><span id="somcolor1"> </span> <span id="somword1"> </span> <span id="somcolor2"> </span> <span id="somword2"> </span> <span id="somcolor3"> </span></div> |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 652 | <div id="sominfo">SOM iteration <span id="iterations">0</span></div> |
| 653 | % } |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 654 | </div> |
| 655 | <p> |
| 656 | 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 Kupietz | 247500f | 2015-10-09 11:29:01 +0200 | [diff] [blame] | 657 | <pre> |
Marc Kupietz | 7bc85fd | 2016-02-24 11:42:41 +0100 | [diff] [blame] | 658 | -cbow 1 -size 300 -window 7 -negative 5 -hs 0 -sample 1e-5 -threads 44 -binary 1 -iter 5 |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 659 | </pre> |
| 660 | </p> |
| 661 | </body> |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 662 | </html> |
| 663 | |