Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 1 | #!/usr/local/bin/perl |
| 2 | use Inline C; |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 3 | #use Inline C => Config => BUILD_NOISY => 1, CFLAGS => $Config{cflags}." -O4 -mtune k9"; |
| 4 | use Inline C => Config => CLEAN_AFTER_BUILD => 0, ccflags => $Config{ccflags}." -O4"; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 5 | use Mojolicious::Lite; |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 6 | use Mojo::JSON qw(decode_json encode_json to_json); |
Marc Kupietz | 247500f | 2015-10-09 11:29:01 +0200 | [diff] [blame] | 7 | use Encode qw(decode encode); |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame] | 8 | use Getopt::Std; |
Marc Kupietz | 7bc85fd | 2016-02-24 11:42:41 +0100 | [diff] [blame] | 9 | use Mojo::Server::Daemon; |
Marc Kupietz | d422739 | 2016-03-01 16:45:12 +0100 | [diff] [blame] | 10 | plugin 'Log::Access'; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 11 | |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame] | 12 | our $opt_i = 0; # latin1-input? |
| 13 | our $opt_l = undef; |
| 14 | our $opt_p = 5676; |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 15 | our $opt_m; |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 16 | our $opt_M; |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 17 | our $opt_n = ''; |
| 18 | our $opt_d; |
Marc Kupietz | 5c3887d | 2016-04-28 08:53:35 +0200 | [diff] [blame^] | 19 | our $opt_G; |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame] | 20 | |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 21 | my %marked; |
Marc Kupietz | 793413b | 2016-04-02 21:48:57 +0200 | [diff] [blame] | 22 | my $training_args=""; |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 23 | my $mergedEnd=0; |
Marc Kupietz | 793413b | 2016-04-02 21:48:57 +0200 | [diff] [blame] | 24 | |
Marc Kupietz | 5c3887d | 2016-04-28 08:53:35 +0200 | [diff] [blame^] | 25 | getopts('d:Gil:p:m:M:'); |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 26 | |
| 27 | if($opt_M) { |
Marc Kupietz | ed93021 | 2016-04-27 15:42:38 +0200 | [diff] [blame] | 28 | open my $handle, '<:encoding(UTF-8)', $opt_M |
| 29 | or die "Can't open '$opt_M' for reading: $!"; |
| 30 | while(<$handle>) { |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 31 | foreach my $mw (split /\s+/) { |
| 32 | $marked{$mw}=1 |
| 33 | } |
| 34 | } |
Marc Kupietz | ed93021 | 2016-04-27 15:42:38 +0200 | [diff] [blame] | 35 | close($handle); |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 36 | } |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame] | 37 | |
Marc Kupietz | 7bc85fd | 2016-02-24 11:42:41 +0100 | [diff] [blame] | 38 | # -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] | 39 | if(!$ARGV[0]) { |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 40 | init_net("vectors15.bin", $opt_n, ($opt_i? 1 : 0)); |
Marc Kupietz | 2cb667e | 2016-03-10 09:44:12 +0100 | [diff] [blame] | 41 | } else { |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 42 | init_net($ARGV[0], $opt_n, ($opt_i? 1 : 0)); |
Marc Kupietz | 793413b | 2016-04-02 21:48:57 +0200 | [diff] [blame] | 43 | if(open(FILE, "$ARGV[0].args")) { |
| 44 | $training_args = <FILE>; |
| 45 | } |
| 46 | close(FILE); |
Marc Kupietz | 2cb667e | 2016-03-10 09:44:12 +0100 | [diff] [blame] | 47 | } |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 48 | |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 49 | if($opt_m) { |
| 50 | $mergedEnd = mergeVectors($opt_m); |
| 51 | } |
| 52 | |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 53 | |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 54 | if($opt_d) { # -d: dump vecs and exit |
| 55 | dump_vecs($opt_d); |
| 56 | exit; |
| 57 | } |
| 58 | |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame] | 59 | my $daemon = Mojo::Server::Daemon->new( |
| 60 | app => app, |
| 61 | listen => ['http://'.($opt_l ? $opt_l : '*').":$opt_p"] |
| 62 | ); |
| 63 | |
Marc Kupietz | 5c3887d | 2016-04-28 08:53:35 +0200 | [diff] [blame^] | 64 | if($opt_G) { |
| 65 | print "Filtering garbage\n"; |
| 66 | filter_garbage(); |
| 67 | } |
| 68 | |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 69 | get '/' => sub { |
| 70 | my $c = shift; |
| 71 | my $word=$c->param('word'); |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 72 | my $no_nbs=$c->param('n') || 100; |
| 73 | my $no_iterations=$c->param('N') || 2000; |
Marc Kupietz | d422739 | 2016-03-01 16:45:12 +0100 | [diff] [blame] | 74 | my $perplexity=$c->param('perplexity') || 20; |
Marc Kupietz | c4d62f8 | 2016-03-01 11:04:24 +0100 | [diff] [blame] | 75 | my $epsilon=$c->param('epsilon') || 5; |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 76 | my $som=$c->param('som') || 0; |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 77 | my $searchBaseVocabFirst=$c->param('sbf') || 0; |
Marc Kupietz | 6d9a678 | 2016-03-23 17:25:25 +0100 | [diff] [blame] | 78 | my $sort=$c->param('sort') || 0; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 79 | my $res; |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 80 | my @lists; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 81 | my @collocations; |
Marc Kupietz | 7bc85fd | 2016-02-24 11:42:41 +0100 | [diff] [blame] | 82 | if(defined($word) && $word !~ /^\s*$/) { |
| 83 | $c->inactivity_timeout(300); |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 84 | $word =~ s/\s+/ /g; |
| 85 | for my $w (split(' *\| *', $word)) { |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 86 | $c->app->log->debug('Looking for neighbours of '.$w); |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame] | 87 | if($opt_i) { |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 88 | $res = get_neighbours(encode("iso-8859-1", $w), $no_nbs, $sort, $searchBaseVocabFirst); |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame] | 89 | } else { |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 90 | $res = get_neighbours($w, $no_nbs, $sort, $searchBaseVocabFirst); |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame] | 91 | } |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 92 | push(@lists, $res->{paradigmatic}); |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 93 | } |
Marc Kupietz | 247500f | 2015-10-09 11:29:01 +0200 | [diff] [blame] | 94 | } |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 95 | $word =~ s/ *\| */ | /g; |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 96 | $c->render(template=>"index", word=>$word, no_nbs=>$no_nbs, no_iterations => $no_iterations, epsilon=> $epsilon, perplexity=> $perplexity, show_som=>$som, searchBaseVocabFirst=>$searchBaseVocabFirst, sort=>$sort, training_args=>$training_args, mergedEnd=> $mergedEnd, marked=>\%marked, lists=> \@lists, collocators=> $res->{syntagmatic}); |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 97 | }; |
| 98 | |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame] | 99 | $daemon->run; # app->start; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 100 | |
| 101 | exit; |
| 102 | |
| 103 | __END__ |
| 104 | |
| 105 | __C__ |
| 106 | #include <stdio.h> |
| 107 | #include <string.h> |
| 108 | #include <math.h> |
| 109 | #include <malloc.h> |
| 110 | #include <stdlib.h> //strlen |
Marc Kupietz | f080976 | 2016-02-26 10:13:47 +0100 | [diff] [blame] | 111 | #include <sys/mman.h> |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 112 | #include <pthread.h> |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 113 | |
| 114 | #define max_size 2000 |
| 115 | #define max_w 50 |
Marc Kupietz | 7bc85fd | 2016-02-24 11:42:41 +0100 | [diff] [blame] | 116 | #define MAX_NEIGHBOURS 1000 |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 117 | #define MAX_WORDS -1 |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 118 | #define MAX_THREADS 100 |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 119 | #define MAX_CC 50 |
| 120 | #define EXP_TABLE_SIZE 1000 |
| 121 | #define MAX_EXP 6 |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 122 | #define MIN_RESP 0.50 |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 123 | |
| 124 | //the thread function |
| 125 | void *connection_handler(void *); |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 126 | |
| 127 | typedef struct { |
| 128 | long long *index; |
| 129 | float *dist; |
Marc Kupietz | b864ccf | 2016-03-21 22:40:03 +0100 | [diff] [blame] | 130 | float *norm; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 131 | long long *pos; |
Marc Kupietz | 80abb44 | 2016-03-23 21:04:08 +0100 | [diff] [blame] | 132 | int length; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 133 | } knn; |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 134 | |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 135 | typedef struct { |
Marc Kupietz | 48c2968 | 2016-03-19 11:30:43 +0100 | [diff] [blame] | 136 | long long wordi[MAX_NEIGHBOURS]; |
| 137 | char sep[MAX_NEIGHBOURS]; |
| 138 | int length; |
| 139 | } wordlist; |
| 140 | |
| 141 | typedef struct { |
| 142 | wordlist *wl; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 143 | char *token; |
| 144 | int N; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 145 | long from; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 146 | unsigned long upto; |
Marc Kupietz | ce3d4c6 | 2016-03-23 16:11:25 +0100 | [diff] [blame] | 147 | float *target_sums; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 148 | } knnpars; |
| 149 | |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 150 | float *M, *M2=0L, *syn1neg_window, *expTable; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 151 | char *vocab; |
Marc Kupietz | 5c3887d | 2016-04-28 08:53:35 +0200 | [diff] [blame^] | 152 | char *garbage = NULL; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 153 | |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 154 | long long words, size, merged_end; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 155 | int num_threads=20; |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame] | 156 | int latin_enc=0; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 157 | int window; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 158 | |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 159 | int init_net(char *file_name, char *net_name, int latin) { |
Marc Kupietz | 67c2028 | 2016-02-26 09:42:00 +0100 | [diff] [blame] | 160 | FILE *f, *binvecs, *binwords; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 161 | int binwords_fd, binvecs_fd, net_fd, i; |
Marc Kupietz | 82b0267 | 2016-02-26 12:32:25 +0100 | [diff] [blame] | 162 | long long a, b, c, d, cn; |
| 163 | float len; |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 164 | double val; |
Marc Kupietz | 82b0267 | 2016-02-26 12:32:25 +0100 | [diff] [blame] | 165 | |
Marc Kupietz | 67c2028 | 2016-02-26 09:42:00 +0100 | [diff] [blame] | 166 | char binvecs_fname[256], binwords_fname[256]; |
| 167 | strcpy(binwords_fname, file_name); |
| 168 | strcat(binwords_fname, ".words"); |
| 169 | strcpy(binvecs_fname, file_name); |
| 170 | strcat(binvecs_fname, ".vecs"); |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 171 | |
Marc Kupietz | a5b9015 | 2016-03-15 17:39:19 +0100 | [diff] [blame] | 172 | latin_enc = latin; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 173 | f = fopen(file_name, "rb"); |
| 174 | if (f == NULL) { |
| 175 | printf("Input file %s not found\n", file_name); |
| 176 | return -1; |
| 177 | } |
| 178 | fscanf(f, "%lld", &words); |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 179 | if(MAX_WORDS > 0 && words > MAX_WORDS) words = MAX_WORDS; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 180 | fscanf(f, "%lld", &size); |
Marc Kupietz | 2cb667e | 2016-03-10 09:44:12 +0100 | [diff] [blame] | 181 | if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) < 0 || (binwords_fd = open(binwords_fname, O_RDONLY)) < 0) { |
| 182 | printf("Converting %s to memory mappable structures\n", file_name); |
Marc Kupietz | f080976 | 2016-02-26 10:13:47 +0100 | [diff] [blame] | 183 | vocab = (char *)malloc((long long)words * max_w * sizeof(char)); |
| 184 | M = (float *)malloc((long long)words * (long long)size * sizeof(float)); |
| 185 | if (M == NULL) { |
| 186 | printf("Cannot allocate memory: %lld MB %lld %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size); |
| 187 | return -1; |
| 188 | } |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 189 | if(strstr(file_name, ".txt")) { |
| 190 | for (b = 0; b < words; b++) { |
| 191 | a = 0; |
| 192 | while (1) { |
| 193 | vocab[b * max_w + a] = fgetc(f); |
| 194 | if (feof(f) || (vocab[b * max_w + a] == ' ')) break; |
| 195 | if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++; |
| 196 | } |
| 197 | vocab[b * max_w + a] = 0; |
| 198 | len = 0; |
| 199 | for (a = 0; a < size; a++) { |
| 200 | fscanf(f, "%lf", &val); |
| 201 | M[a + b * size] = val; |
| 202 | len += val * val; |
| 203 | } |
| 204 | len = sqrt(len); |
| 205 | for (a = 0; a < size; a++) M[a + b * size] /= len; |
| 206 | } |
| 207 | } else { |
| 208 | for (b = 0; b < words; b++) { |
| 209 | a = 0; |
| 210 | while (1) { |
| 211 | vocab[b * max_w + a] = fgetc(f); |
| 212 | if (feof(f) || (vocab[b * max_w + a] == ' ')) break; |
| 213 | if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++; |
| 214 | } |
| 215 | vocab[b * max_w + a] = 0; |
| 216 | fread(&M[b * size], sizeof(float), size, f); |
| 217 | len = 0; |
| 218 | for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size]; |
| 219 | len = sqrt(len); |
| 220 | for (a = 0; a < size; a++) M[a + b * size] /= len; |
| 221 | } |
| 222 | } |
Marc Kupietz | 67c2028 | 2016-02-26 09:42:00 +0100 | [diff] [blame] | 223 | if( (binvecs = fopen(binvecs_fname, "wb")) != NULL && (binwords = fopen(binwords_fname, "wb")) != NULL) { |
| 224 | fwrite(M, sizeof(float), (long long)words * (long long)size, binvecs); |
| 225 | fclose(binvecs); |
| 226 | fwrite(vocab, sizeof(char), (long long)words * max_w, binwords); |
| 227 | fclose(binwords); |
| 228 | } |
Marc Kupietz | 2cb667e | 2016-03-10 09:44:12 +0100 | [diff] [blame] | 229 | } |
| 230 | if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) >= 0 && (binwords_fd = open(binwords_fname, O_RDONLY)) >= 0) { |
| 231 | M = mmap(0, sizeof(float) * (long long)words * (long long)size, PROT_READ, MAP_SHARED, binvecs_fd, 0); |
| 232 | vocab = mmap(0, sizeof(char) * (long long)words * max_w, PROT_READ, MAP_SHARED, binwords_fd, 0); |
| 233 | if (M == MAP_FAILED || vocab == MAP_FAILED) { |
| 234 | close(binvecs_fd); |
| 235 | close(binwords_fd); |
| 236 | fprintf(stderr, "Cannot mmap %s or %s\n", binwords_fname, binvecs_fname); |
| 237 | exit(-1); |
| 238 | } |
| 239 | } else { |
| 240 | fprintf(stderr, "Cannot open %s or %s\n", binwords_fname, binvecs_fname); |
| 241 | exit(-1); |
Marc Kupietz | 67c2028 | 2016-02-26 09:42:00 +0100 | [diff] [blame] | 242 | } |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 243 | fclose(f); |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 244 | |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 245 | if(net_name && strlen(net_name) > 0) { |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 246 | if( (net_fd = open(net_name, O_RDONLY)) >= 0) { |
| 247 | window = (lseek(net_fd, 0, SEEK_END) - sizeof(float) * words * size) / words / size / sizeof(float) / 2; |
| 248 | // lseek(net_fd, sizeof(float) * words * size, SEEK_SET); |
Marc Kupietz | 10bec2b | 2016-03-23 09:41:31 +0100 | [diff] [blame] | 249 | // munmap(M, sizeof(float) * words * size); |
| 250 | M2 = mmap(0, sizeof(float) * words * size + sizeof(float) * 2 * window * size * words, PROT_READ, MAP_SHARED, net_fd, 0); |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 251 | if (M2 == MAP_FAILED) { |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 252 | close(net_fd); |
| 253 | fprintf(stderr, "Cannot mmap %s\n", net_name); |
| 254 | exit(-1); |
| 255 | } |
Marc Kupietz | 10bec2b | 2016-03-23 09:41:31 +0100 | [diff] [blame] | 256 | syn1neg_window = M2 + words * size; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 257 | } else { |
| 258 | fprintf(stderr, "Cannot open %s\n", net_name); |
| 259 | exit(-1); |
| 260 | } |
| 261 | fprintf(stderr, "Successfully memmaped %s. Determined window size: %d\n", net_name, window); |
| 262 | } |
| 263 | |
| 264 | expTable = (float *) malloc((EXP_TABLE_SIZE + 1) * sizeof(float)); |
| 265 | for (i = 0; i < EXP_TABLE_SIZE; i++) { |
| 266 | expTable[i] = exp((i / (float) EXP_TABLE_SIZE * 2 - 1) * MAX_EXP); // Precompute the exp() table |
| 267 | expTable[i] = expTable[i] / (expTable[i] + 1); // Precompute f(x) = x / (x + 1) |
| 268 | } |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 269 | return 0; |
| 270 | } |
| 271 | |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 272 | long mergeVectors(char *file_name){ |
| 273 | FILE *f, *binvecs, *binwords; |
| 274 | int binwords_fd, binvecs_fd, net_fd, i; |
| 275 | long long a, b, c, d, cn; |
| 276 | float len; |
| 277 | float *merge_vecs; |
| 278 | char *merge_vocab; |
| 279 | long long merge_words, merge_size; |
| 280 | |
| 281 | char binvecs_fname[256], binwords_fname[256]; |
| 282 | strcpy(binwords_fname, file_name); |
| 283 | strcat(binwords_fname, ".words"); |
| 284 | strcpy(binvecs_fname, file_name); |
| 285 | strcat(binvecs_fname, ".vecs"); |
| 286 | |
| 287 | f = fopen(file_name, "rb"); |
| 288 | if (f == NULL) { |
| 289 | printf("Input file %s not found\n", file_name); |
| 290 | exit -1; |
| 291 | } |
| 292 | fscanf(f, "%lld", &merge_words); |
| 293 | fscanf(f, "%lld", &merge_size); |
| 294 | if(merge_size != size){ |
| 295 | fprintf(stderr, "vectors must have the same length\n"); |
| 296 | exit(-1); |
| 297 | } |
| 298 | if( (binvecs_fd = open(binvecs_fname, O_RDONLY)) >= 0 && (binwords_fd = open(binwords_fname, O_RDONLY)) >= 0) { |
| 299 | merge_vecs = malloc(sizeof(float) * (words + merge_words) * size); |
| 300 | merge_vocab = malloc(sizeof(char) * (words + merge_words) * max_w); |
| 301 | if (merge_vecs == NULL || merge_vocab == NULL) { |
| 302 | close(binvecs_fd); |
| 303 | close(binwords_fd); |
| 304 | fprintf(stderr, "Cannot reserve memory for %s or %s\n", binwords_fname, binvecs_fname); |
| 305 | exit(-1); |
| 306 | } |
| 307 | read(binvecs_fd, merge_vecs, merge_words * size * sizeof(float)); |
| 308 | read(binwords_fd, merge_vocab, merge_words * max_w); |
| 309 | } else { |
| 310 | fprintf(stderr, "Cannot open %s or %s\n", binwords_fname, binvecs_fname); |
| 311 | exit(-1); |
| 312 | } |
| 313 | printf("Successfully reallocated memory\nMerging...\n"); |
| 314 | fflush(stdout); |
| 315 | memcpy(merge_vecs + merge_words * size, M, words * size * sizeof(float)); |
| 316 | memcpy(merge_vocab + merge_words * max_w, vocab, words * max_w); |
| 317 | munmap(M, words * size * sizeof(float)); |
| 318 | munmap(vocab, words * max_w); |
| 319 | M = merge_vecs; |
| 320 | vocab = merge_vocab; |
| 321 | merged_end = merge_words; |
| 322 | words += merge_words; |
| 323 | fclose(f); |
| 324 | printf("merged_end: %lld, words: %lld\n", merged_end, words); |
| 325 | return((long) merged_end); |
| 326 | } |
| 327 | |
Marc Kupietz | 5c3887d | 2016-04-28 08:53:35 +0200 | [diff] [blame^] | 328 | void filter_garbage() { |
| 329 | long i; |
| 330 | char *w, previous, c; |
| 331 | garbage = malloc(words); |
| 332 | memset(garbage, 0, words); |
| 333 | for (i = 0; i < words; i++) { |
| 334 | w = vocab + i * max_w; |
| 335 | previous = 0; |
| 336 | while((c=*w++) && !garbage[i]) { |
| 337 | if( ((c & 32) == 0 && (previous & 32) == 32) || |
| 338 | previous == '-' && (c & 32) || |
| 339 | c == '' |
| 340 | ) { |
| 341 | garbage[i]=1; |
| 342 | continue; |
| 343 | } |
| 344 | previous = c; |
| 345 | } |
| 346 | } |
| 347 | return; |
| 348 | } |
| 349 | |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 350 | void *getCollocators(knnpars *pars) { |
| 351 | int N = pars->N; |
| 352 | int cc = pars->wl->wordi[0]; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 353 | knn *nbs = NULL; |
| 354 | long window_layer_size = size * window * 2; |
| 355 | long a, b, c, d, e, window_offset, target, max_target=0, maxmax_target; |
| 356 | float f, max_f, maxmax_f; |
Marc Kupietz | b864ccf | 2016-03-21 22:40:03 +0100 | [diff] [blame] | 357 | float *target_sums, *bestf, *bestn, worstbest, wpos_sum; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 358 | long long *besti, *bestp; |
Marc Kupietz | d564258 | 2016-03-19 22:23:13 +0100 | [diff] [blame] | 359 | |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 360 | if(M2 == NULL || cc == -1) |
Marc Kupietz | d564258 | 2016-03-19 22:23:13 +0100 | [diff] [blame] | 361 | return NULL; |
| 362 | |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 363 | a = posix_memalign((void **) &target_sums, 128, words * sizeof(float)); |
| 364 | besti = malloc(N * sizeof(long long)); |
| 365 | bestp = malloc(N * sizeof(long long)); |
| 366 | bestf = malloc(N * sizeof(float)); |
Marc Kupietz | b864ccf | 2016-03-21 22:40:03 +0100 | [diff] [blame] | 367 | bestn = malloc(N * sizeof(float)); |
| 368 | |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 369 | worstbest = MIN_RESP; |
| 370 | |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 371 | for (b = 0; b < words; b++) |
| 372 | target_sums[b]=0; |
Marc Kupietz | b864ccf | 2016-03-21 22:40:03 +0100 | [diff] [blame] | 373 | for (b = 0; b < N; b++) { |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 374 | besti[b] = -1; |
Marc Kupietz | b864ccf | 2016-03-21 22:40:03 +0100 | [diff] [blame] | 375 | bestn[b] = 1; |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 376 | bestf[b] = worstbest; |
Marc Kupietz | b864ccf | 2016-03-21 22:40:03 +0100 | [diff] [blame] | 377 | } |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 378 | |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 379 | d = cc; |
| 380 | maxmax_f = -1; |
| 381 | maxmax_target = 0; |
| 382 | |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 383 | for (a = pars->from; a < pars->upto; a++) { |
| 384 | if(a >= window) |
| 385 | a++; |
Marc Kupietz | b864ccf | 2016-03-21 22:40:03 +0100 | [diff] [blame] | 386 | wpos_sum = 0; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 387 | printf("window pos: %ld\n", a); |
| 388 | if (a != window) { |
| 389 | max_f = -1; |
| 390 | window_offset = a * size; |
| 391 | if (a > window) |
| 392 | window_offset -= size; |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 393 | for(target = 0; target < words; target ++) { |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 394 | if(target == d) |
| 395 | continue; |
| 396 | f = 0; |
| 397 | for (c = 0; c < size; c++) |
Marc Kupietz | 10bec2b | 2016-03-23 09:41:31 +0100 | [diff] [blame] | 398 | f += M2[d* size + c] * syn1neg_window[target * window_layer_size + window_offset + c]; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 399 | if (f < -MAX_EXP) |
| 400 | continue; |
| 401 | else if (f > MAX_EXP) |
| 402 | continue; |
| 403 | else |
| 404 | f = expTable[(int) ((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))]; |
Marc Kupietz | b864ccf | 2016-03-21 22:40:03 +0100 | [diff] [blame] | 405 | wpos_sum += f; |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 406 | |
Marc Kupietz | ce3d4c6 | 2016-03-23 16:11:25 +0100 | [diff] [blame] | 407 | target_sums[target] += f; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 408 | if(f > worstbest) { |
Marc Kupietz | 6d9a678 | 2016-03-23 17:25:25 +0100 | [diff] [blame] | 409 | for (b = 0; b < N; b++) { |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 410 | if (f > bestf[b]) { |
Marc Kupietz | 33679a3 | 2016-03-22 08:49:39 +0100 | [diff] [blame] | 411 | memmove(bestf + b + 1, bestf + b, (N - b -1) * sizeof(float)); |
| 412 | memmove(besti + b + 1, besti + b, (N - b -1) * sizeof(long long)); |
| 413 | memmove(bestp + b + 1, bestp + b, (N - b -1) * sizeof(long long)); |
| 414 | bestf[b] = f; |
| 415 | besti[b] = target; |
| 416 | bestp[b] = window-a; |
| 417 | break; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 418 | } |
| 419 | } |
Marc Kupietz | 6d9a678 | 2016-03-23 17:25:25 +0100 | [diff] [blame] | 420 | if(b == N - 1) |
| 421 | worstbest = bestf[N-1]; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | printf("%d %.2f\n", max_target, max_f); |
| 425 | printf("%s (%.2f) ", &vocab[max_target * max_w], max_f); |
| 426 | if(max_f > maxmax_f) { |
| 427 | maxmax_f = max_f; |
| 428 | maxmax_target = max_target; |
| 429 | } |
Marc Kupietz | 33679a3 | 2016-03-22 08:49:39 +0100 | [diff] [blame] | 430 | for (b = 0; b < N; b++) |
Marc Kupietz | b864ccf | 2016-03-21 22:40:03 +0100 | [diff] [blame] | 431 | if(bestp[b] == window-a) |
| 432 | bestn[b] = bestf[b] / wpos_sum; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 433 | } else { |
| 434 | printf("\x1b[1m%s\x1b[0m ", &vocab[d*max_w]); |
| 435 | } |
Marc Kupietz | b864ccf | 2016-03-21 22:40:03 +0100 | [diff] [blame] | 436 | |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 437 | } |
Marc Kupietz | ce3d4c6 | 2016-03-23 16:11:25 +0100 | [diff] [blame] | 438 | for (b = 0; b < words; b++) |
| 439 | pars->target_sums[b] += (target_sums[b] / wpos_sum ) / (window * 2); |
| 440 | free(target_sums); |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 441 | for(b=0; b<N && besti[b] >= 0; b++) // THIS LOOP IS NEEDED (b...) |
Marc Kupietz | ce3d4c6 | 2016-03-23 16:11:25 +0100 | [diff] [blame] | 442 | printf("%s %.2f %d * ", &vocab[besti[b]*max_w], bestf[b], bestp[b]); |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 443 | printf("\n"); |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 444 | nbs = malloc(sizeof(knn)); |
| 445 | nbs->index = besti; |
| 446 | nbs->dist = bestf; |
Marc Kupietz | b864ccf | 2016-03-21 22:40:03 +0100 | [diff] [blame] | 447 | nbs->norm = bestn; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 448 | nbs->pos = bestp; |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 449 | nbs->length = b-1; |
| 450 | pthread_exit(nbs); |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 451 | } |
| 452 | |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 453 | wordlist *getTargetWords(char *st1, int search_backw) { |
Marc Kupietz | 48c2968 | 2016-03-19 11:30:43 +0100 | [diff] [blame] | 454 | wordlist *wl = malloc(sizeof(wordlist)); |
| 455 | char st[100][max_size], sep[100]; |
| 456 | long a, b=0, c=0, cn=0; |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 457 | int unmerged; |
| 458 | |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 459 | while (1) { |
| 460 | st[cn][b] = st1[c]; |
| 461 | b++; |
| 462 | c++; |
| 463 | st[cn][b] = 0; |
| 464 | if (st1[c] == 0) break; |
Marc Kupietz | 95aa1c0 | 2016-03-15 09:40:43 +0100 | [diff] [blame] | 465 | if (st1[c] == ' ' || st1[c] == '-') { |
| 466 | sep[cn++] = st1[c]; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 467 | b = 0; |
| 468 | c++; |
| 469 | } |
| 470 | } |
| 471 | cn++; |
| 472 | for (a = 0; a < cn; a++) { |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 473 | if(search_backw) { |
| 474 | for (b = words - 1; b >= 0; b--) if (!strcmp(&vocab[b * max_w], st[a])) break; |
| 475 | } else { |
| 476 | for (b = 0; b < words; b++) if (!strcmp(&vocab[b * max_w], st[a])) break; |
| 477 | } |
Marc Kupietz | 34a3ee9 | 2016-02-27 22:43:16 +0100 | [diff] [blame] | 478 | if (b == words) b = -1; |
Marc Kupietz | 48c2968 | 2016-03-19 11:30:43 +0100 | [diff] [blame] | 479 | wl->wordi[a] = b; |
| 480 | fprintf(stderr, "Word: \"%s\" Position in vocabulary: %lld\n", st[a], wl->wordi[a]); |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 481 | if (b == -1) { |
Marc Kupietz | e8da306 | 2016-02-25 08:37:53 +0100 | [diff] [blame] | 482 | fprintf(stderr, "Out of dictionary word!\n"); |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 483 | cn--; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 484 | break; |
| 485 | } |
| 486 | } |
Marc Kupietz | 48c2968 | 2016-03-19 11:30:43 +0100 | [diff] [blame] | 487 | wl->length=cn; |
| 488 | return(wl); |
| 489 | } |
| 490 | |
| 491 | void *_get_neighbours(knnpars *pars) { |
| 492 | char *st1 = pars->token; |
| 493 | int N = pars->N; |
| 494 | long from = pars -> from; |
| 495 | unsigned long upto = pars -> upto; |
| 496 | char file_name[max_size], st[100][max_size], *sep; |
| 497 | float dist, len, *bestd, vec[max_size]; |
| 498 | long long a, b, c, d, cn, *bi, *besti; |
| 499 | char ch; |
| 500 | knn *nbs = NULL; |
| 501 | wordlist *wl = pars->wl; |
| 502 | |
| 503 | besti = malloc(N * sizeof(long long)); |
| 504 | bestd = malloc(N * sizeof(float)); |
| 505 | |
| 506 | float worstbest=-1; |
| 507 | |
| 508 | for (a = 0; a < N; a++) bestd[a] = 0; |
| 509 | a = 0; |
| 510 | bi = wl->wordi; |
| 511 | cn = wl->length; |
| 512 | sep = wl->sep; |
| 513 | b = bi[0]; |
| 514 | c = 0; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 515 | if (b == -1) { |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 516 | N = 0; |
| 517 | goto end; |
| 518 | } |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 519 | for (a = 0; a < size; a++) vec[a] = 0; |
| 520 | for (b = 0; b < cn; b++) { |
| 521 | if (bi[b] == -1) continue; |
Marc Kupietz | 95aa1c0 | 2016-03-15 09:40:43 +0100 | [diff] [blame] | 522 | if(b>0 && sep[b-1] == '-') |
| 523 | for (a = 0; a < size; a++) vec[a] -= M[a + bi[b] * size]; |
| 524 | else |
| 525 | 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] | 526 | } |
| 527 | len = 0; |
| 528 | for (a = 0; a < size; a++) len += vec[a] * vec[a]; |
| 529 | len = sqrt(len); |
| 530 | for (a = 0; a < size; a++) vec[a] /= len; |
| 531 | for (a = 0; a < N; a++) bestd[a] = -1; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 532 | for (c = from; c < upto; c++) { |
Marc Kupietz | 5c3887d | 2016-04-28 08:53:35 +0200 | [diff] [blame^] | 533 | if(garbage && garbage[c]) continue; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 534 | a = 0; |
Marc Kupietz | 34020dc | 2016-02-25 08:44:19 +0100 | [diff] [blame] | 535 | // do not skip taget word |
Marc Kupietz | e8da306 | 2016-02-25 08:37:53 +0100 | [diff] [blame] | 536 | // for (b = 0; b < cn; b++) if (bi[b] == c) a = 1; |
| 537 | // if (a == 1) continue; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 538 | dist = 0; |
| 539 | 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] | 540 | if(dist > worstbest) { |
| 541 | for (a = 0; a < N; a++) { |
| 542 | if (dist > bestd[a]) { |
Marc Kupietz | 33679a3 | 2016-03-22 08:49:39 +0100 | [diff] [blame] | 543 | memmove(bestd + a + 1, bestd + a, (N - a -1) * sizeof(float)); |
| 544 | memmove(besti + a + 1, besti + a, (N - a -1) * sizeof(long long)); |
Marc Kupietz | be1b9fc | 2016-02-26 10:34:30 +0100 | [diff] [blame] | 545 | bestd[a] = dist; |
| 546 | besti[a] = c; |
| 547 | break; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 548 | } |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 549 | } |
Marc Kupietz | be1b9fc | 2016-02-26 10:34:30 +0100 | [diff] [blame] | 550 | worstbest = bestd[N-1]; |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 551 | } |
| 552 | } |
Marc Kupietz | 34020dc | 2016-02-25 08:44:19 +0100 | [diff] [blame] | 553 | |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 554 | nbs = malloc(sizeof(knn)); |
| 555 | nbs->index = besti; |
| 556 | nbs->dist = bestd; |
| 557 | nbs->length = N; |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 558 | end: |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 559 | pthread_exit(nbs); |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 560 | } |
| 561 | |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 562 | |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 563 | SV *get_neighbours(char *st1, int N, int sort_by, int search_backw) { |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 564 | HV *result = newHV(); |
Marc Kupietz | ce3d4c6 | 2016-03-23 16:11:25 +0100 | [diff] [blame] | 565 | float *target_sums, bestd[MAX_NEIGHBOURS], bestn[MAX_NEIGHBOURS], bests[MAX_NEIGHBOURS], vec[max_size]; |
Marc Kupietz | 50485ba | 2016-03-23 09:13:14 +0100 | [diff] [blame] | 566 | long besti[MAX_NEIGHBOURS], bestp[MAX_NEIGHBOURS], a, b, c, d, slice; |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 567 | knn *para_nbs[MAX_THREADS]; |
| 568 | knn *syn_nbs[MAX_THREADS]; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 569 | knnpars pars[MAX_THREADS]; |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 570 | pthread_t *pt = (pthread_t *)malloc((num_threads+1) * sizeof(pthread_t)); |
Marc Kupietz | 48c2968 | 2016-03-19 11:30:43 +0100 | [diff] [blame] | 571 | wordlist *wl; |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 572 | int syn_threads = (M2? window * 2 : 0); |
| 573 | int para_threads = num_threads - syn_threads; |
Marc Kupietz | 48c2968 | 2016-03-19 11:30:43 +0100 | [diff] [blame] | 574 | |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 575 | if(N>MAX_NEIGHBOURS) N=MAX_NEIGHBOURS; |
| 576 | |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 577 | slice = words / para_threads; |
| 578 | |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 579 | wl = getTargetWords(st1, search_backw); |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 580 | if(wl->length < 1) |
| 581 | goto end; |
Marc Kupietz | 48c2968 | 2016-03-19 11:30:43 +0100 | [diff] [blame] | 582 | |
Marc Kupietz | ce3d4c6 | 2016-03-23 16:11:25 +0100 | [diff] [blame] | 583 | a = posix_memalign((void **) &target_sums, 128, words * sizeof(float)); |
| 584 | for(a = 0; a < words; a++) |
| 585 | target_sums[a] = 0; |
| 586 | |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 587 | printf("Starting %d threads\n", para_threads); |
| 588 | fflush(stdout); |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 589 | for(a=0; a < para_threads; a++) { |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 590 | pars[a].token = st1; |
Marc Kupietz | 48c2968 | 2016-03-19 11:30:43 +0100 | [diff] [blame] | 591 | pars[a].wl = wl; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 592 | pars[a].N = N; |
| 593 | pars[a].from = a*slice; |
| 594 | pars[a].upto = ((a+1)*slice > words? words:(a+1)*slice); |
| 595 | pthread_create(&pt[a], NULL, _get_neighbours, (void *) &pars[a]); |
| 596 | } |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 597 | if(M2) { |
| 598 | for(a=0; a < syn_threads; a++) { |
| 599 | pars[a + para_threads].target_sums = target_sums; |
| 600 | pars[a + para_threads].wl = wl; |
| 601 | pars[a + para_threads].N = N; |
| 602 | pars[a + para_threads].from = a; |
| 603 | pars[a + para_threads].upto = a+1; |
| 604 | pthread_create(&pt[a + para_threads], NULL, getCollocators, (void *) &pars[a + para_threads]); |
| 605 | } |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 606 | } |
| 607 | printf("Waiting for para threads to join\n"); |
| 608 | fflush(stdout); |
| 609 | for (a = 0; a < para_threads; a++) pthread_join(pt[a], ¶_nbs[a]); |
| 610 | printf("Para threads joint\n"); |
| 611 | fflush(stdout); |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 612 | |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 613 | /* if(!syn_nbs[0]) */ |
| 614 | /* goto end; */ |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 615 | |
| 616 | for(b=0; b < N; b++) { |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 617 | besti[b] = para_nbs[0]->index[b]; |
| 618 | bestd[b] = para_nbs[0]->dist[b]; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 619 | } |
| 620 | |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 621 | for(a=1; a < para_threads; a++) { |
| 622 | for(b=0; b < para_nbs[a]->length && para_nbs[a]->index[b] >= 0; b++) { |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 623 | for(c=0; c < N; c++) { |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 624 | if(para_nbs[a]->dist[b] > bestd[c]) { |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 625 | for(d=N-1; d>c; d--) { |
| 626 | bestd[d] = bestd[d-1]; |
| 627 | besti[d] = besti[d-1]; |
| 628 | } |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 629 | besti[c] = para_nbs[a]->index[b]; |
| 630 | bestd[c] = para_nbs[a]->dist[b]; |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 631 | break; |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 637 | AV* array = newAV(); |
| 638 | for (a = 0; a < N; a++) { |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 639 | HV* hash = newHV(); |
Marc Kupietz | 50485ba | 2016-03-23 09:13:14 +0100 | [diff] [blame] | 640 | SV* word = newSVpvf(&vocab[besti[a] * max_w], 0); |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 641 | if(latin_enc == 0) SvUTF8_on(word); |
| 642 | hv_store(hash, "word", strlen("word"), word , 0); |
| 643 | hv_store(hash, "dist", strlen("dist"), newSVnv(bestd[a]), 0); |
| 644 | hv_store(hash, "rank", strlen("rank"), newSVuv(besti[a]), 0); |
| 645 | AV *vector = newAV(); |
| 646 | for (b = 0; b < size; b++) { |
| 647 | av_push(vector, newSVnv(M[b + besti[a] * size])); |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 648 | } |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 649 | hv_store(hash, "vector", strlen("vector"), newRV_noinc((SV*)vector), 0); |
| 650 | av_push(array, newRV_noinc((SV*)hash)); |
| 651 | } |
| 652 | hv_store(result, "paradigmatic", strlen("paradigmatic"), newRV_noinc((SV*)array), 0); |
| 653 | |
Marc Kupietz | 50485ba | 2016-03-23 09:13:14 +0100 | [diff] [blame] | 654 | for(b=0; b < MAX_NEIGHBOURS; b++) { |
| 655 | besti[b] = -1L; |
| 656 | bestd[b] = 0; |
| 657 | bestn[b] = 0; |
| 658 | bestp[b] = 0; |
Marc Kupietz | 6d9a678 | 2016-03-23 17:25:25 +0100 | [diff] [blame] | 659 | bests[b] = 0; |
Marc Kupietz | 50485ba | 2016-03-23 09:13:14 +0100 | [diff] [blame] | 660 | } |
| 661 | |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 662 | if (M2) { |
| 663 | printf("Waiting for syn threads to join\n"); |
| 664 | fflush(stdout); |
| 665 | for (a = 0; a < syn_threads; a++) pthread_join(pt[a+para_threads], &syn_nbs[a]); |
| 666 | printf("syn threads joint\n"); |
| 667 | fflush(stdout); |
Marc Kupietz | 50485ba | 2016-03-23 09:13:14 +0100 | [diff] [blame] | 668 | |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 669 | for(b=0; b < syn_nbs[0]->length; b++) { |
| 670 | besti[b] = syn_nbs[0]->index[b]; |
| 671 | bestd[b] = syn_nbs[0]->dist[b]; |
| 672 | bestn[b] = syn_nbs[0]->norm[b]; |
| 673 | bestp[b] = syn_nbs[0]->pos[b]; |
| 674 | bests[b] = target_sums[syn_nbs[0]->index[b]]; |
| 675 | } |
| 676 | |
| 677 | if(sort_by != 1) { // sort by responsiveness |
| 678 | for(a=1; a < syn_threads; a++) { |
| 679 | for(b=0; b < syn_nbs[a]->length; b++) { |
| 680 | for(c=0; c < MAX_NEIGHBOURS; c++) { |
| 681 | if(syn_nbs[a]->dist[b] > bestd[c]) { |
| 682 | for(d=MAX_NEIGHBOURS-1; d>c; d--) { |
| 683 | bestd[d] = bestd[d-1]; |
| 684 | besti[d] = besti[d-1]; |
| 685 | bestn[d] = bestn[d-1]; |
| 686 | bestp[d] = bestp[d-1]; |
| 687 | } |
| 688 | besti[c] = syn_nbs[a]->index[b]; |
| 689 | bestd[c] = syn_nbs[a]->dist[b]; |
| 690 | bestn[c] = syn_nbs[a]->norm[b]; |
| 691 | bestp[c] = syn_nbs[a]->pos[b]; |
| 692 | break; |
Marc Kupietz | 6d9a678 | 2016-03-23 17:25:25 +0100 | [diff] [blame] | 693 | } |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | } |
| 697 | } else { // sort by mean p |
| 698 | for(a=1; a < syn_threads; a++) { |
| 699 | for(b=0; b < syn_nbs[a]->length; b++) { |
| 700 | for(c=0; c < MAX_NEIGHBOURS; c++) { |
| 701 | if(target_sums[syn_nbs[a]->index[b]] > bests[c]) { |
| 702 | for(d=MAX_NEIGHBOURS-1; d>c; d--) { |
| 703 | bestd[d] = bestd[d-1]; |
| 704 | besti[d] = besti[d-1]; |
| 705 | bestn[d] = bestn[d-1]; |
| 706 | bestp[d] = bestp[d-1]; |
| 707 | bests[d] = bests[d-1]; |
| 708 | } |
| 709 | besti[c] = syn_nbs[a]->index[b]; |
| 710 | bestd[c] = syn_nbs[a]->dist[b]; |
| 711 | bestn[c] = syn_nbs[a]->norm[b]; |
| 712 | bestp[c] = syn_nbs[a]->pos[b]; |
| 713 | bests[c] = target_sums[syn_nbs[a]->index[b]]; |
| 714 | break; |
| 715 | } |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 716 | } |
Marc Kupietz | 6d9a678 | 2016-03-23 17:25:25 +0100 | [diff] [blame] | 717 | } |
| 718 | } |
| 719 | } |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 720 | array = newAV(); |
| 721 | for (a = 0; a < MAX_NEIGHBOURS && besti[a] >= 0; a++) { |
| 722 | HV* hash = newHV(); |
| 723 | SV* word = newSVpvf(&vocab[besti[a] * max_w], 0); |
| 724 | if(latin_enc == 0) SvUTF8_on(word); |
| 725 | hv_store(hash, "word", strlen("word"), word , 0); |
| 726 | hv_store(hash, "dist", strlen("dist"), newSVnv(bestd[a]), 0); |
| 727 | hv_store(hash, "norm", strlen("norm"), newSVnv(bestn[a]), 0); |
| 728 | hv_store(hash, "sum", strlen("sum"), newSVnv(target_sums[besti[a]]), 0); |
| 729 | hv_store(hash, "pos", strlen("pos"), newSVnv(bestp[a]), 0); |
| 730 | av_push(array, newRV_noinc((SV*)hash)); |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 731 | } |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 732 | hv_store(result, "syntagmatic", strlen("syntagmatic"), newRV_noinc((SV*)array), 0); |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 733 | } |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 734 | end: |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 735 | return newRV_noinc((SV*)result); |
Marc Kupietz | 000ad86 | 2016-02-26 14:59:12 +0100 | [diff] [blame] | 736 | } |
Marc Kupietz | 7bc85fd | 2016-02-24 11:42:41 +0100 | [diff] [blame] | 737 | |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 738 | int dump_vecs(char *fname) { |
| 739 | long i, j; |
| 740 | FILE *f; |
| 741 | /* if(words>200000) */ |
| 742 | /* words=200000; */ |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 743 | |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 744 | if((f=fopen(fname, "w")) == NULL) { |
| 745 | fprintf(stderr, "cannot open %s for writing\n", fname); |
| 746 | return(-1); |
| 747 | } |
| 748 | fprintf(f, "%lld %lld\n", words, size); |
| 749 | for (i=0; i < words; i++) { |
| 750 | fprintf(f, "%s ", &vocab[i * max_w]); |
| 751 | for(j=0; j < size - 1; j++) |
| 752 | fprintf(f, "%f ", M[i*size + j]); |
| 753 | fprintf(f, "%f\n", M[i*size + j]); |
| 754 | } |
| 755 | fclose(f); |
| 756 | return(0); |
| 757 | } |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 758 | __DATA__ |
| 759 | |
| 760 | @@ index.html.ep |
| 761 | <!DOCTYPE html> |
| 762 | <html> |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 763 | <head> |
| 764 | <title>DeReKo-Word-Vector-Distances</title> |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 765 | <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] | 766 | <script src="http://code.jquery.com/jquery-latest.min.js"></script> |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 767 | <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> |
| 768 | <script> |
| 769 | $(function() { |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 770 | $( document ).tooltip({ |
| 771 | content: function() { |
| 772 | return $(this).attr('title'); |
| 773 | }} |
| 774 | ) |
| 775 | }) |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 776 | </script> |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 777 | <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> |
| 778 | <script src="http://klinux10/word2vec/tsne.js"></script> |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 779 | <script src="http://klinux10/word2vec/som.js"></script> |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 780 | <script src="http://klinux10/word2vec/labeler.js"></script> |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 781 | <style> |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 782 | body, input { |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 783 | font-family: Arial, sans-serif; |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 784 | font-size: 11pt; |
| 785 | } |
| 786 | |
| 787 | .ui-tooltip-content { |
| 788 | font-size: 9pt; |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 789 | color: #222222; |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 790 | } |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 791 | |
| 792 | svg > .ui-tooltip-content { |
Marc Kupietz | b102936 | 2016-02-27 21:38:55 +0100 | [diff] [blame] | 793 | font-size: 8pt; |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 794 | color: #222222; |
| 795 | } |
| 796 | |
| 797 | a.merged { |
| 798 | color: green; |
| 799 | fill: green; |
| 800 | } |
| 801 | |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 802 | #first a { |
| 803 | text-decoration: none; |
| 804 | } |
| 805 | |
Marc Kupietz | 5c3887d | 2016-04-28 08:53:35 +0200 | [diff] [blame^] | 806 | a.marked, #first a.marked { |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 807 | text-decoration: underline; |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | a.target { |
| 811 | color: red; |
| 812 | fill: red; |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 813 | } |
| 814 | |
Marc Kupietz | 6b2975c | 2016-03-18 21:59:33 +0100 | [diff] [blame] | 815 | #collocators { |
| 816 | margin-bottom: 15px; |
| 817 | } |
| 818 | |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 819 | #wrapper { |
| 820 | width: 100%; |
| 821 | // border: 1px solid red; |
| 822 | overflow: hidden; /* will contain if #first is longer than #second */ |
| 823 | } |
| 824 | #first { |
Marc Kupietz | b102936 | 2016-02-27 21:38:55 +0100 | [diff] [blame] | 825 | margin-right: 20px; |
| 826 | float: left; |
| 827 | // border: 1px solid green; |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 828 | } |
| 829 | #second { |
| 830 | border: 1px solid #333; |
| 831 | overflow: hidden; /* if you don't want #second to wrap below #first */ |
| 832 | } |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 833 | #som2 svg { |
| 834 | border: 1px solid #333; |
| 835 | } |
| 836 | |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 837 | #cost { |
Marc Kupietz | b102936 | 2016-02-27 21:38:55 +0100 | [diff] [blame] | 838 | font-size: 8pt; |
| 839 | color: #222222; |
| 840 | margin-top: 4px; |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 841 | margin-bottom: 12px; |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 842 | } |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 843 | |
Marc Kupietz | 6c1ca44 | 2016-03-03 09:35:18 +0100 | [diff] [blame] | 844 | #sominfo1, #sominfo { |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 845 | font-size: 8pt; |
| 846 | color: #222222; |
| 847 | margin-top: 0px; |
| 848 | } |
| 849 | |
Marc Kupietz | 6c1ca44 | 2016-03-03 09:35:18 +0100 | [diff] [blame] | 850 | #somcolor1, #somcolor2, #somcolor3 { |
| 851 | display: inline-block; |
| 852 | height: 10px; |
| 853 | width: 10px; |
| 854 | } |
| 855 | |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 856 | #third { |
| 857 | border: 1px solid #333; |
| 858 | } |
| 859 | |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 860 | </style> |
| 861 | <script> |
| 862 | |
Marc Kupietz | c4d62f8 | 2016-03-01 11:04:24 +0100 | [diff] [blame] | 863 | var opt = {epsilon: <%= $epsilon %>, perplexity: <%= $perplexity %>}, |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 864 | mapWidth = 800, // width map |
| 865 | mapHeight = 800, |
| 866 | jitterRadius = 7; |
| 867 | |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 868 | var T = new tsnejs.tSNE(opt); // create a tSNE instance |
| 869 | |
| 870 | var Y; |
| 871 | |
| 872 | var data; |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 873 | var labeler; |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 874 | |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 875 | |
| 876 | function applyJitter() { |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 877 | svg.selectAll('.tsnet') |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 878 | .data(labels) |
| 879 | .transition() |
| 880 | .duration(50) |
| 881 | .attr("transform", function(d, i) { |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 882 | T.Y[i][0] = (d.x - mapWidth/2 - tx)/ss/20; |
| 883 | T.Y[i][1] = (d.y - mapHeight/2 - ty)/ss/20; |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 884 | return "translate(" + |
| 885 | (d.x) + "," + |
| 886 | (d.y) + ")"; |
| 887 | }); |
| 888 | } |
| 889 | |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 890 | function updateEmbedding() { |
| 891 | var Y = T.getSolution(); |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 892 | svg.selectAll('.tsnet') |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 893 | .data(data.words) |
| 894 | .attr("transform", function(d, i) { |
| 895 | return "translate(" + |
| 896 | ((Y[i][0]*20*ss + tx) + mapWidth/2) + "," + |
| 897 | ((Y[i][1]*20*ss + ty) + mapHeight/2) + ")"; }); |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | var svg; |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 901 | var labels = []; |
| 902 | var anchor_array = []; |
| 903 | var text; |
| 904 | |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 905 | function drawEmbedding() { |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 906 | $("#embed").empty(); |
| 907 | var div = d3.select("#embed"); |
| 908 | |
| 909 | // get min and max in each column of Y |
| 910 | var Y = T.Y; |
| 911 | |
| 912 | svg = div.append("svg") // svg is global |
| 913 | .attr("width", mapWidth) |
| 914 | .attr("height", mapHeight); |
| 915 | |
| 916 | var g = svg.selectAll(".b") |
| 917 | .data(data.words) |
| 918 | .enter().append("g") |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 919 | .attr("class", "tsnet"); |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 920 | |
| 921 | g.append("a") |
| 922 | .attr("xlink:href", function(word) {return "/?word="+word;}) |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 923 | .attr("class", function(d, i) { |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 924 | var res=""; |
| 925 | if(data.marked[i]) { |
| 926 | res="marked "; |
| 927 | } |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 928 | if(data.target.indexOf(" "+d+" ") >= 0) { |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 929 | return res+"target"; |
| 930 | } else if(data.ranks[i] < data.mergedEnd) { |
| 931 | return res+"merged"; |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 932 | } else { |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 933 | return res; |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 934 | } |
| 935 | }) |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 936 | .attr("title", function(d, i) { |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 937 | if(data.mergedEnd > 0) { |
| 938 | if(data.ranks[i] >= data.mergedEnd) { |
| 939 | return "rank: "+i +" "+"freq. rank: "+(data.ranks[i]).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); |
| 940 | } else { |
| 941 | return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " (merged vocab)"; |
| 942 | } |
| 943 | } else { |
| 944 | return "rank: "+i +" "+"freq. rank: "+data.ranks[i].toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); |
| 945 | } |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 946 | }) |
Marc Kupietz | a350bce | 2016-02-25 09:34:25 +0100 | [diff] [blame] | 947 | .append("text") |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 948 | .attr("text-anchor", "top") |
| 949 | .attr("font-size", 12) |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 950 | .text(function(d) { return d; }); |
| 951 | |
| 952 | var zoomListener = d3.behavior.zoom() |
| 953 | .scaleExtent([0.1, 10]) |
| 954 | .center([0,0]) |
| 955 | .on("zoom", zoomHandler); |
| 956 | zoomListener(svg); |
| 957 | } |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 958 | |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 959 | var tx=0, ty=0; |
| 960 | var ss=1; |
| 961 | var iter_id=-1; |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 962 | |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 963 | function zoomHandler() { |
| 964 | tx = d3.event.translate[0]; |
| 965 | ty = d3.event.translate[1]; |
| 966 | ss = d3.event.scale; |
| 967 | updateEmbedding(); |
| 968 | } |
| 969 | |
| 970 | var stepnum = 0; |
| 971 | |
| 972 | function stopStep() { |
| 973 | clearInterval(iter_id); |
| 974 | text = svg.selectAll("text"); |
| 975 | |
| 976 | // jitter function needs different data and co-ordinate representation |
| 977 | labels = d3.range(data.words.length).map(function(i) { |
| 978 | var x = (T.Y[i][0]*20*ss + tx) + mapWidth/2; |
| 979 | var y = (T.Y[i][1]*20*ss + ty) + mapHeight/2; |
| 980 | anchor_array.push({x: x, y: y, r: jitterRadius}); |
| 981 | return { |
| 982 | x: x, |
| 983 | y: y, |
| 984 | name: data.words[i] |
| 985 | }; |
| 986 | }); |
| 987 | |
| 988 | // get the actual label bounding boxes for the jitter function |
| 989 | var index = 0; |
| 990 | text.each(function() { |
| 991 | labels[index].width = this.getBBox().width; |
| 992 | labels[index].height = this.getBBox().height; |
| 993 | index += 1; |
| 994 | }); |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 995 | |
| 996 | |
| 997 | // setTimeout(updateEmbedding, 1); |
| 998 | // setTimeout( |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 999 | labeler = d3.labeler() |
| 1000 | .label(labels) |
| 1001 | .anchor(anchor_array) |
| 1002 | .width(mapWidth) |
| 1003 | .height(mapHeight) |
| 1004 | .update(applyJitter); |
| 1005 | // .start(1000); |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 1006 | |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 1007 | iter_id = setInterval(jitterStep, 1); |
| 1008 | } |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 1009 | |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 1010 | var jitter_i=0; |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 1011 | |
| 1012 | function jitterStep() { |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 1013 | if(jitter_i++ > 100) { |
| 1014 | clearInterval(iter_id); |
| 1015 | } else { |
| 1016 | labeler.start2(10); |
| 1017 | applyJitter(); |
| 1018 | } |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 1019 | } |
Marc Kupietz | b102936 | 2016-02-27 21:38:55 +0100 | [diff] [blame] | 1020 | |
| 1021 | var last_cost=1000; |
| 1022 | |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 1023 | function step() { |
| 1024 | var i = T.iter; |
| 1025 | |
| 1026 | if(i > <%= $no_iterations %>) { |
| 1027 | stopStep(); |
| 1028 | } else { |
| 1029 | var cost = Math.round(T.step() * 100000) / 100000; // do a few steps |
| 1030 | $("#cost").html("tsne iteration " + i + ", cost: " + cost.toFixed(5)); |
| 1031 | if(i % 250 == 0 && cost >= last_cost) { |
| 1032 | stopStep(); |
| 1033 | } else { |
| 1034 | last_cost = cost; |
| 1035 | updateEmbedding(); |
| 1036 | } |
| 1037 | } |
| 1038 | } |
Marc Kupietz | c5990da | 2016-02-26 08:47:12 +0100 | [diff] [blame] | 1039 | |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 1040 | function showMap(j) { |
| 1041 | data=j; |
| 1042 | T.iter=0; |
| 1043 | T.initDataRaw(data.vecs); // init embedding |
| 1044 | drawEmbedding(); // draw initial embedding |
| 1045 | |
| 1046 | if(iter_id >= 0) { |
| 1047 | clearInterval(iter_id); |
| 1048 | } |
| 1049 | //T.debugGrad(); |
| 1050 | iter_id = setInterval(step, 1); |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 1051 | if(<%= $show_som %>) { |
| 1052 | makeSOM(j, <%= $no_iterations %>); |
| 1053 | } |
Marc Kupietz | 9fca173 | 2016-02-29 09:07:04 +0100 | [diff] [blame] | 1054 | } |
Marc Kupietz | a350bce | 2016-02-25 09:34:25 +0100 | [diff] [blame] | 1055 | |
Marc Kupietz | c489336 | 2016-02-25 08:04:46 +0100 | [diff] [blame] | 1056 | </script> |
| 1057 | </head> |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 1058 | <body> |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 1059 | <form action="<%=url_for('/')->to_abs%>" method="GET"> |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 1060 | word(s): |
| 1061 | <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."> |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 1062 | % if($mergedEnd > 0) { |
| 1063 | backw. <input type="checkbox" name="sbf" value="1" <%= ($searchBaseVocabFirst ? "checked" : "") %> title="If checkecked base vocabulary will be searched first. Otherwise merged vocabulray will be searched first."> |
| 1064 | % } |
Marc Kupietz | 44bee3c | 2016-02-25 16:26:29 +0100 | [diff] [blame] | 1065 | max. neighbours: <input type="text" size="8" name="n" value="<%= $no_nbs %>"> |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 1066 | max. iterations: <input type="text" name="N" size="8" value="<%= $no_iterations %>"> |
| 1067 | SOM <input type="checkbox" name="som" value="1" <%= ($show_som ? "checked" : "") %>> |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 1068 | % if($collocators) { |
Marc Kupietz | 6d9a678 | 2016-03-23 17:25:25 +0100 | [diff] [blame] | 1069 | <span> </span>sort collocators by |
| 1070 | <select name="sort"> |
| 1071 | <option value="0" <%= ($sort!=1? "selected":"") %>>responsiveness</option> |
| 1072 | <option value="1" <%= ($sort==1? "selected":"") %>>mean p</option> |
| 1073 | </select> |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 1074 | % } |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 1075 | <span> </span><input type="submit" value="Show"> |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 1076 | </form> |
| 1077 | <br> |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 1078 | % if($lists) { |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 1079 | <div id="wrapper"> |
| 1080 | <table id="first"> |
| 1081 | <tr> |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 1082 | <th align="right">#</th><th align="right">cos</th><th align="left">paradigmatic</th> |
| 1083 | % if($collocators) { |
| 1084 | <th title="Position in winodw around target word. Absolute value can be too low because of sub-sampling frequent words.">@</th><th align="right" title=""Responsivenes" of the collocator at the relative position @. Approximation of the probability that the combination of the target word and the collocator at the relative position @ come from the corpus.">resp.</th><th title="Probability of the collocator at window location @."align="right">p(c<sub><small>@</small></sub>)</th><th align="right">Σp(c<sub><small>@</small></sub>)/|w|</th><th align="left">syntagmatic</th> |
| 1085 | % } |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 1086 | </tr> |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 1087 | % my $j=0; my @words; my @vecs; my @ranks; my @marked; for my $list (@$lists) { |
Marc Kupietz | c47b390 | 2016-04-22 10:29:44 +0200 | [diff] [blame] | 1088 | % my $i=0; while($list) { |
Marc Kupietz | 50485ba | 2016-03-23 09:13:14 +0100 | [diff] [blame] | 1089 | % my $item = (@$list)[$i]; |
Marc Kupietz | 43ee87e | 2016-04-25 10:50:08 +0200 | [diff] [blame] | 1090 | % my $c = ($collocators? (@$collocators)[$i] : 0); |
Marc Kupietz | 50485ba | 2016-03-23 09:13:14 +0100 | [diff] [blame] | 1091 | % last if(!$c && !$item); |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 1092 | <tr> |
| 1093 | <td align="right"> |
Marc Kupietz | d564258 | 2016-03-19 22:23:13 +0100 | [diff] [blame] | 1094 | <%= ++$i %>. |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 1095 | </td> |
Marc Kupietz | 50485ba | 2016-03-23 09:13:14 +0100 | [diff] [blame] | 1096 | % if($item) { |
| 1097 | % if(!grep{$_ eq $item->{word}} @words) { |
| 1098 | % push @vecs, $item->{vector}; |
| 1099 | % push @words, $item->{word}; |
| 1100 | % push @ranks, $item->{rank}; |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 1101 | % push @marked, ($marked->{$item->{word}}? 1 : 0); |
Marc Kupietz | 50485ba | 2016-03-23 09:13:14 +0100 | [diff] [blame] | 1102 | % } |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 1103 | <td align="right"> |
| 1104 | <%= sprintf("%.3f", $item->{dist}) %> |
| 1105 | </td> |
Marc Kupietz | d564258 | 2016-03-19 22:23:13 +0100 | [diff] [blame] | 1106 | <td> |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 1107 | % my $class = ($marked->{$item->{word}}? "marked " : ""); |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 1108 | % my $r = $item->{rank}; |
| 1109 | % if($r < $mergedEnd) { |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 1110 | % $class .= "merged"; |
Marc Kupietz | a2e6450 | 2016-04-27 09:53:51 +0200 | [diff] [blame] | 1111 | % $r .= " (merged vocab)"; |
| 1112 | % } elsif($mergedEnd!=0 && $r > $mergedEnd) { |
| 1113 | % $r -= $mergedEnd; |
| 1114 | % } |
| 1115 | <a class="<%= $class %>" title="freq. rank: <%= $r %>" href="/?word=<%= $item->{word} %>"><%= $item->{word} %></a> |
Marc Kupietz | d564258 | 2016-03-19 22:23:13 +0100 | [diff] [blame] | 1116 | </td> |
Marc Kupietz | 50485ba | 2016-03-23 09:13:14 +0100 | [diff] [blame] | 1117 | % } else { |
| 1118 | <td colspan="2"/> |
| 1119 | % } |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 1120 | % if($c) { |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 1121 | <td align="right"> |
Marc Kupietz | d564258 | 2016-03-19 22:23:13 +0100 | [diff] [blame] | 1122 | <%= $c->{pos} %>: |
| 1123 | </td> |
| 1124 | <td align="right"> |
| 1125 | <%= sprintf("%.3f", $c->{dist}) %> |
| 1126 | </td> |
Marc Kupietz | b864ccf | 2016-03-21 22:40:03 +0100 | [diff] [blame] | 1127 | <td align="right"> |
| 1128 | <%= sprintf("%.3e", $c->{norm}) %> |
| 1129 | </td> |
Marc Kupietz | ce3d4c6 | 2016-03-23 16:11:25 +0100 | [diff] [blame] | 1130 | <td align="right"> |
| 1131 | <%= sprintf("%.3e", $c->{sum}) %> |
| 1132 | </td> |
Marc Kupietz | d564258 | 2016-03-19 22:23:13 +0100 | [diff] [blame] | 1133 | <td align="left"> |
| 1134 | <a href="/?word=<%= $c->{word} %>"> |
| 1135 | <%= $c->{word} %> |
Marc Kupietz | 5f78067 | 2016-02-25 17:15:54 +0100 | [diff] [blame] | 1136 | </td> |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 1137 | % } else { |
Marc Kupietz | ce3d4c6 | 2016-03-23 16:11:25 +0100 | [diff] [blame] | 1138 | <td colspan="5"/> |
Marc Kupietz | 271e2a4 | 2016-03-22 11:37:43 +0100 | [diff] [blame] | 1139 | % } |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 1140 | </tr> |
| 1141 | % } |
Marc Kupietz | 7b2cbeb | 2016-02-25 11:22:00 +0100 | [diff] [blame] | 1142 | % } |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 1143 | </table> |
| 1144 | <script> |
| 1145 | % use Mojo::ByteStream 'b'; |
| 1146 | $(window).load(function() { |
Marc Kupietz | 6ed8187 | 2016-04-27 14:04:04 +0200 | [diff] [blame] | 1147 | showMap(<%= b(Mojo::JSON::to_json({target => " $word ", mergedEnd=> $mergedEnd, words => \@words, vecs => \@vecs, ranks => \@ranks, marked => \@marked})); %>); |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 1148 | }); |
| 1149 | </script> |
| 1150 | % } |
| 1151 | <div id="second" style="width:800px; height:800px; font-family: arial;"> |
| 1152 | <div id="embed"> |
| 1153 | </div> |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 1154 | </div> |
Marc Kupietz | b102936 | 2016-02-27 21:38:55 +0100 | [diff] [blame] | 1155 | <div id="cost"></div> |
Marc Kupietz | d7aea72 | 2016-03-02 11:59:12 +0100 | [diff] [blame] | 1156 | % if($show_som) { |
| 1157 | <div id="som2"> |
| 1158 | </div> |
Marc Kupietz | 6c1ca44 | 2016-03-03 09:35:18 +0100 | [diff] [blame] | 1159 | <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] | 1160 | <div id="sominfo">SOM iteration <span id="iterations">0</span></div> |
| 1161 | % } |
Marc Kupietz | 4aa6217 | 2016-02-25 10:39:27 +0100 | [diff] [blame] | 1162 | </div> |
Marc Kupietz | 793413b | 2016-04-02 21:48:57 +0200 | [diff] [blame] | 1163 | % if($training_args) { |
| 1164 | <p> |
| 1165 | Word vector model trained with <a href="https://code.google.com/p/word2vec/">word2vec</a> using the following parameters: <pre><%= $training_args %></pre> |
| 1166 | </p> |
| 1167 | % } |
| 1168 | </body> |
Marc Kupietz | dc22b98 | 2015-10-09 09:19:34 +0200 | [diff] [blame] | 1169 | </html> |
| 1170 | |