src/skipgram_mixture_neural_network.cpp
//Train a window sample and update the input embedding & output embedding vectors
Train a window sample and update the input embedding & output embedding vectors
Train a window sample and update the input embedding & output embedding vectors
void SkipGramMixtureNeuralNetwork<T>::TrainSample(int input_node, std::vector<std::pair<int, int> >& output_nodes, void* v_gamma, void* v_fTable, void* v_input_backup)
{
	T* gamma = (T*)v_gamma; 
	T* f_table = (T*)v_fTable; 
	T* input_backup = (T*)v_input_backup;
	T posterior_ll[MAX_SENSE_CNT]; 
	T senses[1] = { 1.0 }; 
	T* sense_prior = m_word_sense_info->word_sense_cnts_info[input_node] == 1 ? senses : (m_option->store_multinomial ? m_sense_priors_paras_ptr[input_node] : m_sense_priors_ptr[input_node]);
	T log_likelihood;
	for (int iter = 0; iter < m_option->EM_iteration; ++iter)
	{
		memcpy(input_backup, m_input_embedding_weights_ptr[input_node], m_option->embeding_size * m_word_sense_info->word_sense_cnts_info[input_node] * sizeof(T));
		log_likelihood = 0;
		log_likelihood += EstimateGamma(input_node, output_nodes, posterior_ll, gamma, sense_prior, f_table);
		if (m_option->store_multinomial)
			MaximizeSensePriors(input_node, gamma);
		else
			MaximizeSensePriors(input_node, posterior_ll);
		UpdateEmbeddings(input_node, output_nodes, gamma, f_table, input_backup, UpdateDirection::UPDATE_INPUT);
		UpdateEmbeddings(input_node, output_nodes, gamma, f_table, input_backup, UpdateDirection::UPDATE_OUTPUT);
	}
}
void SkipGramMixtureNeuralNetwork < T > :: TrainSample ( int input_node , std :: vector < std :: pair < int , int > > & output_nodes , void * v_gamma , void * v_fTable , void * v_input_backup ) { T * gamma = ( T * ) v_gamma ; T * f_table = ( T * ) v_fTable ; T * input_backup = ( T * ) v_input_backup ; T posterior_ll [ MAX_SENSE_CNT ] ; T senses [ 1 ] = { 1.0 } ; T * sense_prior = m_word_sense_info -> word_sense_cnts_info [ input_node ] == 1 ? senses : ( m_option -> store_multinomial ? m_sense_priors_paras_ptr [ input_node ] : m_sense_priors_ptr [ input_node ] ) ; T log_likelihood ; for ( int iter = 0 ; iter < m_option -> EM_iteration ; ++ iter ) { memcpy ( input_backup , m_input_embedding_weights_ptr [ input_node ] , m_option -> embeding_size * m_word_sense_info -> word_sense_cnts_info [ input_node ] * sizeof ( T ) ) ; log_likelihood = 0 ; log_likelihood += EstimateGamma ( input_node , output_nodes , posterior_ll , gamma , sense_prior , f_table ) ; if ( m_option -> store_multinomial ) MaximizeSensePriors ( input_node , gamma ) ; else MaximizeSensePriors ( input_node , posterior_ll ) ; UpdateEmbeddings ( input_node , output_nodes , gamma , f_table , input_backup , UpdateDirection :: UPDATE_INPUT ) ; UpdateEmbeddings ( input_node , output_nodes , gamma , f_table , input_backup , UpdateDirection :: UPDATE_OUTPUT ) ; } }
Train a window sample and update the input embedding & output embedding vectors
Train a window sample and update the input embedding & output embedding vectors
//stores the posterior probabilities //stores the inner product values of input and output embeddings //stores the posterior log likelihood //For those words with only one sense // backup input embeddings // E-Step // M-Step