diff --git a/weightedWord2vec.c b/weightedWord2vec.c
new file mode 100644
index 0000000..f1d8f60
--- /dev/null
+++ b/weightedWord2vec.c
@@ -0,0 +1,1317 @@
+//  Copyright 2013 Google Inc. All Rights Reserved.
+//
+//  Licensed under the Apache License, Version 2.0 (the "License");
+//  you may not use this file except in compliance with the License.
+//  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <pthread.h>
+
+#define MAX_STRING 100
+#define EXP_TABLE_SIZE 1000
+#define MAX_EXP 6
+#define MAX_SENTENCE_LENGTH 1000
+#define MAX_CODE_LENGTH 40
+
+const int vocab_hash_size = 30000000;  // Maximum 30 * 0.7 = 21M words in the vocabulary
+
+typedef float real;                    // Precision of float numbers
+
+struct vocab_word {
+  long long cn;
+  int *point;
+  char *word, *code, codelen;
+};
+
+char train_file[MAX_STRING], output_file[MAX_STRING];
+char save_vocab_file[MAX_STRING], read_vocab_file[MAX_STRING];
+struct vocab_word *vocab;
+int binary = 0, type = 1, debug_mode = 2, window = 5, min_count = 5, num_threads = 12, min_reduce = 1;
+int *vocab_hash;
+long long vocab_max_size = 1000, vocab_size = 0, layer1_size = 100;
+long long train_words = 0, word_count_actual = 0, iter = 5, file_size = 0, classes = 0;
+real alpha = 0.025, starting_alpha, sample = 1e-3;
+real *syn0, *syn1, *syn1neg, *syn1nce, *expTable;
+clock_t start;
+
+real *syn1_window, *syn1neg_window, *syn1nce_window;
+int w_offset, window_layer_size;
+
+int window_hidden_size = 500; 
+real *syn_window_hidden, *syn_hidden_word, *syn_hidden_word_neg, *syn_hidden_word_nce; 
+
+int hs = 0, negative = 5;
+const int table_size = 1e8;
+int *table;
+
+//constrastive negative sampling
+char negative_classes_file[MAX_STRING];
+int *word_to_group;
+int *group_to_table; //group_size*table_size
+int class_number;
+
+//nce
+real* noise_distribution;
+int nce = 0;
+
+//param caps
+real CAP_VALUE = 50;
+int cap = 0;
+
+void capParam(real* array, int index){
+	if(array[index] > CAP_VALUE) 
+		array[index] = CAP_VALUE;
+	else if(array[index] < -CAP_VALUE)
+		array[index] = -CAP_VALUE; 
+}
+
+real hardTanh(real x){
+	if(x>=1){
+		return 1;
+	}
+	else if(x<=-1){
+		return -1;
+	}
+	else{
+		return x;
+	}
+}
+
+real dHardTanh(real x, real g){
+	if(x > 1 && g > 0){
+		return 0;
+	}
+	if(x < -1 && g < 0){
+		return 0;
+	}
+	return 1;
+}
+
+int isEndOfSentence(char* word){
+    return strcmp("</s>", word) == 0;
+}
+
+void InitUnigramTable() {
+  int a, i;
+  long long train_words_pow = 0;
+  real d1, power = 0.75;
+  table = (int *)malloc(table_size * sizeof(int));
+  for (a = 0; a < vocab_size; a++) train_words_pow += pow(vocab[a].cn, power);
+  i = 0;
+  d1 = pow(vocab[i].cn, power) / (real)train_words_pow;
+  for (a = 0; a < table_size; a++) {
+    table[a] = i;
+    if (a / (real)table_size > d1) {
+      i++;
+      d1 += pow(vocab[i].cn, power) / (real)train_words_pow;
+    }
+    if (i >= vocab_size) i = vocab_size - 1;
+  }
+  
+  noise_distribution = (real *)calloc(vocab_size, sizeof(real));
+  for (a = 0; a < vocab_size; a++) noise_distribution[a] = pow(vocab[a].cn, power)/(real)train_words_pow;
+}
+
+// Reads a single word from a file, assuming space + tab + EOL to be word boundaries
+void ReadWord(char *word, FILE *fin) {
+  int a = 0, ch;
+  while (!feof(fin)) {
+    ch = fgetc(fin);
+    if (ch == 13) continue;
+    if ((ch == ' ') || (ch == '\t') || (ch == '\n')) {
+      if (a > 0) {
+        if (ch == '\n') ungetc(ch, fin);
+        break;
+      }
+      if (ch == '\n') {
+        strcpy(word, (char *)"</s>");
+        return;
+      } else continue;
+    }
+    word[a] = ch;
+    a++;
+    if (a >= MAX_STRING - 1) a--;   // Truncate too long words
+  }
+  word[a] = 0;
+}
+
+// Returns hash value of a word
+int GetWordHash(char *word) {
+  unsigned long long a, hash = 0;
+  for (a = 0; a < strlen(word); a++) hash = hash * 257 + word[a];
+  hash = hash % vocab_hash_size;
+  return hash;
+}
+
+// Returns position of a word in the vocabulary; if the word is not found, returns -1
+int SearchVocab(char *word) {
+  unsigned int hash = GetWordHash(word);
+  while (1) {
+    if (vocab_hash[hash] == -1) return -1;
+    if (!strcmp(word, vocab[vocab_hash[hash]].word)) return vocab_hash[hash];
+    hash = (hash + 1) % vocab_hash_size;
+  }
+  return -1;
+}
+
+// Reads a word and returns its index in the vocabulary
+int ReadWordIndex(FILE *fin) {
+  char word[MAX_STRING];
+  ReadWord(word, fin);
+  if (feof(fin)) return -1;
+  return SearchVocab(word);
+}
+
+// Adds a word to the vocabulary
+int AddWordToVocab(char *word) {
+  unsigned int hash, length = strlen(word) + 1;
+  if (length > MAX_STRING) length = MAX_STRING;
+  vocab[vocab_size].word = (char *)calloc(length, sizeof(char));
+  strcpy(vocab[vocab_size].word, word);
+  vocab[vocab_size].cn = 0;
+  vocab_size++;
+  // Reallocate memory if needed
+  if (vocab_size + 2 >= vocab_max_size) {
+    vocab_max_size += 1000;
+    vocab = (struct vocab_word *)realloc(vocab, vocab_max_size * sizeof(struct vocab_word));
+  }
+  hash = GetWordHash(word);
+  while (vocab_hash[hash] != -1) hash = (hash + 1) % vocab_hash_size;
+  vocab_hash[hash] = vocab_size - 1;
+  return vocab_size - 1;
+}
+
+// Used later for sorting by word counts
+int VocabCompare(const void *a, const void *b) {
+    return ((struct vocab_word *)b)->cn - ((struct vocab_word *)a)->cn;
+}
+
+// Sorts the vocabulary by frequency using word counts
+void SortVocab() {
+  int a, size;
+  unsigned int hash;
+  // Sort the vocabulary and keep </s> at the first position
+  qsort(&vocab[1], vocab_size - 1, sizeof(struct vocab_word), VocabCompare);
+  for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1;
+  size = vocab_size;
+  train_words = 0;
+  for (a = 0; a < size; a++) {
+    // Words occuring less than min_count times will be discarded from the vocab
+    if ((vocab[a].cn < min_count) && (a != 0)) {
+      vocab_size--;
+      free(vocab[a].word);
+    } else {
+      // Hash will be re-computed, as after the sorting it is not actual
+      hash=GetWordHash(vocab[a].word);
+      while (vocab_hash[hash] != -1) hash = (hash + 1) % vocab_hash_size;
+      vocab_hash[hash] = a;
+      train_words += vocab[a].cn;
+    }
+  }
+  vocab = (struct vocab_word *)realloc(vocab, (vocab_size + 1) * sizeof(struct vocab_word));
+  // Allocate memory for the binary tree construction
+  for (a = 0; a < vocab_size; a++) {
+    vocab[a].code = (char *)calloc(MAX_CODE_LENGTH, sizeof(char));
+    vocab[a].point = (int *)calloc(MAX_CODE_LENGTH, sizeof(int));
+  }
+}
+
+// Reduces the vocabulary by removing infrequent tokens
+void ReduceVocab() {
+  int a, b = 0;
+  unsigned int hash;
+  for (a = 0; a < vocab_size; a++) if (vocab[a].cn > min_reduce) {
+    vocab[b].cn = vocab[a].cn;
+    vocab[b].word = vocab[a].word;
+    b++;
+  } else free(vocab[a].word);
+  vocab_size = b;
+  for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1;
+  for (a = 0; a < vocab_size; a++) {
+    // Hash will be re-computed, as it is not actual
+    hash = GetWordHash(vocab[a].word);
+    while (vocab_hash[hash] != -1) hash = (hash + 1) % vocab_hash_size;
+    vocab_hash[hash] = a;
+  }
+  fflush(stdout);
+  min_reduce++;
+}
+
+// Create binary Huffman tree using the word counts
+// Frequent words will have short uniqe binary codes
+void CreateBinaryTree() {
+  long long a, b, i, min1i, min2i, pos1, pos2, point[MAX_CODE_LENGTH];
+  char code[MAX_CODE_LENGTH];
+  long long *count = (long long *)calloc(vocab_size * 2 + 1, sizeof(long long));
+  long long *binary = (long long *)calloc(vocab_size * 2 + 1, sizeof(long long));
+  long long *parent_node = (long long *)calloc(vocab_size * 2 + 1, sizeof(long long));
+  for (a = 0; a < vocab_size; a++) count[a] = vocab[a].cn;
+  for (a = vocab_size; a < vocab_size * 2; a++) count[a] = 1e15;
+  pos1 = vocab_size - 1;
+  pos2 = vocab_size;
+  // Following algorithm constructs the Huffman tree by adding one node at a time
+  for (a = 0; a < vocab_size - 1; a++) {
+    // First, find two smallest nodes 'min1, min2'
+    if (pos1 >= 0) {
+      if (count[pos1] < count[pos2]) {
+        min1i = pos1;
+        pos1--;
+      } else {
+        min1i = pos2;
+        pos2++;
+      }
+    } else {
+      min1i = pos2;
+      pos2++;
+    }
+    if (pos1 >= 0) {
+      if (count[pos1] < count[pos2]) {
+        min2i = pos1;
+        pos1--;
+      } else {
+        min2i = pos2;
+        pos2++;
+      }
+    } else {
+      min2i = pos2;
+      pos2++;
+    }
+    count[vocab_size + a] = count[min1i] + count[min2i];
+    parent_node[min1i] = vocab_size + a;
+    parent_node[min2i] = vocab_size + a;
+    binary[min2i] = 1;
+  }
+  // Now assign binary code to each vocabulary word
+  for (a = 0; a < vocab_size; a++) {
+    b = a;
+    i = 0;
+    while (1) {
+      code[i] = binary[b];
+      point[i] = b;
+      i++;
+      b = parent_node[b];
+      if (b == vocab_size * 2 - 2) break;
+    }
+    vocab[a].codelen = i;
+    vocab[a].point[0] = vocab_size - 2;
+    for (b = 0; b < i; b++) {
+      vocab[a].code[i - b - 1] = code[b];
+      vocab[a].point[i - b] = point[b] - vocab_size;
+    }
+  }
+  free(count);
+  free(binary);
+  free(parent_node);
+}
+
+void LearnVocabFromTrainFile() {
+  char word[MAX_STRING];
+  FILE *fin;
+  long long a, i;
+  for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1;
+  fin = fopen(train_file, "rb");
+  if (fin == NULL) {
+    printf("ERROR: training data file not found!\n");
+    exit(1);
+  }
+  vocab_size = 0;
+  AddWordToVocab((char *)"</s>");
+  int startOfLine = 1;
+  while (1) {
+    ReadWord(word, fin);
+    if (feof(fin)) break;
+    if (startOfLine) {
+      ReadWord(word, fin);
+      startOfLine = 0;
+    }
+    if(isEndOfSentence(word)){
+      startOfLine = 1;
+    }
+    train_words++;
+    if ((debug_mode > 1) && (train_words % 100000 == 0)) {
+      printf("%lldK%c", train_words / 1000, 13);
+      fflush(stdout);
+    }
+    i = SearchVocab(word);
+    if (i == -1) {
+      a = AddWordToVocab(word);
+      vocab[a].cn = 1;
+    } else vocab[i].cn++;
+    if (vocab_size > vocab_hash_size * 0.7) ReduceVocab();
+  }
+  SortVocab();
+  if (debug_mode > 0) {
+    printf("Vocab size: %lld\n", vocab_size);
+    printf("Words in train file: %lld\n", train_words);
+  }
+  file_size = ftell(fin);
+  fclose(fin);
+}
+
+void SaveVocab() {
+  long long i;
+  FILE *fo = fopen(save_vocab_file, "wb");
+  for (i = 0; i < vocab_size; i++) fprintf(fo, "%s %lld\n", vocab[i].word, vocab[i].cn);
+  fclose(fo);
+}
+
+void ReadVocab() {
+  long long a, i = 0;
+  char c;
+  char word[MAX_STRING];
+  FILE *fin = fopen(read_vocab_file, "rb");
+  if (fin == NULL) {
+    printf("Vocabulary file not found\n");
+    exit(1);
+  }
+  for (a = 0; a < vocab_hash_size; a++) vocab_hash[a] = -1;
+  vocab_size = 0;
+  while (1) {
+    ReadWord(word, fin);
+    if (feof(fin)) break;
+    a = AddWordToVocab(word);
+    fscanf(fin, "%lld%c", &vocab[a].cn, &c);
+    i++;
+  }
+  SortVocab();
+  if (debug_mode > 0) {
+    printf("Vocab size: %lld\n", vocab_size);
+    printf("Words in train file: %lld\n", train_words);
+  }
+  fin = fopen(train_file, "rb");
+  if (fin == NULL) {
+    printf("ERROR: training data file not found!\n");
+    exit(1);
+  }
+  fseek(fin, 0, SEEK_END);
+  file_size = ftell(fin);
+  fclose(fin);
+}
+
+void InitClassUnigramTable() {
+  long long a,c;
+  printf("loading class unigrams \n");
+  FILE *fin = fopen(negative_classes_file, "rb");
+  if (fin == NULL) {
+    printf("ERROR: class file not found!\n");
+    exit(1);
+  }
+  word_to_group = (int *)malloc(vocab_size * sizeof(int));
+  for(a = 0; a < vocab_size; a++) word_to_group[a] = -1;
+  char class[MAX_STRING];
+  char prev_class[MAX_STRING];
+  prev_class[0] = 0;
+  char word[MAX_STRING];
+  class_number = -1;
+  while (1) {
+    if (feof(fin)) break;
+    ReadWord(class, fin);
+    ReadWord(word, fin);
+    int word_index = SearchVocab(word);
+    if (word_index != -1){
+       if(strcmp(class, prev_class) != 0){
+	    class_number++;
+	    strcpy(prev_class, class);
+       }
+       word_to_group[word_index] = class_number;
+    }
+    ReadWord(word, fin);
+  }
+  class_number++;
+  fclose(fin);
+  
+  group_to_table = (int *)malloc(table_size * class_number * sizeof(int)); 
+  long long train_words_pow = 0;
+  real d1, power = 0.75;
+  
+  for(c = 0; c < class_number; c++){
+     long long offset = c * table_size;
+     train_words_pow = 0;
+     for (a = 0; a < vocab_size; a++) if(word_to_group[a] == c) train_words_pow += pow(vocab[a].cn, power);
+     int i = 0;
+     while(word_to_group[i]!=c && i < vocab_size) i++;
+     d1 = pow(vocab[i].cn, power) / (real)train_words_pow;
+     for (a = 0; a < table_size; a++) {
+	//printf("index %lld , word %d\n", a, i);
+	group_to_table[offset + a] = i;
+        if (a / (real)table_size > d1) {
+	   i++;
+           while(word_to_group[i]!=c && i < vocab_size) i++;
+	   d1 += pow(vocab[i].cn, power) / (real)train_words_pow;
+        }
+        if (i >= vocab_size) while(word_to_group[i]!=c && i >= 0) i--;
+     }
+  }
+}
+
+void InitNet() {
+  long long a, b;
+  unsigned long long next_random = 1;
+  window_layer_size = layer1_size*window*2;
+  a = posix_memalign((void **)&syn0, 128, (long long)vocab_size * layer1_size * sizeof(real));
+  if (syn0 == NULL) {printf("Memory allocation failed\n"); exit(1);}
+  
+  if (hs) {
+    a = posix_memalign((void **)&syn1, 128, (long long)vocab_size * layer1_size * sizeof(real));
+    if (syn1 == NULL) {printf("Memory allocation failed\n"); exit(1);}
+    a = posix_memalign((void **)&syn1_window, 128, (long long)vocab_size * window_layer_size * sizeof(real));
+    if (syn1_window == NULL) {printf("Memory allocation failed\n"); exit(1);}
+    a = posix_memalign((void **)&syn_hidden_word, 128, (long long)vocab_size * window_hidden_size * sizeof(real));
+    if (syn_hidden_word == NULL) {printf("Memory allocation failed\n"); exit(1);}
+
+    for (a = 0; a < vocab_size; a++) for (b = 0; b < layer1_size; b++)
+     syn1[a * layer1_size + b] = 0;
+    for (a = 0; a < vocab_size; a++) for (b = 0; b < window_layer_size; b++)
+     syn1_window[a * window_layer_size + b] = 0;
+    for (a = 0; a < vocab_size; a++) for (b = 0; b < window_hidden_size; b++)
+     syn_hidden_word[a * window_hidden_size + b] = 0;
+  }
+  if (negative>0) {
+    a = posix_memalign((void **)&syn1neg, 128, (long long)vocab_size * layer1_size * sizeof(real));
+    if (syn1neg == NULL) {printf("Memory allocation failed\n"); exit(1);}
+    a = posix_memalign((void **)&syn1neg_window, 128, (long long)vocab_size * window_layer_size * sizeof(real));
+    if (syn1neg_window == NULL) {printf("Memory allocation failed\n"); exit(1);}
+    a = posix_memalign((void **)&syn_hidden_word_neg, 128, (long long)vocab_size * window_hidden_size * sizeof(real));
+    if (syn_hidden_word_neg == NULL) {printf("Memory allocation failed\n"); exit(1);}
+
+    for (a = 0; a < vocab_size; a++) for (b = 0; b < layer1_size; b++)
+     syn1neg[a * layer1_size + b] = 0;
+    for (a = 0; a < vocab_size; a++) for (b = 0; b < window_layer_size; b++)
+     syn1neg_window[a * window_layer_size + b] = 0;
+    for (a = 0; a < vocab_size; a++) for (b = 0; b < window_hidden_size; b++)
+     syn_hidden_word_neg[a * window_hidden_size + b] = 0;
+  }
+  if (nce>0) {
+    a = posix_memalign((void **)&syn1nce, 128, (long long)vocab_size * layer1_size * sizeof(real));
+    if (syn1nce == NULL) {printf("Memory allocation failed\n"); exit(1);}
+    a = posix_memalign((void **)&syn1nce_window, 128, (long long)vocab_size * window_layer_size * sizeof(real));
+    if (syn1nce_window == NULL) {printf("Memory allocation failed\n"); exit(1);}
+    a = posix_memalign((void **)&syn_hidden_word_nce, 128, (long long)vocab_size * window_hidden_size * sizeof(real));
+    if (syn_hidden_word_nce == NULL) {printf("Memory allocation failed\n"); exit(1);}
+
+    for (a = 0; a < vocab_size; a++) for (b = 0; b < layer1_size; b++)
+     syn1nce[a * layer1_size + b] = 0;
+    for (a = 0; a < vocab_size; a++) for (b = 0; b < window_layer_size; b++)
+     syn1nce_window[a * window_layer_size + b] = 0;
+    for (a = 0; a < vocab_size; a++) for (b = 0; b < window_hidden_size; b++)
+     syn_hidden_word_nce[a * window_hidden_size + b] = 0;
+  }
+  for (a = 0; a < vocab_size; a++) for (b = 0; b < layer1_size; b++) {
+    next_random = next_random * (unsigned long long)25214903917 + 11;
+    syn0[a * layer1_size + b] = (((next_random & 0xFFFF) / (real)65536) - 0.5) / layer1_size;
+  }
+
+  a = posix_memalign((void **)&syn_window_hidden, 128, window_hidden_size * window_layer_size * sizeof(real));
+  if (syn_window_hidden == NULL) {printf("Memory allocation failed\n"); exit(1);}
+  for (a = 0; a < window_hidden_size * window_layer_size; a++){
+    next_random = next_random * (unsigned long long)25214903917 + 11;
+    syn_window_hidden[a] = (((next_random & 0xFFFF) / (real)65536) - 0.5) / (window_hidden_size*window_layer_size);
+  }
+
+  CreateBinaryTree();
+}
+
+long long findStartOfLine(char* file, long long start){
+  char word[MAX_STRING];
+  if(start == 0) return 0;
+  while(start != 0){
+    FILE*fi = fopen(file, "rb");
+    fseek(fi, start, SEEK_SET);
+    ReadWord(word, fi);
+    if(isEndOfSentence(word)){
+      fclose(fi);
+      return start+1;
+    }
+    fclose(fi);
+    start--;
+  }
+  return 0;
+}
+
+void *TrainModelThread(void *id) {
+  char word_str[MAX_STRING];
+  long long a, b, d, cw, word, last_word, sentence_length = 0, sentence_position = 0;
+  long long word_count = 0, last_word_count = 0, sen[MAX_SENTENCE_LENGTH + 1];
+  long long l1, l2, c, target, label, local_iter = iter;
+  unsigned long long next_random = (long long)id;
+  real f, g;
+  clock_t now;
+  int input_len_1 = layer1_size;
+  int window_offset = -1;
+  float currentWeight = 0;
+  if(type == 2 || type == 4){
+     input_len_1=window_layer_size;
+  }
+  real *neu1 = (real *)calloc(input_len_1, sizeof(real));
+  real *neu1e = (real *)calloc(input_len_1, sizeof(real));
+
+  int input_len_2 = 0;
+  if(type == 4){
+     input_len_2 = window_hidden_size;
+  }
+  real *neu2 = (real *)calloc(input_len_2, sizeof(real));
+  real *neu2e = (real *)calloc(input_len_2, sizeof(real));
+
+  long long start_pos = findStartOfLine(train_file, file_size / (long long)num_threads * (long long)id);
+  FILE *fi = fopen(train_file, "rb");
+  fseek(fi, start_pos, SEEK_SET);
+  int startOfSentence = 1;
+  int startEndOfLineIndex = SearchVocab("</s>");
+  while (1) {
+    if (word_count - last_word_count > 10000) {
+      word_count_actual += word_count - last_word_count;
+      last_word_count = word_count;
+      if ((debug_mode > 1)) {
+        now=clock();
+        printf("%cAlpha: %f Weight: %f  Progress: %.2f%%  Words/thread/sec: %.2fk  ", 13, alpha, currentWeight,
+         word_count_actual / (real)(iter * train_words + 1) * 100,
+         word_count_actual / ((real)(now - start + 1) / (real)CLOCKS_PER_SEC * 1000));
+        fflush(stdout);
+      }
+      alpha = starting_alpha * (1 - word_count_actual / (real)(iter * train_words + 1));
+      if (alpha < starting_alpha * 0.0001) alpha = starting_alpha * 0.0001;
+    }
+    if (sentence_length == 0) {
+      while (1) {
+        if(startOfSentence){
+          ReadWord(word_str, fi);
+          currentWeight = atof(word_str);
+          startOfSentence = 0;
+          continue;
+        }
+        word = ReadWordIndex(fi);
+        if (word == startEndOfLineIndex){
+          startOfSentence = 1;
+        }
+        if (feof(fi)) break;
+        if (word == -1) continue;
+        word_count++;
+        if (word == 0) break;
+        // The subsampling randomly discards frequent words while keeping the ranking same
+        if (sample > 0) {
+          real ran = (sqrt(vocab[word].cn / (sample * train_words)) + 1) * (sample * train_words) / vocab[word].cn;
+          next_random = next_random * (unsigned long long)25214903917 + 11;
+          if (ran < (next_random & 0xFFFF) / (real)65536) continue;
+        }
+        sen[sentence_length] = word;
+        sentence_length++;
+        if (sentence_length >= MAX_SENTENCE_LENGTH) break;
+      }
+      sentence_position = 0;
+    }
+    if (feof(fi) || (word_count > train_words / num_threads)) {
+      word_count_actual += word_count - last_word_count;
+      local_iter--;
+      if (local_iter == 0) break;
+      word_count = 0;
+      last_word_count = 0;
+      sentence_length = 0;
+      fseek(fi, start_pos, SEEK_SET);
+      continue;
+    }
+    word = sen[sentence_position];
+    if (word == -1) continue;
+    for (c = 0; c < input_len_1; c++) neu1[c] = 0;
+    for (c = 0; c < input_len_1; c++) neu1e[c] = 0;
+    for (c = 0; c < input_len_2; c++) neu2[c] = 0;
+    for (c = 0; c < input_len_2; c++) neu2e[c] = 0;
+    next_random = next_random * (unsigned long long)25214903917 + 11;
+    b = next_random % window;
+    if (type == 0) {  //train the cbow architecture
+      // in -> hidden
+      cw = 0;
+      for (a = b; a < window * 2 + 1 - b; a++) if (a != window) {
+        c = sentence_position - window + a;
+        if (c < 0) continue;
+        if (c >= sentence_length) continue;
+        last_word = sen[c];
+        if (last_word == -1) continue;
+        for (c = 0; c < layer1_size; c++) neu1[c] += syn0[c + last_word * layer1_size];
+        cw++;
+      }
+      if (cw) {
+        for (c = 0; c < layer1_size; c++) neu1[c] /= cw;
+        if (hs) for (d = 0; d < vocab[word].codelen; d++) {
+          f = 0;
+          l2 = vocab[word].point[d] * layer1_size;
+          // Propagate hidden -> output
+          for (c = 0; c < layer1_size; c++) f += neu1[c] * syn1[c + l2];
+          if (f <= -MAX_EXP) continue;
+          else if (f >= MAX_EXP) continue;
+          else f = expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))];
+          // 'g' is the gradient multiplied by the learning rate
+          g = (1 - vocab[word].code[d] - f) * alpha * currentWeight;
+          // Propagate errors output -> hidden
+          for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1[c + l2];
+          // Learn weights hidden -> output
+          for (c = 0; c < layer1_size; c++) syn1[c + l2] += g * neu1[c];
+	  if(cap == 1) for (c = 0; c < layer1_size; c++) capParam(syn1, c + l2);
+        }
+        // NEGATIVE SAMPLING
+        if (negative > 0) for (d = 0; d < negative + 1; d++) {
+          if (d == 0) {
+            target = word;
+            label = 1;
+          } else {
+            next_random = next_random * (unsigned long long)25214903917 + 11;
+	    if(word_to_group != NULL && word_to_group[word] != -1){
+		target = word;
+		while(target == word) {
+			target = group_to_table[word_to_group[word]*table_size + (next_random >> 16) % table_size];
+            		next_random = next_random * (unsigned long long)25214903917 + 11;
+		}
+		//printf("negative sampling %lld for word %s returned %s\n", d, vocab[word].word, vocab[target].word);
+	    }
+	    else{
+            	target = table[(next_random >> 16) % table_size];
+	    }
+            if (target == 0) target = next_random % (vocab_size - 1) + 1;
+            if (target == word) continue;
+            label = 0;
+          }
+          l2 = target * layer1_size;
+          f = 0;
+          for (c = 0; c < layer1_size; c++) f += neu1[c] * syn1neg[c + l2];
+          if (f > MAX_EXP) g = (label - 1) * alpha * currentWeight;
+          else if (f < -MAX_EXP) g = (label - 0) * alpha * currentWeight;
+          else g = (label - expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))]) * alpha * currentWeight;
+          for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1neg[c + l2];
+          for (c = 0; c < layer1_size; c++) syn1neg[c + l2] += g * neu1[c];
+	  if (cap == 1) for (c = 0; c < layer1_size; c++) capParam(syn1neg, c + l2);
+        }
+        // Noise Contrastive Estimation
+        if (nce > 0) for (d = 0; d < nce + 1; d++) {
+          if (d == 0) {
+            target = word;
+            label = 1;
+          } else {
+            next_random = next_random * (unsigned long long)25214903917 + 11;
+	    if(word_to_group != NULL && word_to_group[word] != -1){
+		target = word;
+		while(target == word) {
+			target = group_to_table[word_to_group[word]*table_size + (next_random >> 16) % table_size];
+            		next_random = next_random * (unsigned long long)25214903917 + 11;
+		}
+	    }
+	    else{
+            	target = table[(next_random >> 16) % table_size];
+	    }
+            if (target == 0) target = next_random % (vocab_size - 1) + 1;
+            if (target == word) continue;
+            label = 0;
+          }
+          l2 = target * layer1_size;
+          f = 0;
+	  
+          for (c = 0; c < layer1_size; c++) f += neu1[c] * syn1nce[c + l2];
+          if (f > MAX_EXP) g = (label - 1) * alpha * currentWeight;
+          else if (f < -MAX_EXP) g = (label - 0) * alpha * currentWeight;
+          else {
+                f = exp(f);
+                g = (label - f/(noise_distribution[target]*nce + f)) * alpha * currentWeight;
+          }
+	  for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1nce[c + l2];
+          for (c = 0; c < layer1_size; c++) syn1nce[c + l2] += g * neu1[c];
+	  if(cap == 1) for (c = 0; c < layer1_size; c++) capParam(syn1nce,c + l2);
+        }
+        // hidden -> in
+        for (a = b; a < window * 2 + 1 - b; a++) if (a != window) {
+          c = sentence_position - window + a;
+          if (c < 0) continue;
+          if (c >= sentence_length) continue;
+          last_word = sen[c];
+          if (last_word == -1) continue;
+          for (c = 0; c < layer1_size; c++) syn0[c + last_word * layer1_size] += neu1e[c];
+        }
+      }
+    } else if(type==1) {  //train skip-gram
+      for (a = b; a < window * 2 + 1 - b; a++) if (a != window) {
+        c = sentence_position - window + a;
+        if (c < 0) continue;
+        if (c >= sentence_length) continue;
+        last_word = sen[c];
+        if (last_word == -1) continue;
+        l1 = last_word * layer1_size;
+        for (c = 0; c < layer1_size; c++) neu1e[c] = 0;
+        // HIERARCHICAL SOFTMAX
+        if (hs) for (d = 0; d < vocab[word].codelen; d++) {
+          f = 0;
+          l2 = vocab[word].point[d] * layer1_size;
+          // Propagate hidden -> output
+          for (c = 0; c < layer1_size; c++) f += syn0[c + l1] * syn1[c + l2];
+          if (f <= -MAX_EXP) continue;
+          else if (f >= MAX_EXP) continue;
+          else f = expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))];
+          // 'g' is the gradient multiplied by the learning rate
+          g = (1 - vocab[word].code[d] - f) * alpha * currentWeight;
+          // Propagate errors output -> hidden
+          for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1[c + l2];
+          // Learn weights hidden -> output
+          for (c = 0; c < layer1_size; c++) syn1[c + l2] += g * syn0[c + l1];
+	  if (cap == 1) for (c = 0; c < layer1_size; c++) capParam(syn1, c + l2);
+        }
+        // NEGATIVE SAMPLING
+	if (negative > 0) for (d = 0; d < negative + 1; d++) {
+          if (d == 0) {
+            target = word;
+            label = 1;
+          } else {
+	    next_random = next_random * (unsigned long long)25214903917 + 11;
+            if(word_to_group != NULL && word_to_group[word] != -1){
+                target = word;
+                while(target == word) {
+                        target = group_to_table[word_to_group[word]*table_size + (next_random >> 16) % table_size];
+                        next_random = next_random * (unsigned long long)25214903917 + 11;
+                }
+                //printf("negative sampling %lld for word %s returned %s\n", d, vocab[word].word, vocab[target].word);
+            }
+            else{
+                target = table[(next_random >> 16) % table_size];
+            }
+            if (target == 0) target = next_random % (vocab_size - 1) + 1;
+            if (target == word) continue;
+            label = 0;
+          }
+          l2 = target * layer1_size;
+          f = 0;
+          for (c = 0; c < layer1_size; c++) f += syn0[c + l1] * syn1neg[c + l2];
+          if (f > MAX_EXP) g = (label - 1) * alpha * currentWeight;
+          else if (f < -MAX_EXP) g = (label - 0) * alpha * currentWeight;
+          else g = (label - expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))]) * alpha * currentWeight;
+          for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1neg[c + l2];
+          for (c = 0; c < layer1_size; c++) syn1neg[c + l2] += g * syn0[c + l1];
+	  if (cap == 1) for (c = 0; c < layer1_size; c++) capParam(syn1neg, c + l2);
+        }
+	//Noise Contrastive Estimation
+        if (nce > 0) for (d = 0; d < nce + 1; d++) {
+          if (d == 0) {
+            target = word;
+            label = 1;
+          } else {
+	    next_random = next_random * (unsigned long long)25214903917 + 11;
+            if(word_to_group != NULL && word_to_group[word] != -1){
+                target = word;
+                while(target == word) {
+                        target = group_to_table[word_to_group[word]*table_size + (next_random >> 16) % table_size];
+                        next_random = next_random * (unsigned long long)25214903917 + 11;
+                }
+                //printf("negative sampling %lld for word %s returned %s\n", d, vocab[word].word, vocab[target].word);
+            }
+            else{
+                target = table[(next_random >> 16) % table_size];
+            }
+            if (target == 0) target = next_random % (vocab_size - 1) + 1;
+            if (target == word) continue;
+            label = 0;
+          }
+          l2 = target * layer1_size;
+          f = 0;
+          for (c = 0; c < layer1_size; c++) f += syn0[c + l1] * syn1nce[c + l2];
+          if (f > MAX_EXP) g = (label - 1) * alpha * currentWeight;
+          else if (f < -MAX_EXP) g = (label - 0) * alpha * currentWeight;
+          else {
+                f = exp(f);
+                g = (label - f/(noise_distribution[target]*nce + f)) * alpha * currentWeight;
+          }
+          for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1nce[c + l2];
+          for (c = 0; c < layer1_size; c++) syn1nce[c + l2] += g * syn0[c + l1];
+	  if (cap == 1) for (c = 0; c < layer1_size; c++) capParam(syn1nce, c + l2);
+        }
+        // Learn weights input -> hidden
+        for (c = 0; c < layer1_size; c++) syn0[c + l1] += neu1e[c];
+      }
+    }
+    else if(type == 2){ //train the cwindow architecture
+      // in -> hidden
+      cw = 0;
+      for (a = 0; a < window * 2 + 1; a++) if (a != window) {
+        c = sentence_position - window + a;
+        if (c < 0) continue;
+        if (c >= sentence_length) continue;
+        last_word = sen[c];
+        if (last_word == -1) continue;
+        window_offset = a*layer1_size;
+        if (a > window) window_offset-=layer1_size;
+        for (c = 0; c < layer1_size; c++) neu1[c+window_offset] += syn0[c + last_word * layer1_size];
+        cw++;
+      }
+      if (cw) {
+        if (hs) for (d = 0; d < vocab[word].codelen; d++) {
+          f = 0;
+          l2 = vocab[word].point[d] * window_layer_size;
+          // Propagate hidden -> output
+          for (c = 0; c < window_layer_size; c++) f += neu1[c] * syn1_window[c + l2];
+          if (f <= -MAX_EXP) continue;
+          else if (f >= MAX_EXP) continue;
+          else f = expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))];
+          // 'g' is the gradient multiplied by the learning rate
+          g = (1 - vocab[word].code[d] - f) * alpha * currentWeight;
+          // Propagate errors output -> hidden
+          for (c = 0; c < window_layer_size; c++) neu1e[c] += g * syn1_window[c + l2];
+          // Learn weights hidden -> output
+          for (c = 0; c < window_layer_size; c++) syn1_window[c + l2] += g * neu1[c];
+	  if (cap == 1) for (c = 0; c < window_layer_size; c++) capParam(syn1_window, c + l2);
+        }
+        // NEGATIVE SAMPLING
+        if (negative > 0) for (d = 0; d < negative + 1; d++) {
+          if (d == 0) {
+            target = word;
+            label = 1;
+          } else {
+            next_random = next_random * (unsigned long long)25214903917 + 11;
+            if(word_to_group != NULL && word_to_group[word] != -1){
+                target = word;
+                while(target == word) {
+                        target = group_to_table[word_to_group[word]*table_size + (next_random >> 16) % table_size];
+                        next_random = next_random * (unsigned long long)25214903917 + 11;
+                }
+                //printf("negative sampling %lld for word %s returned %s\n", d, vocab[word].word, vocab[target].word);
+            }
+            else{
+                target = table[(next_random >> 16) % table_size];
+            }
+            if (target == 0) target = next_random % (vocab_size - 1) + 1;
+            if (target == word) continue;
+            label = 0;
+          }
+          l2 = target * window_layer_size;
+          f = 0;
+          for (c = 0; c < window_layer_size; c++) f += neu1[c] * syn1neg_window[c + l2];
+	  if (f > MAX_EXP) g = (label - 1) * alpha * currentWeight;
+          else if (f < -MAX_EXP) g = (label - 0) * alpha * currentWeight;
+          else g = (label - expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))]) * alpha * currentWeight;
+          for (c = 0; c < window_layer_size; c++) neu1e[c] += g * syn1neg_window[c + l2];
+          for (c = 0; c < window_layer_size; c++) syn1neg_window[c + l2] += g * neu1[c];
+	  if(cap == 1) for (c = 0; c < window_layer_size; c++) capParam(syn1neg_window, c + l2);
+        }
+	// Noise Contrastive Estimation
+        if (nce > 0) for (d = 0; d < nce + 1; d++) {
+          if (d == 0) {
+            target = word;
+            label = 1;
+          } else {
+            next_random = next_random * (unsigned long long)25214903917 + 11;
+            if(word_to_group != NULL && word_to_group[word] != -1){
+                target = word;
+                while(target == word) {
+                        target = group_to_table[word_to_group[word]*table_size + (next_random >> 16) % table_size];
+                        next_random = next_random * (unsigned long long)25214903917 + 11;
+                }
+                //printf("negative sampling %lld for word %s returned %s\n", d, vocab[word].word, vocab[target].word);
+            }
+            else{
+                target = table[(next_random >> 16) % table_size];
+            }
+            if (target == 0) target = next_random % (vocab_size - 1) + 1;
+            if (target == word) continue;
+            label = 0;
+          }
+          l2 = target * window_layer_size;
+          f = 0;
+          for (c = 0; c < window_layer_size; c++) f += neu1[c] * syn1nce_window[c + l2];
+	  if (f > MAX_EXP) g = (label - 1) * alpha * currentWeight;
+          else if (f < -MAX_EXP) g = (label - 0) * alpha * currentWeight;
+          else {
+                f = exp(f);
+                g = (label - f/(noise_distribution[target]*nce + f)) * alpha * currentWeight;
+          }
+          for (c = 0; c < window_layer_size; c++) neu1e[c] += g * syn1nce_window[c + l2];
+          for (c = 0; c < window_layer_size; c++) syn1nce_window[c + l2] += g * neu1[c];
+	  if(cap == 1) for (c = 0; c < window_layer_size; c++) capParam(syn1nce_window, c + l2);
+        }
+        // hidden -> in
+        for (a = 0; a < window * 2 + 1; a++) if (a != window) {
+          c = sentence_position - window + a;
+          if (c < 0) continue;
+          if (c >= sentence_length) continue;
+          last_word = sen[c];
+          if (last_word == -1) continue;
+	  window_offset = a * layer1_size;
+	  if(a > window) window_offset -= layer1_size;
+          for (c = 0; c < layer1_size; c++) syn0[c + last_word * layer1_size] += neu1e[c + window_offset];
+        }
+      }
+    }
+    else if (type == 3){  //train structured skip-gram
+      for (a = 0; a < window * 2 + 1; a++) if (a != window) {
+        c = sentence_position - window + a;
+        if (c < 0) continue;
+        if (c >= sentence_length) continue;
+        last_word = sen[c];
+        if (last_word == -1) continue;
+        l1 = last_word * layer1_size;
+	window_offset = a * layer1_size;
+	if(a > window) window_offset -= layer1_size;
+        for (c = 0; c < layer1_size; c++) neu1e[c] = 0;
+        // HIERARCHICAL SOFTMAX
+        if (hs) for (d = 0; d < vocab[word].codelen; d++) {
+          f = 0;
+          l2 = vocab[word].point[d] * window_layer_size;
+          // Propagate hidden -> output
+          for (c = 0; c < layer1_size; c++) f += syn0[c + l1] * syn1_window[c + l2 + window_offset];
+          if (f <= -MAX_EXP) continue;
+          else if (f >= MAX_EXP) continue;
+          else f = expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))];
+          // 'g' is the gradient multiplied by the learning rate
+          g = (1 - vocab[word].code[d] - f) * alpha * currentWeight;
+          // Propagate errors output -> hidden
+          for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1_window[c + l2 + window_offset];
+          // Learn weights hidden -> output
+          for (c = 0; c < layer1_size; c++) syn1[c + l2 + window_offset] += g * syn0[c + l1];
+	  if(cap == 1) for (c = 0; c < layer1_size; c++) capParam(syn1, c + l2 + window_offset);
+        }
+        // NEGATIVE SAMPLING
+        if (negative > 0) for (d = 0; d < negative + 1; d++) {
+          if (d == 0) {
+            target = word;
+            label = 1;
+          } else {
+	     next_random = next_random * (unsigned long long)25214903917 + 11;
+            if(word_to_group != NULL && word_to_group[word] != -1){
+                target = word;
+                while(target == word) {
+                        target = group_to_table[word_to_group[word]*table_size + (next_random >> 16) % table_size];
+                        next_random = next_random * (unsigned long long)25214903917 + 11;
+                }
+                //printf("negative sampling %lld for word %s returned %s\n", d, vocab[word].word, vocab[target].word);
+            }
+            else{
+                target = table[(next_random >> 16) % table_size];
+            }
+            if (target == 0) target = next_random % (vocab_size - 1) + 1;
+            if (target == word) continue;
+            label = 0;
+          }
+          l2 = target * window_layer_size;
+          f = 0;
+          for (c = 0; c < layer1_size; c++) f += syn0[c + l1] * syn1neg_window[c + l2 + window_offset];
+	  if (f > MAX_EXP) g = (label - 1) * alpha * currentWeight;
+          else if (f < -MAX_EXP) g = (label - 0) * alpha * currentWeight;
+          else g = (label - expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))]) * alpha * currentWeight;
+	  for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1neg_window[c + l2 + window_offset];
+          for (c = 0; c < layer1_size; c++) syn1neg_window[c + l2 + window_offset] += g * syn0[c + l1]; 
+	  if(cap == 1) for (c = 0; c < layer1_size; c++) capParam(syn1neg_window, c + l2 + window_offset);
+        }
+	// Noise Constrastive Estimation
+        if (nce > 0) for (d = 0; d < nce + 1; d++) {
+          if (d == 0) {
+            target = word;
+            label = 1;
+          } else {
+             next_random = next_random * (unsigned long long)25214903917 + 11;
+            if(word_to_group != NULL && word_to_group[word] != -1){
+                target = word;
+                while(target == word) {
+                        target = group_to_table[word_to_group[word]*table_size + (next_random >> 16) % table_size];
+                        next_random = next_random * (unsigned long long)25214903917 + 11;
+                }
+                //printf("negative sampling %lld for word %s returned %s\n", d, vocab[word].word, vocab[target].word);
+            }
+            else{
+                target = table[(next_random >> 16) % table_size];
+            }
+            if (target == 0) target = next_random % (vocab_size - 1) + 1;
+            if (target == word) continue;
+            label = 0;
+          }
+          l2 = target * window_layer_size;
+          f = 0;
+          for (c = 0; c < layer1_size; c++) f += syn0[c + l1] * syn1nce_window[c + l2 + window_offset];
+	  if (f > MAX_EXP) g = (label - 1) * alpha * currentWeight;
+          else if (f < -MAX_EXP) g = (label - 0) * alpha * currentWeight;
+          else {
+                f = exp(f);
+                g = (label - f/(noise_distribution[target]*nce + f)) * alpha * currentWeight;
+          }
+          for (c = 0; c < layer1_size; c++) neu1e[c] += g * syn1nce_window[c + l2 + window_offset];
+          for (c = 0; c < layer1_size; c++) syn1nce_window[c + l2 + window_offset] += g * syn0[c + l1];
+	  if (cap == 1) for (c = 0; c < layer1_size; c++) capParam(syn1nce_window, c + l2 + window_offset);
+        }
+        // Learn weights input -> hidden
+        for (c = 0; c < layer1_size; c++) {syn0[c + l1] += neu1e[c]; if(syn0[c + l1] > 50) syn0[c + l1] = 50; if(syn0[c + l1] < -50) syn0[c + l1] = -50;}
+      }
+    }
+    else if(type == 4){ //training senna
+	// in -> hidden
+      cw = 0;
+      for (a = 0; a < window * 2 + 1; a++) if (a != window) {
+        c = sentence_position - window + a;
+        if (c < 0) continue;
+        if (c >= sentence_length) continue;
+        last_word = sen[c];
+        if (last_word == -1) continue;
+        window_offset = a*layer1_size;
+        if (a > window) window_offset-=layer1_size;
+        for (c = 0; c < layer1_size; c++) neu1[c+window_offset] += syn0[c + last_word * layer1_size];
+        cw++;
+      }
+      if (cw) {
+		for (a = 0; a < window_hidden_size; a++){
+          c = a*window_layer_size;
+          for(b = 0; b < window_layer_size; b++){
+             neu2[a] += syn_window_hidden[c + b] * neu1[b];
+          }
+        }
+        if (hs) for (d = 0; d < vocab[word].codelen; d++) {
+          f = 0;
+          l2 = vocab[word].point[d] * window_hidden_size;
+          // Propagate hidden -> output
+          for (c = 0; c < window_hidden_size; c++) f += hardTanh(neu2[c]) * syn_hidden_word[c + l2];
+          if (f <= -MAX_EXP) continue;
+          else if (f >= MAX_EXP) continue;
+          else f = expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))];
+          // 'g' is the gradient multiplied by the learning rate
+          g = (1 - vocab[word].code[d] - f) * alpha * currentWeight;
+          // Propagate errors output -> hidden
+          for (c = 0; c < window_hidden_size; c++) neu2e[c] += dHardTanh(neu2[c],g) * g * syn_hidden_word[c + l2];
+          // Learn weights hidden -> output
+          for (c = 0; c < window_hidden_size; c++) syn_hidden_word[c + l2] += dHardTanh(neu2[c],g) * g * neu2[c];
+        }
+      // NEGATIVE SAMPLING
+        if (negative > 0) for (d = 0; d < negative + 1; d++) {
+          if (d == 0) {
+            target = word;
+            label = 1;
+          } else {
+	    next_random = next_random * (unsigned long long)25214903917 + 11;
+            if(word_to_group != NULL && word_to_group[word] != -1){
+                target = word;
+                while(target == word) {
+                        target = group_to_table[word_to_group[word]*table_size + (next_random >> 16) % table_size];
+                        next_random = next_random * (unsigned long long)25214903917 + 11;
+                }
+                //printf("negative sampling %lld for word %s returned %s\n", d, vocab[word].word, vocab[target].word);
+            }
+            else{
+                target = table[(next_random >> 16) % table_size];
+            }
+            if (target == 0) target = next_random % (vocab_size - 1) + 1;
+            if (target == word) continue;
+            label = 0;
+          }
+          l2 = target * window_hidden_size;
+          f = 0;
+          for (c = 0; c < window_hidden_size; c++) f += hardTanh(neu2[c]) * syn_hidden_word_neg[c + l2];
+          if (f > MAX_EXP) g = (label - 1) * alpha  * currentWeight / negative;
+          else if (f < -MAX_EXP) g = (label - 0) * alpha * currentWeight / negative;
+          else g = (label - expTable[(int)((f + MAX_EXP) * (EXP_TABLE_SIZE / MAX_EXP / 2))]) * alpha * currentWeight / negative;
+          for (c = 0; c < window_hidden_size; c++) neu2e[c] += dHardTanh(neu2[c],g) * g * syn_hidden_word_neg[c + l2];
+          for (c = 0; c < window_hidden_size; c++) syn_hidden_word_neg[c + l2] += dHardTanh(neu2[c],g) * g * neu2[c];
+        }
+        for (a = 0; a < window_hidden_size; a++)
+          for(b = 0; b < window_layer_size; b++)
+	     neu1e[b] += neu2e[a] * syn_window_hidden[a*window_layer_size + b];
+	for (a = 0; a < window_hidden_size; a++)
+          for(b = 0; b < window_layer_size; b++)
+	     syn_window_hidden[a*window_layer_size + b] += neu2e[a] * neu1[b];
+        // hidden -> in
+        for (a = 0; a < window * 2 + 1; a++) if (a != window) {
+          c = sentence_position - window + a;
+          if (c < 0) continue;
+          if (c >= sentence_length) continue;
+          last_word = sen[c];
+          if (last_word == -1) continue;
+          window_offset = a * layer1_size;
+          if(a > window) window_offset -= layer1_size;
+          for (c = 0; c < layer1_size; c++) syn0[c + last_word * layer1_size] += neu1e[c + window_offset];
+        }
+      }
+    }
+    else{
+	printf("unknown type %i", type);
+	exit(0);
+    }
+    sentence_position++;
+    if (sentence_position >= sentence_length) {
+      sentence_length = 0;
+      continue;
+    }
+  }
+  fclose(fi);
+  free(neu1);
+  free(neu1e);
+  pthread_exit(NULL);
+}
+
+void TrainModel() {
+  long a, b, c, d;
+  FILE *fo;
+  pthread_t *pt = (pthread_t *)malloc(num_threads * sizeof(pthread_t));
+  printf("Starting training using file %s\n", train_file);
+  starting_alpha = alpha;
+  if (read_vocab_file[0] != 0) ReadVocab(); else LearnVocabFromTrainFile();
+  if (save_vocab_file[0] != 0) SaveVocab();
+  if (output_file[0] == 0) return;
+  InitNet();
+  if (negative > 0 || nce > 0) InitUnigramTable();
+  if (negative_classes_file[0] != 0) InitClassUnigramTable();
+  start = clock();
+  for (a = 0; a < num_threads; a++) pthread_create(&pt[a], NULL, TrainModelThread, (void *)a);
+  for (a = 0; a < num_threads; a++) pthread_join(pt[a], NULL);
+  fo = fopen(output_file, "wb");
+  if (classes == 0) {
+    // Save the word vectors
+    fprintf(fo, "%lld %lld\n", vocab_size, layer1_size);
+    for (a = 0; a < vocab_size; a++) {
+      fprintf(fo, "%s ", vocab[a].word);
+      if (binary) for (b = 0; b < layer1_size; b++) fwrite(&syn0[a * layer1_size + b], sizeof(real), 1, fo);
+      else for (b = 0; b < layer1_size; b++) fprintf(fo, "%lf ", syn0[a * layer1_size + b]);
+      fprintf(fo, "\n");
+    }
+  } else {
+    // Run K-means on the word vectors
+    int clcn = classes, iter = 10, closeid;
+    int *centcn = (int *)malloc(classes * sizeof(int));
+    int *cl = (int *)calloc(vocab_size, sizeof(int));
+    real closev, x;
+    real *cent = (real *)calloc(classes * layer1_size, sizeof(real));
+    for (a = 0; a < vocab_size; a++) cl[a] = a % clcn;
+    for (a = 0; a < iter; a++) {
+      for (b = 0; b < clcn * layer1_size; b++) cent[b] = 0;
+      for (b = 0; b < clcn; b++) centcn[b] = 1;
+      for (c = 0; c < vocab_size; c++) {
+        for (d = 0; d < layer1_size; d++) cent[layer1_size * cl[c] + d] += syn0[c * layer1_size + d];
+        centcn[cl[c]]++;
+      }
+      for (b = 0; b < clcn; b++) {
+        closev = 0;
+        for (c = 0; c < layer1_size; c++) {
+          cent[layer1_size * b + c] /= centcn[b];
+          closev += cent[layer1_size * b + c] * cent[layer1_size * b + c];
+        }
+        closev = sqrt(closev);
+        for (c = 0; c < layer1_size; c++) cent[layer1_size * b + c] /= closev;
+      }
+      for (c = 0; c < vocab_size; c++) {
+        closev = -10;
+        closeid = 0;
+        for (d = 0; d < clcn; d++) {
+          x = 0;
+          for (b = 0; b < layer1_size; b++) x += cent[layer1_size * d + b] * syn0[c * layer1_size + b];
+          if (x > closev) {
+            closev = x;
+            closeid = d;
+          }
+        }
+        cl[c] = closeid;
+      }
+    }
+    // Save the K-means classes
+    for (a = 0; a < vocab_size; a++) fprintf(fo, "%s %d\n", vocab[a].word, cl[a]);
+    free(centcn);
+    free(cent);
+    free(cl);
+  }
+  fclose(fo);
+}
+
+int ArgPos(char *str, int argc, char **argv) {
+  int a;
+  for (a = 1; a < argc; a++) if (!strcmp(str, argv[a])) {
+    if (a == argc - 1) {
+      printf("Argument missing for %s\n", str);
+      exit(1);
+    }
+    return a;
+  }
+  return -1;
+}
+
+int main(int argc, char **argv) {
+  int i;
+  if (argc == 1) {
+    printf("WORD VECTOR estimation toolkit v 0.1c\n\n");
+    printf("Options:\n");
+    printf("Parameters for training:\n");
+    printf("\t-train <file>\n");
+    printf("\t\tUse text data from <file> to train the model\n");
+    printf("\t-output <file>\n");
+    printf("\t\tUse <file> to save the resulting word vectors / word clusters\n");
+    printf("\t-size <int>\n");
+    printf("\t\tSet size of word vectors; default is 100\n");
+    printf("\t-window <int>\n");
+    printf("\t\tSet max skip length between words; default is 5\n");
+    printf("\t-sample <float>\n");
+    printf("\t\tSet threshold for occurrence of words. Those that appear with higher frequency in the training data\n");
+    printf("\t\twill be randomly down-sampled; default is 1e-3, useful range is (0, 1e-5)\n");
+    printf("\t-hs <int>\n");
+    printf("\t\tUse Hierarchical Softmax; default is 0 (not used)\n");
+    printf("\t-negative <int>\n");
+    printf("\t\tNumber of negative examples; default is 5, common values are 3 - 10 (0 = not used)\n");
+    printf("\t-negative-classes <file>\n");
+    printf("\t\tNegative classes to sample from\n");
+    printf("\t-nce <int>\n");
+    printf("\t\tNumber of negative examples for nce; default is 0, common values are 3 - 10 (0 = not used)\n");
+    printf("\t-threads <int>\n");
+    printf("\t\tUse <int> threads (default 12)\n");
+    printf("\t-iter <int>\n");
+    printf("\t\tRun more training iterations (default 5)\n");
+    printf("\t-min-count <int>\n");
+    printf("\t\tThis will discard words that appear less than <int> times; default is 5\n");
+    printf("\t-alpha <float>\n");
+    printf("\t\tSet the starting learning rate; default is 0.025 for skip-gram and 0.05 for CBOW\n");
+    printf("\t-classes <int>\n");
+    printf("\t\tOutput word classes rather than word vectors; default number of classes is 0 (vectors are written)\n");
+    printf("\t-debug <int>\n");
+    printf("\t\tSet the debug mode (default = 2 = more info during training)\n");
+    printf("\t-binary <int>\n");
+    printf("\t\tSave the resulting vectors in binary moded; default is 0 (off)\n");
+    printf("\t-save-vocab <file>\n");
+    printf("\t\tThe vocabulary will be saved to <file>\n");
+    printf("\t-read-vocab <file>\n");
+    printf("\t\tThe vocabulary will be read from <file>, not constructed from the training data\n");
+    printf("\t-type <int>\n");
+    printf("\t\tType of embeddings (0 for cbow, 1 for skipngram, 2 for cwindow, 3 for structured skipngram, 4 for senna type)\n");
+    printf("\t-cap <int>\n");
+    printf("\t\tlimit the parameter values to the range [-50, 50]; default is 0 (off)\n");
+    printf("\nExamples:\n");
+    printf("./word2vec -train data.txt -output vec.txt -size 200 -window 5 -sample 1e-4 -negative 5 -hs 0 -binary 0 -type 1 -iter 3\n\n");
+    return 0;
+  }
+  output_file[0] = 0;
+  save_vocab_file[0] = 0;
+  read_vocab_file[0] = 0;
+  negative_classes_file[0] = 0;
+  if ((i = ArgPos((char *)"-size", argc, argv)) > 0) layer1_size = atoi(argv[i + 1]);
+  if ((i = ArgPos((char *)"-train", argc, argv)) > 0) strcpy(train_file, argv[i + 1]);
+  if ((i = ArgPos((char *)"-save-vocab", argc, argv)) > 0) strcpy(save_vocab_file, argv[i + 1]);
+  if ((i = ArgPos((char *)"-read-vocab", argc, argv)) > 0) strcpy(read_vocab_file, argv[i + 1]);
+  if ((i = ArgPos((char *)"-debug", argc, argv)) > 0) debug_mode = atoi(argv[i + 1]);
+  if ((i = ArgPos((char *)"-binary", argc, argv)) > 0) binary = atoi(argv[i + 1]);
+  if ((i = ArgPos((char *)"-type", argc, argv)) > 0) type = atoi(argv[i + 1]);
+  if ((i = ArgPos((char *)"-output", argc, argv)) > 0) strcpy(output_file, argv[i + 1]);
+  if ((i = ArgPos((char *)"-window", argc, argv)) > 0) window = atoi(argv[i + 1]);
+  if ((i = ArgPos((char *)"-sample", argc, argv)) > 0) sample = atof(argv[i + 1]);
+  if ((i = ArgPos((char *)"-hs", argc, argv)) > 0) hs = atoi(argv[i + 1]);
+  if ((i = ArgPos((char *)"-negative", argc, argv)) > 0) negative = atoi(argv[i + 1]);
+  if ((i = ArgPos((char *)"-negative-classes", argc, argv)) > 0) strcpy(negative_classes_file, argv[i + 1]);
+  if ((i = ArgPos((char *)"-nce", argc, argv)) > 0) nce = atoi(argv[i + 1]);
+  if ((i = ArgPos((char *)"-threads", argc, argv)) > 0) num_threads = atoi(argv[i + 1]);
+  if ((i = ArgPos((char *)"-iter", argc, argv)) > 0) iter = atoi(argv[i + 1]);
+  if ((i = ArgPos((char *)"-min-count", argc, argv)) > 0) min_count = atoi(argv[i + 1]);
+  if ((i = ArgPos((char *)"-classes", argc, argv)) > 0) classes = atoi(argv[i + 1]);
+  if ((i = ArgPos((char *)"-cap", argc, argv)) > 0) cap = atoi(argv[i + 1]);
+  if (type==0 || type==2 || type==4) alpha = 0.05;
+  if ((i = ArgPos((char *)"-alpha", argc, argv)) > 0) alpha = atof(argv[i + 1]);
+  vocab = (struct vocab_word *)calloc(vocab_max_size, sizeof(struct vocab_word));
+  vocab_hash = (int *)calloc(vocab_hash_size, sizeof(int));
+  expTable = (real *)malloc((EXP_TABLE_SIZE + 1) * sizeof(real));
+  for (i = 0; i < EXP_TABLE_SIZE; i++) {
+    expTable[i] = exp((i / (real)EXP_TABLE_SIZE * 2 - 1) * MAX_EXP); // Precompute the exp() table
+    expTable[i] = expTable[i] / (expTable[i] + 1);                   // Precompute f(x) = x / (x + 1)
+  }
+  TrainModel();
+  return 0;
+}
+
