src/skipgram_mixture_neural_network.cpp
//The E - step, estimate the posterior multinomial probabilities
The E - step, estimate the posterior multinomial probabilities
The E - step estimate the posterior multinomial probabilities
T SkipGramMixtureNeuralNetwork<T>::EstimateGamma(int word_input, std::vector<std::pair<int, int> >& output_nodes, T* posterior_ll, T* estimation, T* sense_prior, T* f_m)
{
	T* input_embedding = m_input_embedding_weights_ptr[word_input];
	T f, log_likelihood = 0;
	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)
	{
		posterior_ll[sense_idx] = sense_prior[sense_idx] < eps ? MIN_LOG : log(sense_prior[sense_idx]); 
		int64_t fidx = sense_idx * MAX_CODE_LENGTH;
		for (int d = 0; d < output_nodes.size(); ++d, fidx++)
		{
			f = Util::InnerProduct(input_embedding, m_output_embedding_weights_ptr[output_nodes[d].first], m_option->embeding_size);
			f = Util::Sigmoid(f);
			f_m[fidx] = f;
			if (output_nodes[d].second) 
				f = 1 - f;
			posterior_ll[sense_idx] += f < eps ? MIN_LOG : log(f);
		}
		log_likelihood += posterior_ll[sense_idx];
	}
	if (m_word_sense_info->word_sense_cnts_info[word_input] == 1)
	{
		estimation[0] = 1;
		return log_likelihood;
	}
	Util::SoftMax(posterior_ll, estimation, m_word_sense_info->word_sense_cnts_info[word_input]);
	return log_likelihood;
}
T SkipGramMixtureNeuralNetwork < T > :: EstimateGamma ( int word_input , std :: vector < std :: pair < int , int > > & output_nodes , T * posterior_ll , T * estimation , T * sense_prior , T * f_m ) { T * input_embedding = m_input_embedding_weights_ptr [ word_input ] ; T f , log_likelihood = 0 ; 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 ) { posterior_ll [ sense_idx ] = sense_prior [ sense_idx ] < eps ? MIN_LOG : log ( sense_prior [ sense_idx ] ) ; int64_t fidx = sense_idx * MAX_CODE_LENGTH ; for ( int d = 0 ; d < output_nodes . size ( ) ; ++ d , fidx ++ ) { f = Util :: InnerProduct ( input_embedding , m_output_embedding_weights_ptr [ output_nodes [ d ] . first ] , m_option -> embeding_size ) ; f = Util :: Sigmoid ( f ) ; f_m [ fidx ] = f ; if ( output_nodes [ d ] . second ) f = 1 - f ; posterior_ll [ sense_idx ] += f < eps ? MIN_LOG : log ( f ) ; } log_likelihood += posterior_ll [ sense_idx ] ; } if ( m_word_sense_info -> word_sense_cnts_info [ word_input ] == 1 ) { estimation [ 0 ] = 1 ; return log_likelihood ; } Util :: SoftMax ( posterior_ll , estimation , m_word_sense_info -> word_sense_cnts_info [ word_input ] ) ; return log_likelihood ; }
The E - step, estimate the posterior multinomial probabilities
The E - step estimate the posterior multinomial probabilities
//posterior likelihood for each sense //huffman code, 0 or 1