src/skipgram_mixture_neural_network.cpp
//The M step : update the embedding vectors to maximize the Q function
The M step : update the embedding vectors to maximize the Q function
The M step : update the embedding vectors to maximize the Q function
void SkipGramMixtureNeuralNetwork<T>::UpdateEmbeddings(int word_input, std::vector<std::pair<int, int> >& output_nodes, T* estimation, T* f_m, T* input_backup, UpdateDirection direction)
{
	T g;
	T* output_embedding;
	T* input_embedding;
	if (direction == UpdateDirection::UPDATE_INPUT)
		input_embedding = m_input_embedding_weights_ptr[word_input];
	else input_embedding = input_backup;
	for (int sense_idx = 0; sense_idx < m_word_sense_info->word_sense_cnts_info[word_input]; ++sense_idx, input_embedding += m_option->embeding_size)
	{
		int64_t fidx = sense_idx * MAX_CODE_LENGTH;
		for (int d = 0; d < output_nodes.size(); ++d, ++fidx)
		{
			output_embedding = m_output_embedding_weights_ptr[output_nodes[d].first];
			g = estimation[sense_idx] * (1 - output_nodes[d].second - f_m[fidx]) * learning_rate;
			if (direction == UpdateDirection::UPDATE_INPUT) 
			{
				for (int j = 0; j < m_option->embeding_size; ++j)
					input_embedding[j] += g * output_embedding[j];
			}
			else  
			{
				for (int j = 0; j < m_option->embeding_size; ++j)
					output_embedding[j] += g * input_embedding[j];
			}
		}
	}
}
void SkipGramMixtureNeuralNetwork < T > :: UpdateEmbeddings ( int word_input , std :: vector < std :: pair < int , int > > & output_nodes , T * estimation , T * f_m , T * input_backup , UpdateDirection direction ) { T g ; T * output_embedding ; T * input_embedding ; if ( direction == UpdateDirection :: UPDATE_INPUT ) input_embedding = m_input_embedding_weights_ptr [ word_input ] ; else input_embedding = input_backup ; for ( int sense_idx = 0 ; sense_idx < m_word_sense_info -> word_sense_cnts_info [ word_input ] ; ++ sense_idx , input_embedding += m_option -> embeding_size ) { int64_t fidx = sense_idx * MAX_CODE_LENGTH ; for ( int d = 0 ; d < output_nodes . size ( ) ; ++ d , ++ fidx ) { output_embedding = m_output_embedding_weights_ptr [ output_nodes [ d ] . first ] ; g = estimation [ sense_idx ] * ( 1 - output_nodes [ d ] . second - f_m [ fidx ] ) * learning_rate ; if ( direction == UpdateDirection :: UPDATE_INPUT ) { for ( int j = 0 ; j < m_option -> embeding_size ; ++ j ) input_embedding [ j ] += g * output_embedding [ j ] ; } else { for ( int j = 0 ; j < m_option -> embeding_size ; ++ j ) output_embedding [ j ] += g * input_embedding [ j ] ; } } } }
The M step : update the embedding vectors to maximize the Q function
The M step : update the embedding vectors to maximize the Q function
//Update Input // Update Output