diff --git a/lib/IDS/DeReKoVecs/Read.pm b/lib/IDS/DeReKoVecs/Read.pm
new file mode 100644
index 0000000..d76ddf0
--- /dev/null
+++ b/lib/IDS/DeReKoVecs/Read.pm
@@ -0,0 +1,93 @@
+use utf8;
+package IDS::DeReKoVecs::Read;
+use strict;
+use warnings;
+use Config;
+
+my $src_file      = undef;
+
+our $mergedEnd=0;
+our %cache;
+our %cccache; # classic collocator cache
+our %spcache; # similar profile cache
+our $opt_p = 5676;
+our $opt_C;
+
+BEGIN {
+  $src_file = __FILE__;
+  $src_file =~ s/Read.pm/derekovecs-server.c/;
+}
+
+use Inline C => "$src_file" => CLEAN_AFTER_BUILD => 0, BUILD_NOISY => 1, ccflags =>  $Config{ccflags} . "-Wall -fno-rtti -O4 -I/usr/local/kl/include", libs => "-L/usr/local/kl/lib64 -l:libcollocatordb.so.1.3.0";
+#use Inline C => Config => BUILD_NOISY => 1, CFLAGS => $Config{cflags}." -O4 -mtune k9";
+#use Inline C => Config => CLEAN_AFTER_BUILD => 0, ccflags => $Config{ccflags}." -Ofast -march k8 -mtune k8 ";
+
+use Mojo::JSON qw(decode_json encode_json to_json);
+use Exporter qw(import);
+
+our @EXPORT = qw(init_net load_sprofiles getCollocationAssociation getClassicCollocatorsCached getClassicCollocatorsCached getBiggestMergedDifferences filter_garbage get_neighbours);
+
+
+sub getCollocationAssociation {
+  my ($c, $word, $collocate) = @_;
+  return getCollocationScores($word, $collocate)
+}
+
+sub getClassicCollocatorsCached {
+  my ($c, $word) = @_;
+  my $s2 = "";
+  if($word > $mergedEnd) {
+    $word-=$mergedEnd;
+  }
+
+  if($opt_p >= 5000 && $opt_p < 5600) { # German non-reference
+      open PIPE, "GET http://corpora.ids-mannheim.de/openlab/derekovecs/getClassicCollocators?w=$word  |";
+  }
+  if($opt_C || !$cccache{$word}) {
+    $c->app->log->info("Getting classic collocates of $word.");
+    $cccache{$word} = getClassicCollocators($word);
+    $cccache{$word} =~ s/:(-?)(nan|inf)/:"${1}${2}"/g;
+  } else {
+    $c->app->log->info("Getting classic collocates for $word from cache.");
+  }
+  if($opt_p >= 5000 && $opt_p < 5600) { # German non-reference
+    while(<PIPE>) {
+      $s2 .= $_;
+    }
+    close(PIPE);
+  }
+
+  if(length($s2) > 2000) {
+    my $d1 = decode_json($cccache{$word});
+    my $d2 = decode_json($s2);
+    my %d2ld;
+    my $minLd = 14;
+    foreach my $i (@{$d2->{collocates}}) {
+      $d2ld{$i->{word}}=$i->{ld};
+      $minLd=$i->{ld} if($i->{ld} < $minLd);
+    }
+    foreach my $i (@{$d1->{collocates}}) {
+      my $w = $i->{word};
+      $i->{delta} = $i->{ld} - (defined $d2ld{$w} ? $d2ld{$w} : $minLd-0.1);
+    }
+    return(encode_json($d1));
+  } else {
+    my $d1 = decode_json($cccache{$word});
+    foreach my $i (@{$d1->{collocates}}) {
+      $i->{delta} = 0;
+    }
+    return(encode_json($d1));
+  }
+}
+
+sub getSimilarProfilesCached {
+  my ($c, $word) = @_;
+  if(!$spcache{$word}) {
+    $spcache{$word} = getSimilarProfiles($word);
+  } else {
+    $c->app->log->info("Getting similar profiles for $word from cache:");
+  }
+  return $spcache{$word};
+}
+
+return 1;
diff --git a/lib/IDS/DeReKoVecs/derekovecs-server.c b/lib/IDS/DeReKoVecs/derekovecs-server.c
new file mode 100644
index 0000000..b2cdb20
--- /dev/null
+++ b/lib/IDS/DeReKoVecs/derekovecs-server.c
@@ -0,0 +1,1187 @@
+#include <collocatordb.h>
+#include <malloc.h>
+#include <math.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+
+#define max_size 2000
+#define max_w 50
+#define MAX_NEIGHBOURS 1000
+#define MAX_WORDS -1
+#define MAX_THREADS 100
+#define MAX_CC 50
+#define EXP_TABLE_SIZE 1000
+#define MAX_EXP 6
+#define MIN_RESP 0.50
+
+//the thread function
+void *connection_handler(void *);
+
+typedef struct {
+  long long wordi;
+  long position;
+  float activation;
+  float average;
+  float cprobability;  // column wise probability
+  float cprobability_sum;
+  float probability;
+  float activation_sum;
+  float max_activation;
+  float heat[16];
+} collocator;
+
+typedef struct {
+  collocator *best;
+  int length;
+} knn;
+
+typedef struct {
+  long long wordi[MAX_NEIGHBOURS];
+  char sep[MAX_NEIGHBOURS];
+  int length;
+} wordlist;
+
+typedef struct {
+  long cutoff;
+  wordlist *wl;
+  char *token;
+  int N;
+  long from;
+  unsigned long upto;
+  collocator *best;
+  float *target_sums;
+  float *window_sums;
+  float threshold;
+} knnpars;
+
+typedef struct {
+  uint32_t index;
+  float value;
+} sparse_t;
+
+typedef struct {
+  uint32_t len;
+  sparse_t nbr[100];
+} profile_t;
+
+float *M, *M2 = 0L, *syn1neg_window, *expTable;
+float *window_sums;
+char *vocab;
+char *garbage = NULL;
+COLLOCATORDB *cdb = NULL;
+profile_t *sprofiles = NULL;
+size_t sprofiles_qty = 0;
+
+long long words, size, merged_end;
+long long merge_words = 0;
+int num_threads = 20;
+int latin_enc = 0;
+int window;
+
+/* load collocation profiles if file exists */
+int load_sprofiles(char *vecsname) {
+  char *basename = strdup(vecsname);
+  char *pos = strstr(basename, ".vecs");
+  if (pos)
+    *pos = 0;
+
+  char binsprofiles_fname[256];
+  strcpy(binsprofiles_fname, basename);
+  strcat(binsprofiles_fname, ".sprofiles.bin");
+  FILE *fp = fopen(binsprofiles_fname, "rb");
+  if (fp == NULL) {
+    printf("Collocation profiles %s not found. No problem.\n", binsprofiles_fname);
+    return 0;
+  }
+  fseek(fp, 0L, SEEK_END);
+  size_t sz = ftell(fp);
+  fclose(fp);
+
+  int fd = open(binsprofiles_fname, O_RDONLY);
+  sprofiles = mmap(0, sz, PROT_READ, MAP_SHARED, fd, 0);
+  if (sprofiles == MAP_FAILED) {
+    close(fd);
+    fprintf(stderr, "Cannot mmap %s\n", binsprofiles_fname);
+    sprofiles = NULL;
+    return 0;
+  } else {
+    sprofiles_qty = sz / sizeof(profile_t);
+    fprintf(stderr, "Successfully mmaped %s containing similar profiles for %ld word forms.\n", binsprofiles_fname, sprofiles_qty);
+  }
+  return 1;
+}
+
+char *removeExtension(char* myStr) {
+    char *retStr;
+    char *lastExt;
+    if (myStr == NULL) return NULL;
+    if ((retStr = malloc (strlen (myStr) + 1)) == NULL) return NULL;
+    strcpy (retStr, myStr);
+    lastExt = strrchr (retStr, '.');
+    if (lastExt != NULL)
+        *lastExt = '\0';
+    return retStr;
+}
+
+int init_net(char *file_name, char *net_name, int latin, int do_open_cdb) {
+  FILE *f, *binvecs, *binwords;
+  int binwords_fd, binvecs_fd, net_fd, i;
+  long long a, b;
+  float len;
+  double val;
+
+  char binvecs_fname[1024], binwords_fname[1024];
+
+  if (strstr(file_name, ".txt")) {
+    strcpy(binwords_fname, removeExtension(file_name));
+  } else {
+    strcpy(binwords_fname, file_name);
+  }
+  strcat(binwords_fname, ".words");
+  strcpy(binvecs_fname, file_name);
+  strcat(binvecs_fname, ".vecs");
+
+  latin_enc = latin;
+  f = fopen(file_name, "rb");
+  if (f == NULL) {
+    printf("Input file %s not found\n", file_name);
+    return -1;
+  }
+  fscanf(f, "%lld", &words);
+  if (MAX_WORDS > 0 && words > MAX_WORDS) words = MAX_WORDS;
+  fscanf(f, "%lld", &size);
+  if ((binvecs_fd = open(binvecs_fname, O_RDONLY)) < 0 || (binwords_fd = open(binwords_fname, O_RDONLY)) < 0) {
+    printf("Converting %s to memory mappable structures\n", file_name);
+    vocab = (char *)malloc((long long)words * max_w * sizeof(char));
+    M = (float *)malloc((long long)words * (long long)size * sizeof(float));
+    if (M == NULL) {
+      printf("Cannot allocate memory: %lld MB    %lld  %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size);
+      return -1;
+    }
+    if (strstr(file_name, ".txt")) {
+      printf("%lld words in ascii vector file with vector size %lld\n", words, size);
+      for (b = 0; b < words; b++) {
+        a = 0;
+        while (1) {
+          vocab[b * max_w + a] = fgetc(f);
+          if (feof(f) || (vocab[b * max_w + a] == ' ')) break;
+          if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++;
+        }
+        vocab[b * max_w + a] = 0;
+        len = 0;
+        for (a = 0; a < size; a++) {
+          fscanf(f, "%lf", &val);
+          M[a + b * size] = val;
+          len += val * val;
+        }
+        len = sqrt(len);
+        for (a = 0; a < size; a++) M[a + b * size] /= len;
+      }
+    } else {
+      for (b = 0; b < words; b++) {
+        a = 0;
+        while (1) {
+          vocab[b * max_w + a] = fgetc(f);
+          if (feof(f) || (vocab[b * max_w + a] == ' ')) break;
+          if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++;
+        }
+        vocab[b * max_w + a] = 0;
+        fread(&M[b * size], sizeof(float), size, f);
+        len = 0;
+        for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size];
+        len = sqrt(len);
+        for (a = 0; a < size; a++) M[a + b * size] /= len;
+      }
+    }
+    if ((binvecs = fopen(binvecs_fname, "wb")) != NULL && (binwords = fopen(binwords_fname, "wb")) != NULL) {
+      fwrite(M, sizeof(float), (long long)words * (long long)size, binvecs);
+      fclose(binvecs);
+      fwrite(vocab, sizeof(char), (long long)words * max_w, binwords);
+      fclose(binwords);
+    }
+  }
+  if ((binvecs_fd = open(binvecs_fname, O_RDONLY)) >= 0 && (binwords_fd = open(binwords_fname, O_RDONLY)) >= 0) {
+    M = mmap(0, sizeof(float) * (long long)words * (long long)size, PROT_READ, MAP_SHARED, binvecs_fd, 0);
+    vocab = mmap(0, sizeof(char) * (long long)words * max_w, PROT_READ, MAP_SHARED, binwords_fd, 0);
+    if (M == MAP_FAILED || vocab == MAP_FAILED) {
+      close(binvecs_fd);
+      close(binwords_fd);
+      fprintf(stderr, "Cannot mmap %s or %s\n", binwords_fname, binvecs_fname);
+      exit(-1);
+    }
+  } else {
+    fprintf(stderr, "Cannot open %s or %s\n", binwords_fname, binvecs_fname);
+    exit(-1);
+  }
+  fclose(f);
+
+  if (net_name && strlen(net_name) > 0) {
+    if ((net_fd = open(net_name, O_RDONLY)) >= 0) {
+      window = (lseek(net_fd, 0, SEEK_END) - sizeof(float) * words * size) / words / size / sizeof(float) / 2;
+      //      lseek(net_fd, sizeof(float) * words * size, SEEK_SET);
+      // munmap(M,  sizeof(float) * words * size);
+      M2 = mmap(0, sizeof(float) * words * size + sizeof(float) * 2 * window * size * words, PROT_READ, MAP_SHARED, net_fd, 0);
+      if (M2 == MAP_FAILED) {
+        close(net_fd);
+        fprintf(stderr, "Cannot mmap %s\n", net_name);
+        exit(-1);
+      }
+      syn1neg_window = M2 + words * size;
+    } else {
+      fprintf(stderr, "Cannot open %s\n", net_name);
+      exit(-1);
+    }
+    fprintf(stderr, "Successfully memmaped %s. Determined window size: %d\n", net_name, window);
+
+    if (do_open_cdb) {
+      char collocatordb_name[2048];
+      strcpy(collocatordb_name, net_name);
+      char *ext = rindex(collocatordb_name, '.');
+      if (ext) {
+        strcpy(ext, ".rocksdb");
+        if (access(collocatordb_name, R_OK) == 0) {
+          *ext = 0;
+          fprintf(stderr, "Opening collocator DB	%s\n", collocatordb_name);
+          cdb = open_collocatordb(collocatordb_name);
+        } else {
+           fprintf(stderr, "Cannot open collocator DB	%s\n", collocatordb_name);
+        }
+      }
+    }
+  }
+
+  expTable = (float *)malloc((EXP_TABLE_SIZE + 1) * sizeof(float));
+  for (i = 0; i < EXP_TABLE_SIZE; i++) {
+    expTable[i] = exp((i / (float)EXP_TABLE_SIZE * 2 - 1) * MAX_EXP);  // Precompute the exp() table
+    expTable[i] = expTable[i] / (expTable[i] + 1);                     // Precompute f(x) = x / (x + 1)
+  }
+  window_sums = malloc(sizeof(float) * (window + 1) * 2);
+
+  return 0;
+}
+
+long mergeVectors(char *file_name) {
+  FILE *f;
+  int binwords_fd, binvecs_fd;
+  float *merge_vecs;
+  char *merge_vocab;
+  /*  long long merge_words, merge_size; */
+  long long merge_size;
+
+  char binvecs_fname[256], binwords_fname[256];
+
+
+  strcpy(binwords_fname, file_name);
+  strcat(binwords_fname, ".words");
+  strcpy(binvecs_fname, file_name);
+  strcat(binvecs_fname, ".vecs");
+
+  f = fopen(file_name, "rb");
+  if (f == NULL) {
+    printf("Input file %s not found\n", file_name);
+    exit(-1);
+  }
+  fscanf(f, "%lld", &merge_words);
+  fscanf(f, "%lld", &merge_size);
+  if (merge_size != size) {
+    fprintf(stderr, "vectors must have the same length\n");
+    exit(-1);
+  }
+  if ((binvecs_fd = open(binvecs_fname, O_RDONLY)) >= 0 && (binwords_fd = open(binwords_fname, O_RDONLY)) >= 0) {
+    merge_vecs = malloc(sizeof(float) * (words + merge_words) * size);
+    merge_vocab = malloc(sizeof(char) * (words + merge_words) * max_w);
+    if (merge_vecs == NULL || merge_vocab == NULL) {
+      close(binvecs_fd);
+      close(binwords_fd);
+      fprintf(stderr, "Cannot reserve memory for %s or %s\n", binwords_fname, binvecs_fname);
+      exit(-1);
+    }
+    read(binvecs_fd, merge_vecs, merge_words * size * sizeof(float));
+    read(binwords_fd, merge_vocab, merge_words * max_w);
+  } else {
+    fprintf(stderr, "Cannot open %s or %s\n", binwords_fname, binvecs_fname);
+    exit(-1);
+  }
+  printf("Successfully reallocated memory\nMerging...\n");
+  fflush(stdout);
+  memcpy(merge_vecs + merge_words * size, M, words * size * sizeof(float));
+  memcpy(merge_vocab + merge_words * max_w, vocab, words * max_w);
+  munmap(M, words * size * sizeof(float));
+  munmap(vocab, words * max_w);
+  M = merge_vecs;
+  vocab = merge_vocab;
+  merged_end = merge_words;
+  words += merge_words;
+  fclose(f);
+  printf("merged_end: %lld, words: %lld\n", merged_end, words);
+  //printBiggestMergedDifferences();
+  return ((long)merged_end);
+}
+
+void filter_garbage() {
+  long i;
+  unsigned char *w, previous, c;
+  garbage = malloc(words);
+  memset(garbage, 0, words);
+  for (i = 0; i < words; i++) {
+    w = (unsigned char *) vocab + i * max_w;
+    previous = 0;
+    if (strncmp("quot", (const char *)w, 4) == 0) {
+      garbage[i] = 1;
+      //      printf("Gargabe: %s\n", vocab + i * max_w);
+    } else {
+      while ((c = *w++) && !garbage[i]) {
+        if (((c <= 90 && c >= 65) && (previous >= 97 && previous <= 122)) ||
+            (previous == '-' && (c & 32)) ||
+            (previous == 0xc2 && (c == 0xa4 || c == 0xb6)) ||
+            (previous == 'q' && c == 'u' && *(w) == 'o' && *(w + 1) == 't') || /* quot */
+            c == '<') {
+          garbage[i] = 1;
+          continue;
+        }
+        previous = c;
+      }
+    }
+  }
+  return;
+}
+
+knn *simpleGetCollocators(int word, int number, long cutoff, int *result) {
+  knnpars *pars = calloc(sizeof(knnpars), 1);
+  float *target_sums = NULL;
+  float *my_window_sums = malloc(sizeof(float) * (window + 1) * 2);
+  pars->cutoff = (cutoff ? cutoff : 300000);
+  long a;
+  for (a = 0; a < cutoff; a++)
+    target_sums[a] = 0;
+  pars->target_sums = target_sums;
+  pars->window_sums = my_window_sums;
+  pars->N = (number ? number : 20);
+  pars->from = 0;
+  pars->upto = window * 2 - 1;
+  knn *syn_nbs = NULL;  // = (knn*) getCollocators(pars);
+  free(pars);
+  free(my_window_sums);
+  free(target_sums);
+  return syn_nbs;
+}
+
+void *getCollocators(void *args) {
+  knnpars *pars = args;
+  int N = pars->N;
+
+  int cc = pars->wl->wordi[0];
+  knn *nbs = NULL;
+  long window_layer_size = size * window * 2;
+  long a, b, c, d, window_offset, target, max_target = 0, maxmax_target;
+  float f, max_f, maxmax_f;
+  float *target_sums = NULL, worstbest, wpos_sum;
+  collocator *best;
+
+  if (M2 == NULL || cc == -1)
+    return NULL;
+
+  a = posix_memalign((void **)&target_sums, 128, pars->cutoff * sizeof(float));
+  memset(target_sums, 0, pars->cutoff * sizeof(float));
+  best = malloc((N > 200 ? N : 200) * sizeof(collocator));
+  memset(best, 0, (N > 200 ? N : 200) * sizeof(collocator));
+  worstbest = pars->threshold;
+
+  for (b = 0; b < pars->cutoff; b++)
+    target_sums[b] = 0;
+  for (b = 0; b < N; b++) {
+    best[b].wordi = -1;
+    best[b].probability = 1;
+    best[b].activation = worstbest;
+  }
+
+  d = cc;
+  maxmax_f = -1;
+  maxmax_target = 0;
+
+  for (a = pars->from; a < pars->upto; a++) {
+    if (a >= window)
+      a++;
+    wpos_sum = 0;
+    printf("window pos: %ld\n", a);
+    if (a != window) {
+      max_f = -1;
+      window_offset = a * size;
+      if (a > window)
+        window_offset -= size;
+      for (target = 0; target < pars->cutoff; target++) {
+        if (garbage && garbage[target]) continue;
+        if (target == d)
+          continue;
+        f = 0;
+        for (c = 0; c < size; c++)
+          f += M2[d * size + c] * syn1neg_window[target * window_layer_size + window_offset + c];
+        if (f < -MAX_EXP)
+          continue;
+        else if (f > MAX_EXP)
+          continue;
+        else
+          f = expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))];
+        wpos_sum += f;
+
+        target_sums[target] += f;
+        if (f > worstbest) {
+          for (b = 0; b < N; b++) {
+            if (f > best[b].activation) {
+              memmove(best + b + 1, best + b, (N - b - 1) * sizeof(collocator));
+              best[b].activation = f;
+              best[b].wordi = target;
+              best[b].position = window - a;
+              break;
+            }
+          }
+          if (b == N - 1)
+            worstbest = best[N - 1].activation;
+        }
+      }
+      printf("%ld %.2f\n", max_target, max_f);
+      printf("%s (%.2f) ", &vocab[max_target * max_w], max_f);
+      if (max_f > maxmax_f) {
+        maxmax_f = max_f;
+        maxmax_target = max_target;
+      }
+      for (b = 0; b < N; b++)
+        if (best[b].position == window - a)
+          best[b].cprobability = best[b].activation / wpos_sum;
+    } else {
+      printf("\x1b[1m%s\x1b[0m ", &vocab[d * max_w]);
+    }
+    pars->window_sums[a] = wpos_sum;
+  }
+  for (b = 0; b < pars->cutoff; b++)
+    pars->target_sums[b] += target_sums[b];  //(target_sums[b] / wpos_sum ) / (window * 2);
+
+  free(target_sums);
+  for (b = 0; b < N && best[b].wordi >= 0; b++)
+    ;
+     // THIS LOOP IS NEEDED (b...)
+     //		printf("%d: best syn: %s %.2f %.5f\n", b, &vocab[best[b].wordi*max_w], best[b].activation, best[b].probability);
+     //	printf("\n");
+  nbs = malloc(sizeof(knn));
+  nbs->best = best;
+  nbs->length = b - 1;
+  pthread_exit(nbs);
+}
+
+float getOutputWeight(int hidden, long target, int window_position) {
+  const long window_layer_size = size * window * 2;
+  int a;
+
+  if (window_position == 0 || window_position > window || window_position < -window) {
+    fprintf(stderr, "window_position: %d - assert: -%d <= window_position <= %d && window_position != 0 failed.\n", window_position, window, window);
+    exit(-1);
+  }
+
+  if (hidden >= size) {
+    fprintf(stderr, "hidden: %d - assert: hidden < %lld failed.\n", hidden, size);
+    exit(-1);
+  }
+
+  if (target >= words) {
+    fprintf(stderr, "target: %ld - assert: target < %lld failed.\n", target, words);
+    exit(-1);
+  }
+
+  a = window_position + window;
+  if (a > window) {
+    --a;
+  }
+  long window_offset = a * size;
+  return syn1neg_window[target * window_layer_size + window_offset + hidden];
+}
+
+AV *getVecs(AV *array) {
+  int i, b;
+  AV *result = newAV();
+  for (i = 0; i <= av_len(array); i++) {
+    SV **elem = av_fetch(array, i, 0);
+    if (elem != NULL) {
+      long j = (long)SvNV(*elem);
+      AV *vector = newAV();
+      for (b = 0; b < size; b++) {
+        av_push(vector, newSVnv(M[b + j * size]));
+      }
+      av_push(result, newRV_noinc(vector));
+    }
+  }
+  return result;
+}
+
+char *getSimilarProfiles(long node) {
+  int i;
+  char buffer[120000];
+  char pair_buffer[2048];
+  buffer[0] = '[';
+  buffer[1] = 0;
+  if (node >= sprofiles_qty) {
+    printf("Not available in precomputed profile\n");
+    return (strdup("[{\"w\":\"not available\", \"v\":0}]\n"));
+  }
+
+  printf("******* %s ******\n", &vocab[max_w * node]);
+
+  for (i = 0; i < 100 && i < sprofiles[node].len; i++) {
+    sprintf(pair_buffer, "{\"w\":\"%s\", \"v\":%f},", &vocab[max_w * (sprofiles[node].nbr[i].index)], sprofiles[node].nbr[i].value);
+    strcat(buffer, pair_buffer);
+  }
+  buffer[strlen(buffer) - 1] = ']';
+  strcat(buffer, "\n");
+  printf("%s", buffer);
+  return (strdup(buffer));
+}
+
+char *getCollocationScores(long node, long collocate) {
+    char *res = (cdb ? strdup(get_collocation_scores_as_json(cdb, node, collocate)) : "[]");
+    return res;
+}
+
+char *getClassicCollocators(long node) {
+  char *res = (cdb ? strdup(get_collocators_as_json(cdb, node)) : "[]");
+  return res;
+}
+
+wordlist *getTargetWords(char *st1, int search_backw) {
+  wordlist *wl = malloc(sizeof(wordlist));
+  char st[100][max_size];
+  long a, b = 0, c = 0, cn = 0;
+
+  while (1) {
+    st[cn][b] = st1[c];
+    b++;
+    c++;
+    st[cn][b] = 0;
+    if (st1[c] == 0) break;
+    if (st1[c] == ' ' /*|| st1[c] == '-'*/) {
+      b = 0;
+      c++;
+    }
+  }
+  cn++;
+  for (a = 0; a < cn; a++) {
+    if (search_backw) {
+      for (b = words - 1; b >= (merge_words ? merge_words : 0) && strcmp(&vocab[b * max_w], st[a]) != 0; b--)
+        ;
+    } else {
+      for (b = 0; b < (merge_words ? merge_words : words) && strcmp(&vocab[b * max_w], st[a]) != 0; b++)
+        ;
+    }
+    if (b == words) b = -1;
+    wl->wordi[a] = b;
+    if (b == -1) {
+      fprintf(stderr, "Out of dictionary word!\n");
+      cn--;
+    } else {
+      fprintf(stderr, "Word: \"%s\"  Position in vocabulary: %lld\n", &vocab[wl->wordi[a] * max_w], wl->wordi[a]);
+    }
+  }
+  wl->length = cn;
+  return (wl);
+}
+
+long getWordNumber(char *word) {
+  wordlist *wl = getTargetWords(word, 0);
+  if(wl->length > 0)
+    return(wl->wordi[0]);
+  return(0);
+}
+
+float get_distance(long b, long c) {
+  long a;
+  float dist = 0;
+  for (a = 0; a < size; a++) dist += M[a + c * size] * M[a + b * size];
+  return dist;
+}
+
+char *getBiggestMergedDifferences() {
+  static char *result = NULL;
+  float dist;
+  long long a, c;
+  int N = 1000;
+
+  if (merged_end == 0)
+    result = "[]";
+
+  if (result != NULL)
+    return result;
+
+  printf("Looking for biggest distances between main and merged vectors ...\n");
+  collocator *best;
+  best = malloc(N * sizeof(collocator));
+  memset(best, 0, N * sizeof(collocator));
+
+  float worstbest = 1000000;
+
+  for (a = 0; a < N; a++) best[a].activation = worstbest;
+
+  for (c = 0; c < 500000; c++) {
+    if (garbage && garbage[c]) continue;
+    dist = 0;
+    for (a = 0; a < size; a++) dist += M[a + c * size] * M[a + (c + merged_end) * size];
+    if (dist < worstbest) {
+      for (a = 0; a < N; a++) {
+        if (dist < best[a].activation) {
+          memmove(best + a + 1, best + a, (N - a - 1) * sizeof(collocator));
+          best[a].activation = dist;
+          best[a].wordi = c;
+          break;
+        }
+      }
+      worstbest = best[N - 1].activation;
+    }
+  }
+
+  result = malloc(N * max_w);
+  char *p = result;
+  *p++ = '[';
+  *p = 0;
+  for (a = 0; a < N; a++) {
+    p += sprintf(p, "{\"rank\":%lld,\"word\":\"%s\",\"dist\":%.3f},", a, &vocab[best[a].wordi * max_w], 1 - best[a].activation);
+  }
+  *--p = ']';
+  return (result);
+}
+
+float cos_similarity(long b, long c) {
+  float dist = 0;
+  long a;
+  for (a = 0; a < size; a++) dist += M[b * size + a] * M[c * size + a];
+  return dist;
+}
+
+char *cos_similarity_as_json(char *w1, char *w2) {
+  wordlist *a, *b;
+  float res;
+  a = getTargetWords(w1, 0);
+  b = getTargetWords(w2, 0);
+  if (a == NULL || b == NULL || a->length != 1 || b->length != 1)
+    res = -1;
+  else
+    res = cos_similarity(a->wordi[0], b->wordi[0]);
+  fprintf(stderr, "a: %lld b: %lld res:%f\n", a->wordi[0], b->wordi[0], res);
+  char *json = malloc(16);
+  sprintf(json, "%.5f", res);
+  return json;
+}
+
+void *_get_neighbours(void *arg) {
+  knnpars *pars = arg;
+  int N = pars->N;
+  long from = pars->from;
+  unsigned long upto = pars->upto;
+  char *sep;
+  float dist, len, vec[max_size];
+  long long a, b, c, cn, *bi;
+  knn *nbs = NULL;
+  wordlist *wl = pars->wl;
+
+  collocator *best = pars->best;
+
+  float worstbest = -1;
+
+  for (a = 0; a < N; a++) best[a].activation = 0;
+  a = 0;
+  bi = wl->wordi;
+  cn = wl->length;
+  sep = wl->sep;
+  b = bi[0];
+  if (b == -1) {
+    goto end;
+  }
+  for (a = 0; a < size; a++) vec[a] = 0;
+  for (b = 0; b < cn; b++) {
+    if (bi[b] == -1) continue;
+    if (b > 0 && sep[b - 1] == '-')
+      for (a = 0; a < size; a++) vec[a] -= M[a + bi[b] * size];
+    else
+      for (a = 0; a < size; a++) vec[a] += M[a + bi[b] * size];
+  }
+  len = 0;
+  for (a = 0; a < size; a++) len += vec[a] * vec[a];
+  len = sqrt(len);
+  for (a = 0; a < size; a++) vec[a] /= len;
+  for (a = 0; a < N; a++) best[a].activation = -1;
+  for (c = from; c < upto; c++) {
+    if (garbage && garbage[c]) continue;
+    a = 0;
+    // do not skip taget word
+    //		for (b = 0; b < cn; b++) if (bi[b] == c) a = 1;
+    //		if (a == 1) continue;
+    dist = 0;
+    for (a = 0; a < size; a++) dist += vec[a] * M[a + c * size];
+    if (dist > worstbest) {
+      for (a = 0; a < N; a++) {
+        if (dist > best[a].activation) {
+          memmove(best + a + 1, best + a, (N - a - 1) * sizeof(collocator));
+          best[a].activation = dist;
+          best[a].wordi = c;
+          break;
+        }
+      }
+      worstbest = best[N - 1].activation;
+    }
+  }
+
+end:
+  pthread_exit(nbs);
+}
+
+int cmp_activation(const void *a, const void *b) {
+  float fb = ((collocator *)a)->activation;
+  float fa = ((collocator *)b)->activation;
+  return (fa > fb) - (fa < fb);
+}
+
+int cmp_probability(const void *a, const void *b) {
+  float fb = ((collocator *)a)->probability;
+  float fa = ((collocator *)b)->probability;
+  return (fa > fb) - (fa < fb);
+}
+
+char *getPosWiseW2VCollocatorsAsTsv(char *word, long maxPerPos, long cutoff, float threshold) {
+  HV *result = newHV();
+  float *target_sums = NULL;
+  long a, b;
+  knn *para_nbs[MAX_THREADS];
+  knn *syn_nbs[MAX_THREADS];
+  knnpars pars[MAX_THREADS];
+  pthread_t *pt = (pthread_t *)malloc((num_threads + 1) * sizeof(pthread_t));
+  wordlist *wl;
+  int syn_threads = (M2 ? window * 2 : 0);
+  int search_backw = 0;
+  collocator *best = NULL;
+  posix_memalign((void **)&best, 128, 10 * (maxPerPos >= 200 ? maxPerPos : 200) * sizeof(collocator));
+  memset(best, 0, (maxPerPos >= 200 ? maxPerPos : 200) * sizeof(collocator));
+
+  if (cutoff < 1 || cutoff > words)
+    cutoff = words;
+
+  wl = getTargetWords(word, search_backw);
+  if (wl == NULL || wl->length < 1)
+    return "";
+
+  a = posix_memalign((void **)&target_sums, 128, cutoff * sizeof(float));
+  memset(target_sums, 0, cutoff * sizeof(float));
+
+  printf("Starting %d threads\n", syn_threads);
+  fflush(stdout);
+  for (a = 0; a < syn_threads; a++) {
+    pars[a].cutoff = cutoff;
+    pars[a].target_sums = target_sums;
+    pars[a].window_sums = window_sums;
+    pars[a].wl = wl;
+    pars[a].N = maxPerPos;
+    pars[a].threshold = threshold;
+    pars[a].from = a;
+    pars[a].upto = a + 1;
+    pthread_create(&pt[a], NULL, getCollocators, (void *)&pars[a]);
+  }
+  printf("Waiting for syn threads to join\n");
+  fflush(stdout);
+  for (a = 0; a < syn_threads; a++) pthread_join(pt[a], (void *)&syn_nbs[a]);
+  printf("Syn threads joint\n");
+  fflush(stdout);
+  result = malloc(maxPerPos * 80 * syn_threads);
+  char *p = result;
+  *p = 0;
+  for (a = syn_threads - 1; a >= 0; a--) {
+    for (b = 0; b < syn_nbs[a]->length; b++) {
+      p += sprintf(p, "%ld\t%s\t%f\n", syn_nbs[a]->best[b].position, &vocab[syn_nbs[a]->best[b].wordi * max_w], syn_nbs[a]->best[b].activation);
+    }
+  }
+  return (result);
+}
+
+SV *get_neighbours(char *st1, int N, int sort_by, int search_backw, long cutoff, int dedupe, int no_similar_profiles) {
+  HV *result = newHV();
+  float *target_sums = NULL;
+  long a, b, c, d, slice;
+  knn *para_nbs[MAX_THREADS];
+  knn *syn_nbs[MAX_THREADS];
+  knnpars pars[MAX_THREADS];
+  pthread_t *pt = (pthread_t *)malloc((num_threads + 1) * sizeof(pthread_t));
+  wordlist *wl;
+  int syn_threads = (M2 ? window * 2 : 0);
+  int para_threads = (no_similar_profiles ? 0 : num_threads - syn_threads);
+
+  collocator *best = NULL;
+  posix_memalign((void **)&best, 128, 10 * (N >= 200 ? N : 200) * sizeof(collocator));
+  memset(best, 0, (N >= 200 ? N : 200) * sizeof(collocator));
+
+  if (N > MAX_NEIGHBOURS) N = MAX_NEIGHBOURS;
+
+  if (cutoff < 1 || cutoff > words)
+    cutoff = words;
+
+  wl = getTargetWords(st1, search_backw);
+  if (wl == NULL || wl->length < 1)
+    goto end;
+
+  slice = cutoff / para_threads;
+
+  a = posix_memalign((void **)&target_sums, 128, cutoff * sizeof(float));
+  memset(target_sums, 0, cutoff * sizeof(float));
+
+  printf("Starting %d threads for paradigmatic search\n", para_threads);
+  fflush(stdout);
+  for (a = 0; a < para_threads; a++) {
+    pars[a].cutoff = cutoff;
+    pars[a].token = st1;
+    pars[a].wl = wl;
+    pars[a].N = N;
+    pars[a].best = &best[N * a];
+    if (merge_words == 0 || search_backw == 0) {
+      pars[a].from = a * slice;
+      pars[a].upto = ((a + 1) * slice > cutoff ? cutoff : (a + 1) * slice);
+    } else {
+      pars[a].from = merge_words + a * slice;
+      pars[a].upto = merge_words + ((a + 1) * slice > cutoff ? cutoff : (a + 1) * slice);
+    }
+    printf("From: %ld, Upto: %ld\n", pars[a].from, pars[a].upto);
+    pthread_create(&pt[a], NULL, _get_neighbours, (void *)&pars[a]);
+  }
+  if (M2) {
+    for (a = 0; a < syn_threads; a++) {
+      pars[a + para_threads].cutoff = cutoff;
+      pars[a + para_threads].target_sums = target_sums;
+      pars[a + para_threads].window_sums = window_sums;
+      pars[a + para_threads].wl = wl;
+      pars[a + para_threads].N = N;
+      pars[a + para_threads].threshold = MIN_RESP;
+      pars[a + para_threads].from = a;
+      pars[a + para_threads].upto = a + 1;
+      pthread_create(&pt[a + para_threads], NULL, getCollocators, (void *)&pars[a + para_threads]);
+    }
+  }
+  printf("Waiting for para threads to join\n");
+  fflush(stdout);
+  for (a = 0; a < para_threads; a++) pthread_join(pt[a], (void *)&para_nbs[a]);
+  printf("Para threads joint\n");
+  fflush(stdout);
+
+  /* if(!syn_nbs[0]) */
+  /* 	goto end; */
+
+  qsort(best, N * para_threads, sizeof(collocator), cmp_activation);
+
+  long long chosen[MAX_NEIGHBOURS];
+  printf("N: %d\n", N);
+
+  AV *array = newAV();
+  int i, j;
+  int l1_words = 0, l2_words = 0;
+
+  for (a = 0, i = 0; i < N && a < N * para_threads; a++) {
+    int filtered = 0;
+    long long c = best[a].wordi;
+    if ((merge_words && dedupe && i > 1) || (!merge_words && dedupe && i > 0)) {
+      for (j = 0; j < i && !filtered; j++)
+        if (strcasestr(&vocab[c * max_w], &vocab[chosen[j] * max_w]) ||
+            strcasestr(&vocab[chosen[j] * max_w], &vocab[c * max_w])) {
+          printf("filtering %s %s\n", &vocab[chosen[j] * max_w], &vocab[c * max_w]);
+          filtered = 1;
+        }
+      if (filtered)
+        continue;
+    }
+
+    if (0 && merge_words > 0) {
+      if (c >= merge_words) {
+        if (l1_words > N / 2)
+          continue;
+        else
+          l1_words++;
+      } else {
+        if (l2_words > N / 2)
+          continue;
+        else
+          l2_words++;
+      }
+    }
+
+    //    printf("%s l1:%d l2:%d i:%d a:%ld\n", &vocab[c * max_w], l1_words, l2_words, i, a);
+    //    fflush(stdout);
+    HV *hash = newHV();
+    SV *word = newSVpvf(&vocab[c * max_w], 0);
+    chosen[i] = c;
+    if (latin_enc == 0) SvUTF8_on(word);
+    fflush(stdout);
+    hv_store(hash, "word", strlen("word"), word, 0);
+    hv_store(hash, "dist", strlen("dist"), newSVnv(best[a].activation), 0);
+    hv_store(hash, "rank", strlen("rank"), newSVuv(best[a].wordi), 0);
+    AV *vector = newAV();
+    for (b = 0; b < size; b++) {
+      av_push(vector, newSVnv(M[b + best[a].wordi * size]));
+    }
+    hv_store(hash, "vector", strlen("vector"), newRV_noinc((SV *)vector), 0);
+    av_push(array, newRV_noinc((SV *)hash));
+    i++;
+  }
+  hv_store(result, "paradigmatic", strlen("paradigmatic"), newRV_noinc((SV *)array), 0);
+
+  for (b = 0; b < MAX_NEIGHBOURS; b++) {
+    best[b].wordi = -1L;
+    best[b].activation = 0;
+    best[b].probability = 0;
+    best[b].position = 0;
+    best[b].activation_sum = 0;
+    memset(best[b].heat, 0, sizeof(float) * 16);
+  }
+
+  float total_activation = 0;
+
+  if (M2) {
+    printf("Waiting for syn threads to join\n");
+    fflush(stdout);
+    for (a = 0; a < syn_threads; a++) pthread_join(pt[a + para_threads], (void *)&syn_nbs[a]);
+    for (a = 0; a <= syn_threads; a++) {
+      if (a == window) continue;
+      total_activation += window_sums[a];
+      printf("window pos: %ld, sum: %f\n", a, window_sums[a]);
+    }
+    printf("syn threads joint\n");
+    fflush(stdout);
+
+    for (b = 0; b < syn_nbs[0]->length; b++) {
+      memcpy(best + b, &syn_nbs[0]->best[b], sizeof(collocator));
+      best[b].position = -1;  //  syn_nbs[0]->pos[b];
+      best[b].activation_sum = target_sums[syn_nbs[0]->best[b].wordi];
+      best[b].max_activation = 0.0;
+      best[b].average = 0.0;
+      best[b].probability = 0.0;
+      best[b].cprobability = syn_nbs[0]->best[b].cprobability;
+      memset(best[b].heat, 0, sizeof(float) * 16);
+    }
+
+    float best_window_sum[MAX_NEIGHBOURS];
+    int found_index = 0, i = 0, w;
+    for (a = 0; a < syn_threads; a++) {
+      for (b = 0; b < syn_nbs[a]->length; b++) {
+        for (i = 0; i < found_index; i++)
+          if (best[i].wordi == syn_nbs[a]->best[b].wordi)
+            break;
+        if (i >= found_index) {
+          best[found_index].max_activation = 0.0;
+          best[found_index].average = 0.0;
+          best[found_index].probability = 0.0;
+          memset(best[found_index].heat, 0, sizeof(float) * 16);
+          best[found_index].cprobability = syn_nbs[a]->best[b].cprobability;
+          best[found_index].activation_sum = target_sums[syn_nbs[a]->best[b].wordi];  // syn_nbs[a]->best[b].activation_sum;
+          best[found_index++].wordi = syn_nbs[a]->best[b].wordi;
+          //						printf("found: %s\n", &vocab[syn_nbs[a]->index[b] * max_w]);
+        }
+      }
+    }
+    sort_by = 0;                         // ALWAYS AUTO-FOCUS
+    if (sort_by != 1 && sort_by != 2) {  // sort by auto focus mean
+      printf("window: %d  -  syn_threads: %d, %d\n", window, syn_threads, (1 << syn_threads) - 1);
+      int wpos;
+      int bits_set = 0;
+      for (i = 0; i < found_index; i++) {
+        best[i].activation = best[i].probability = best[i].average = best[i].cprobability_sum = 0;
+        for (w = 1; w < (1 << syn_threads); w++) {  // loop through all possible windows
+          float word_window_sum = 0, word_window_average = 0, word_cprobability_sum = 0, word_activation_sum = 0, total_window_sum = 0;
+          bits_set = 0;
+          for (a = 0; a < syn_threads; a++) {
+            if ((1 << a) & w) {
+              wpos = (a >= window ? a + 1 : a);
+              total_window_sum += window_sums[wpos];
+            }
+          }
+          //					printf("%d window-sum %f\n", w, total_window_sum);
+          for (a = 0; a < syn_threads; a++) {
+            if ((1 << a) & w) {
+              wpos = (a >= window ? a + 1 : a);
+              bits_set++;
+              for (b = 0; b < syn_nbs[a]->length; b++)
+                if (best[i].wordi == syn_nbs[a]->best[b].wordi) {
+                  //									float acti = syn_nbs[a]->best[b].activation / total_window_sum;
+                  //                  word_window_sum += syn_nbs[a]->dist[b] *  syn_nbs[a]->norm[b]; // / window_sums[wpos];  // syn_nbs[a]->norm[b];
+                  //                    word_window_sum += syn_nbs[a]->norm[b]; // / window_sums[wpos];  // syn_nbs[a]->norm[b];
+                  //                  word_window_sum = (word_window_sum + syn_nbs[a]->norm[b]) - (word_window_sum * syn_nbs[a]->norm[b]);  // syn_nbs[a]->norm[b];
+
+                  word_window_sum += syn_nbs[a]->best[b].activation;  // / window_sums[wpos];  // syn_nbs[a]->norm[b];
+                                                                      //                  word_window_sum += acti - (word_window_sum * acti); syn_nbs[a]->best[b].activation; // / window_sums[wpos];  // syn_nbs[a]->norm[b];
+
+                  word_window_average += syn_nbs[a]->best[b].activation;                                                                 // - word_window_average * syn_nbs[a]->best[b].activation;  // conormalied activation sum
+                  word_cprobability_sum += syn_nbs[a]->best[b].cprobability - word_cprobability_sum * syn_nbs[a]->best[b].cprobability;  // conormalied column probability sum
+                  word_activation_sum += syn_nbs[a]->best[b].activation;
+                  if (syn_nbs[a]->best[b].activation > best[i].max_activation)
+                    best[i].max_activation = syn_nbs[a]->best[b].activation;
+                  if (syn_nbs[a]->best[b].activation > best[i].heat[wpos])
+                    best[i].heat[wpos] = syn_nbs[a]->best[b].activation;
+                }
+            }
+          }
+          if (bits_set) {
+            word_window_average /= bits_set;
+            //						word_activation_sum /= bits_set;
+            //						word_window_sum /= bits_set;
+          }
+
+          word_window_sum /= total_window_sum;
+
+          if (word_window_sum > best[i].probability) {
+            //						best[i].position = w;
+            best[i].probability = word_window_sum;
+          }
+
+          if (word_cprobability_sum > best[i].cprobability_sum) {
+            best[i].position = w;
+            best[i].cprobability_sum = word_cprobability_sum;
+          }
+
+          best[i].average = word_window_average;
+          //						best[i].activation = word_activation_sum;
+        }
+      }
+      qsort(best, found_index, sizeof(collocator), cmp_probability);
+      //      for(i=0; i < found_index; i++) {
+      //				printf("found: %s - sum: %f - window: %d\n", &vocab[best[i].wordi * max_w], best[i].activation, best[i].position);
+      //			}
+
+    } else if (sort_by == 1) {  // responsiveness any window position
+      int wpos;
+      for (i = 0; i < found_index; i++) {
+        float word_window_sum = 0, word_activation_sum = 0, total_window_sum = 0;
+        for (a = 0; a < syn_threads; a++) {
+          wpos = (a >= window ? a + 1 : a);
+          for (b = 0; b < syn_nbs[a]->length; b++)
+            if (best[i].wordi == syn_nbs[a]->best[b].wordi) {
+              best[i].probability += syn_nbs[a]->best[b].probability;
+              if (syn_nbs[a]->best[b].activation > 0.25)
+                best[i].position |= 1 << wpos;
+              if (syn_nbs[a]->best[b].activation > best[i].activation) {
+                best[i].activation = syn_nbs[a]->best[b].activation;
+              }
+            }
+        }
+      }
+      qsort(best, found_index, sizeof(collocator), cmp_activation);
+    } else if (sort_by == 2) {  // single window position
+      for (a = 1; a < syn_threads; a++) {
+        for (b = 0; b < syn_nbs[a]->length; b++) {
+          for (c = 0; c < MAX_NEIGHBOURS; c++) {
+            if (syn_nbs[a]->best[b].activation > best[c].activation) {
+              for (d = MAX_NEIGHBOURS - 1; d > c; d--) {
+                memmove(best + d, best + d - 1, sizeof(collocator));
+              }
+              memcpy(best + c, &syn_nbs[a]->best[b], sizeof(collocator));
+              best[c].position = 1 << (-syn_nbs[a]->best[b].position + window - (syn_nbs[a]->best[b].position < 0 ? 1 : 0));
+              break;
+            }
+          }
+        }
+      }
+    } else {  // sort by mean p
+      for (a = 1; a < syn_threads; a++) {
+        for (b = 0; b < syn_nbs[a]->length; b++) {
+          for (c = 0; c < MAX_NEIGHBOURS; c++) {
+            if (target_sums[syn_nbs[a]->best[b].wordi] > best[c].activation_sum) {
+              for (d = MAX_NEIGHBOURS - 1; d > c; d--) {
+                memmove(best + d, best + d - 1, sizeof(collocator));
+              }
+              memcpy(best + c, &syn_nbs[a]->best[b], sizeof(collocator));
+              best[c].position = (1 << 2 * window) - 1;  // syn_nbs[a]->pos[b];
+              best[c].activation_sum = target_sums[syn_nbs[a]->best[b].wordi];
+              break;
+            }
+          }
+        }
+      }
+    }
+    array = newAV();
+    for (a = 0, i = 0; a < MAX_NEIGHBOURS && best[a].wordi >= 0; a++) {
+      long long c = best[a].wordi;
+      /*
+      if (dedupe) {
+	  		int filtered=0;
+        for (j=0; j<i; j++)
+          if (strcasestr(&vocab[c * max_w], chosen[j]) ||
+              strcasestr(chosen[j], &vocab[c * max_w])) {
+						printf("filtering %s %s\n", chosen[j], &vocab[c * max_w]);
+						filtered = 1;
+					}
+				if(filtered)
+					continue;
+			}
+*/
+      chosen[i++] = c;
+      HV *hash = newHV();
+      SV *word = newSVpvf(&vocab[best[a].wordi * max_w], 0);
+      AV *heat = newAV();
+      if (latin_enc == 0) SvUTF8_on(word);
+      hv_store(hash, "word", strlen("word"), word, 0);
+      hv_store(hash, "rank", strlen("rank"), newSVuv(best[a].wordi), 0);
+      hv_store(hash, "average", strlen("average"), newSVnv(best[a].average), 0);
+      hv_store(hash, "prob", strlen("prob"), newSVnv(best[a].probability), 0);
+      hv_store(hash, "cprob", strlen("cprob"), newSVnv(best[a].cprobability_sum), 0);
+      hv_store(hash, "max", strlen("max"), newSVnv(best[a].max_activation), 0);                             // newSVnv(target_sums[best[a].wordi]), 0);
+      hv_store(hash, "overall", strlen("overall"), newSVnv(best[a].activation_sum / total_activation), 0);  // newSVnv(target_sums[best[a].wordi]), 0);
+      hv_store(hash, "pos", strlen("pos"), newSVnv(best[a].position), 0);
+      best[a].heat[5] = 0;
+      for (i = 10; i >= 0; i--) av_push(heat, newSVnv(best[a].heat[i]));
+      hv_store(hash, "heat", strlen("heat"), newRV_noinc((SV *)heat), 0);
+      av_push(array, newRV_noinc((SV *)hash));
+    }
+    hv_store(result, "syntagmatic", strlen("syntagmatic"), newRV_noinc((SV *)array), 0);
+  }
+end:
+  free(best);
+  return newRV_noinc((SV *)result);
+}
+
+int dump_vecs(char *fname) {
+  long i, j;
+  FILE *f;
+  /*  if(words>100000)
+	 	words=100000;
+*/
+  if ((f = fopen(fname, "w")) == NULL) {
+    fprintf(stderr, "cannot open %s for writing\n", fname);
+    return (-1);
+  }
+  fprintf(f, "%lld %lld\n", words, size);
+  for (i = 0; i < words; i++) {
+    fprintf(f, "%s ", &vocab[i * max_w]);
+    for (j = 0; j < size - 1; j++)
+      fprintf(f, "%f ", M[i * size + j]);
+    fprintf(f, "%f\n", M[i * size + j]);
+  }
+  fclose(f);
+  return (0);
+}
+
+int dump_for_numpy(char *fname) {
+  long i, j;
+  FILE *f;
+  int max = words; // 300000;
+
+  if ((f = fopen(fname, "w")) == NULL) {
+    fprintf(stderr, "cannot open %s for writing\n", fname);
+    return (-1);
+  }
+  for (i = 0; i < max; i++) {
+    for (j = 0; j < size - 1; j++)
+      fprintf(f, "%f\t", M[i * size + j]);
+    fprintf(f, "%f\n", M[i * size + j]);
+    printf("%s\r\n", &vocab[i * max_w]);
+  }
+  if (merged_end > 0) {
+    for (i = 0; i < max; i++) {
+      for (j = 0; j < size - 1; j++)
+        fprintf(f, "%f\t", M[(merged_end + i) * size + j]);
+      fprintf(f, "%f\n", M[(merged_end + i) * size + j]);
+      printf("_%s\r\n", &vocab[i * max_w]);
+    }
+  }
+  fclose(f);
+  return (0);
+}
