diff --git a/word2vecExt.c b/word2vecExt.c
new file mode 100644
index 0000000..88d7ef0
--- /dev/null
+++ b/word2vecExt.c
@@ -0,0 +1,1830 @@
+//  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];
+char save_net_file[MAX_STRING], read_net_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;
+}
+
+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>");
+	while (1) {
+		ReadWord(word, fin);
+		if (feof(fin))
+			break;
+		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 SaveNet() {
+	long long a, b;
+	FILE *fnet = fopen(save_net_file, "wb");
+	if (fnet == NULL) {
+		printf("Net parameter file not found\n");
+		exit(1);
+	}
+	for (a = 0; a < vocab_size; a++)
+		for (b = 0; b < layer1_size; b++) {
+			fwrite(&syn0[a * layer1_size + b], sizeof(real), 1, fnet);
+		}
+	for (a = 0; a < window_hidden_size * window_layer_size; a++) {
+		fwrite(&syn_window_hidden[a],sizeof(real),1,fnet);
+	}
+	fclose(fnet);
+}
+
+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;
+	}
+	if (read_net_file[0] == 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);
+		}
+	}
+	else {
+		FILE *fnet = fopen(read_net_file, "rb");
+		if (fnet == NULL) {
+			printf("Net parameter file not found\n");
+			exit(1);
+		}
+		for (a = 0; a < vocab_size; a++)
+			for (b = 0; b < layer1_size; b++) {
+				fread(&syn0[a * layer1_size + b], sizeof(real), 1, fnet);
+			}
+
+		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++) {
+			fread(&syn_window_hidden[a],sizeof(real),1,fnet);
+		}
+		fclose(fnet);
+	}
+
+	CreateBinaryTree();
+}
+
+void *TrainModelThread(void *id) {
+	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;
+	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));
+
+	FILE *fi = fopen(train_file, "rb");
+	fseek(fi, file_size / (long long) num_threads * (long long) id, SEEK_SET);
+	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  Progress: %.2f%%  Words/thread/sec: %.2fk  ",
+						13, alpha,
+						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) {
+				word = ReadWordIndex(fi);
+				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, file_size / (long long) num_threads * (long long) id,
+					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;
+						// 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;
+						else if (f < -MAX_EXP)
+							g = (label - 0) * alpha;
+						else
+							g = (label
+									- expTable[(int) ((f + MAX_EXP)
+											* (EXP_TABLE_SIZE / MAX_EXP / 2))])
+									* alpha;
+						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;
+						else if (f < -MAX_EXP)
+							g = (label - 0) * alpha;
+						else {
+							f = exp(f);
+							g =
+									(label
+											- f
+													/ (noise_distribution[target]
+															* nce + f)) * alpha;
+						}
+						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;
+							// 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;
+							else if (f < -MAX_EXP)
+								g = (label - 0) * alpha;
+							else
+								g =
+										(label
+												- expTable[(int) ((f + MAX_EXP)
+														* (EXP_TABLE_SIZE
+																/ MAX_EXP / 2))])
+												* alpha;
+							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;
+							else if (f < -MAX_EXP)
+								g = (label - 0) * alpha;
+							else {
+								f = exp(f);
+								g = (label
+										- f
+												/ (noise_distribution[target]
+														* nce + f)) * alpha;
+							}
+							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;
+						// 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;
+						else if (f < -MAX_EXP)
+							g = (label - 0) * alpha;
+						else
+							g = (label
+									- expTable[(int) ((f + MAX_EXP)
+											* (EXP_TABLE_SIZE / MAX_EXP / 2))])
+									* alpha;
+						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;
+						else if (f < -MAX_EXP)
+							g = (label - 0) * alpha;
+						else {
+							f = exp(f);
+							g =
+									(label
+											- f
+													/ (noise_distribution[target]
+															* nce + f)) * alpha;
+						}
+						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;
+							// 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;
+							else if (f < -MAX_EXP)
+								g = (label - 0) * alpha;
+							else
+								g =
+										(label
+												- expTable[(int) ((f + MAX_EXP)
+														* (EXP_TABLE_SIZE
+																/ MAX_EXP / 2))])
+												* alpha;
+							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;
+							else if (f < -MAX_EXP)
+								g = (label - 0) * alpha;
+							else {
+								f = exp(f);
+								g = (label
+										- f
+												/ (noise_distribution[target]
+														* nce + f)) * alpha;
+							}
+							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;
+						// 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 / negative;
+						else if (f < -MAX_EXP)
+							g = (label - 0) * alpha / negative;
+						else
+							g = (label
+									- expTable[(int) ((f + MAX_EXP)
+											* (EXP_TABLE_SIZE / MAX_EXP / 2))])
+									* alpha / 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);
+	if (save_net_file[0] != 0)
+		SaveNet();
+}
+
+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-read-net <file>\n");
+		printf(
+				"\t\tThe net parameters will be read from <file>, not initialized randomly\n");
+		printf("\t-save-net <file>\n");
+		printf("\t\tThe net parameters will be saved to <file>\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;
+	save_net_file[0] = 0;
+	read_net_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 *) "-save-net", argc, argv)) > 0)
+		strcpy(save_net_file, argv[i + 1]);
+	if ((i = ArgPos((char *) "-read-net", argc, argv)) > 0)
+		strcpy(read_net_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;
+}
+
