//  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 <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.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_CC 100
#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 *threadPos;
int *threadIters;
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;
real avgWordLength=0;
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;

long cc = 0;

//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++) {
		avgWordLength += vocab[a].cn * (strlen(vocab[a].word) + 1);
		// 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;
		}
	}
	avgWordLength /= train_words;
	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++;
	}
	fclose(fin);
	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);
	SortVocab();
	if (debug_mode > 0) {
		printf("Vocab size: %'lld\n", vocab_size);
		printf("Words in vocab's train file: %'lld\n", train_words);
		printf("Avg. word length in vocab's train file: %.2f\n", avgWordLength);
	}
	train_words = file_size / avgWordLength;
	if(debug_mode > 0)
		printf("Estimated words in train file: %'lld\n", train_words);
}

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 SaveArgs(int argc, char **argv) {
	unsigned int i;
	char args_file[MAX_STRING];
	strcpy(args_file, output_file);
	strcat(args_file, ".args");
	FILE *fargs = fopen(args_file, "w");
	if (fargs == NULL) {
		printf("Cannot save args to %s.\n", args_file);
		return;
	}
	
	for(i=1; i<argc; i++)
		fprintf(fargs, "%s ", argv[i]);

	fprintf(fargs, "\n");
	fclose(fargs);

	return;
}

void SaveNet() {
	if(type != 3 || negative <= 0) { 
		fprintf(stderr, "save-net only supported for type 3 with negative sampling\n");
		return;
	}

	FILE *fnet = fopen(save_net_file, "wb");
	if (fnet == NULL) {
		printf("Net parameter file not found\n");
		exit(1);
	}
	fwrite(syn0, sizeof(real), vocab_size * layer1_size, fnet);
	fwrite(syn1neg_window, sizeof(real), vocab_size * window_layer_size, fnet);
	fclose(fnet);
}

void InitNet() {
	long long a, b;
	unsigned long long next_random = 1;
	long long read;
  
	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) {
		if(type == 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);
			}
			for (a = 0; a < vocab_size; a++)
				for (b = 0; b < layer1_size; b++)
					syn1neg[a * layer1_size + b] = 0;
		} else if (type == 3) {
			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);
			}
			for (a = 0; a < vocab_size; a++)
				for (b = 0; b < window_layer_size; b++)
					syn1neg_window[a * window_layer_size + b] = 0;
		} else if (type == 4) {
			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 < 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(type == 4) {
		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);
		}
	}

	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;
			}
	} else if(type == 3 && negative > 0) {
		FILE *fnet = fopen(read_net_file, "rb");
		if (fnet == NULL) {
			printf("Net parameter file not found\n");
			exit(1);
		}
		printf("vocab-size: %lld, layer1_size: %lld, window_layer_size %d\n", vocab_size, layer1_size, window_layer_size);
		read = fread(syn0, sizeof(real), vocab_size * layer1_size, fnet);
		if(read != vocab_size * layer1_size) {
			fprintf(stderr, "read-net failed %lld\n", read);
			exit(-1);
		}
		read = fread(syn1neg_window, sizeof(real), vocab_size * window_layer_size, fnet);
		if(read != (long long) vocab_size * window_layer_size) {
			fprintf(stderr, "read-net failed, read %lld, expected: %lld\n", read ,
							(long long) sizeof(real) * vocab_size * window_layer_size);
			exit(-1);
		}
		fgetc(fnet);
		if(!feof(fnet)) {
			fprintf(stderr, "Remaining bytes in net-file after read-net. File position: %ld\n", ftell(fnet));
			exit(-1);
		}
		fclose(fnet);
	} else {
		fprintf(stderr, "read-net only supported for type 3 with negative sampling\n");
		exit(-1);
	}

	CreateBinaryTree();
}

char *currentDateTime(char *buf, real offset) {
	time_t     t;
	time(&t);
	t += (long) offset;
	struct tm  tstruct;
	tstruct = *localtime(&t);
	strftime(buf, 80, "%c", &tstruct);
	return buf;
}

void *MonitorThread(void *id) {
	char *timebuf = malloc(80);;
	int i, n=num_threads;
	long long sum;
	sleep(1);
	while(n > 0) {
		sleep(1);
		sum = n = 0;
		for(i=0; i < num_threads; i++) {
			if(threadPos[i] >= 0) {
				sum += (iter - threadIters[i]) * file_size / num_threads + threadPos[i] - (file_size / num_threads) * i;
				n++;
			} else {
				sum += iter * file_size / num_threads;
			}
		}
		if(n == 0)
			break;
		real finished_portion = (real) sum / (float) (file_size * iter);
		long long now = clock();
		long long elapsed = (now - start) / CLOCKS_PER_SEC / num_threads;
		long long ttg = ((1.0 / finished_portion) * (real) elapsed - elapsed) * ((real) num_threads / n) ;

		printf("\rAlpha: %.3f  Done: %.2f%% with %.2fKB/t/s  TE: %llds  TTG: %llds  ETA: %s\033[K",
					 alpha,
					 finished_portion * 100,
					 (float) sum / elapsed / num_threads / 1000,
					 elapsed,
					 ttg,
					 currentDateTime(timebuf, ttg)
					 );
		fflush(stdout);
	}
	pthread_exit(NULL);
}

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;
	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));
	threadIters[(long) id] = iter;

	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");
	long long start_pos = file_size / (long long) num_threads * (long long) id;
	long long end_pos = file_size / (long long) num_threads * (long long) (id + 1) -1;
	long long current_pos = start_pos;
	long long last_pos = start_pos;;
	fseek(fi, start_pos, SEEK_SET);
	while (1) {
		if ((current_pos - last_pos > 100000)) {
			word_count_actual += word_count - last_word_count;
			last_pos = current_pos;
			last_word_count = word_count;
			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) {
            if(type == 3) // in structured skipgrams 
              word = -2;  // keep the window position correct
            else
              continue;
					}
				}
				sen[sentence_length] = word;
				sentence_length++;
				if (sentence_length >= MAX_SENTENCE_LENGTH)
					break;
			}
			sentence_position = 0;
		}
		current_pos = threadPos[(long) id] = ftell(fi);
		if (feof(fi) || current_pos >= end_pos ) {
			word_count_actual += word_count - last_word_count;
			threadIters[(long) id]--;
			local_iter--;
			if (local_iter == 0)
				break;
			word_count = 0;
			current_pos = last_pos = start_pos;
			last_word_count = 0;
			sentence_length = 0;
			fseek(fi, start_pos, SEEK_SET);
			continue;
		}
		word = sen[sentence_position];
    while (word == -2 && sentence_position<sentence_length)
	      word = sen[++sentence_position];
   if (sentence_position>=sentence_length) {
      sentence_length=0;
      continue;
   }
		if (word < 0)
			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 < 0)
						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;
							if(debug_mode > 2 && ((long long) id) == 0) {
								printf("negative sampling %lld for input (word) %s (#%lld), target (last word) %s returned %s (#%lld), ", d, vocab[word].word, word, vocab[last_word].word, vocab[target].word, target);
								printf("label %lld, a %lld, gain %.4f\n", label, a-window, g);
							}
							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);
	threadPos[(long) id] = -1;
	pthread_exit(NULL);
}

void ShowCollocations() {
	long a, b, c, d, e, window_offset, target, max_target=0, maxmax_target;
	real f, max_f, maxmax_f;
	real *target_sums, bestf[MAX_CC], worstbest;
	long besti[MAX_CC];
	int N = 10, bestp[MAX_CC];
	a = posix_memalign((void **) &target_sums, 128, vocab_size * sizeof(real));

	for (d = cc; d < vocab_size; d++) {
		for (b = 0; b < vocab_size; b++)
			target_sums[b]=0;
		for (b = 0; b < N; b++)
			bestf[b]=-1;
		worstbest = -1;

		maxmax_f = -1;
		maxmax_target = 0;
		for (a = window * 2 + 1; a >=0; a--) {
			if (a != window) {
				max_f = -1;
				window_offset = a * layer1_size;
				if (a > window)
					window_offset -= layer1_size;
				for(target = 0; target < vocab_size; target ++) {
					if(target == d)
						continue;
					f = 0;
					for (c = 0; c < layer1_size; c++)
						f += syn0[d* layer1_size + c]	* syn1neg_window[target * window_layer_size	+ window_offset + c];
					if (f < -MAX_EXP)
						continue;
					else if (f > MAX_EXP)
						continue;
					else
						f = expTable[(int) ((f + MAX_EXP)	* (EXP_TABLE_SIZE / MAX_EXP / 2))];
					if(f > max_f) {
						max_f = f;
						max_target = target;
					}
					target_sums[target] += (1-target_sums[target]) * f;
					if(f > worstbest) {
						for (b = 0; b < N; b++) {
							if (f > bestf[b]) {
								for (e = N - 1; e > b; e--) {
									bestf[e] = bestf[e - 1];
									besti[e] = besti[e - 1];
									bestp[e] = bestp[e - 1];
								}
								bestf[b] = f;
								besti[b] = target;
								bestp[b] = window-a;
								break;
							}
						}
						worstbest = bestf[N-1];
					}
				}
				printf("%s (%.2f) ", vocab[max_target].word, max_f);
				if(max_f > maxmax_f) {
					maxmax_f = max_f;
					maxmax_target = max_target;
				}
			} else {
				printf("\x1b[1m%s\x1b[0m ", vocab[d].word);
			}
		}
		max_f = -1;
		for (b = 0; b < vocab_size; b++) {
			if(target_sums[b] > max_f) {
				max_f = target_sums[b];
				max_target = b;
			}
		}
		printf(" – max sum: %s (%.2f), max resp.: \x1b[1m%s\x1b[0m (%.2f)\n",
					 vocab[max_target].word, max_f,
					 vocab[maxmax_target].word, maxmax_f);
		for(b=0; b<N && bestf[b]>-1; b++) 
			printf("%-32s %.2f %d\n", vocab[besti[b]].word, bestf[b], bestp[b]);
		printf("\n");
	}
}

void TrainModel() {
	long a, b, c, d;
	FILE *fo;
	pthread_t *pt = (pthread_t *) malloc(num_threads * sizeof(pthread_t));
	threadPos = malloc(num_threads * sizeof(long long));
	threadIters = malloc(num_threads * sizeof(int));
	char *timebuf = malloc(80);
	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(cc > 0)
		ShowCollocations();
	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);
	if(debug_mode > 1)
		pthread_create(&pt[num_threads], NULL, MonitorThread, (void *) a);
	for (a = 0; a < num_threads; a++)
		pthread_join(pt[a], NULL);
	if(debug_mode > 1) {
		pthread_join(pt[num_threads], NULL);
		clock_t now = clock();
		printf("\nFinished: %s - user: %lds - real: %lds\n", currentDateTime(timebuf, 0), (now-start) / CLOCKS_PER_SEC / num_threads,  (now-start) / CLOCKS_PER_SEC);
		printf("Saving vectors to %s ...", output_file);
		fflush(stdout);
	}
	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");
		}
		if(debug_mode > 1)
			fprintf(stderr, "\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;
}

void print_help() {
		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-show-cc <int>\n");
		printf("\t\tShow words with their collocators starting from word rank <int>. Depends on -read-vocab and -read-net.\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");
}

int main(int argc, char **argv) {
	int i;
	setlocale(LC_ALL, "");
	if (argc == 1) {
		print_help();
		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 *) "-h", argc, argv)) > 0) {
		print_help();
		return(0);
	}
	if ((i = ArgPos((char *) "-help", argc, argv)) > 0) {
		print_help();
		return(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 *) "-show-cc", argc, argv)) > 0)
		cc = 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)
	}
	SaveArgs(argc, argv);
	TrainModel();
	return 0;
}

