src/trainer.cpp
//Add delta to the parameter stored in the buffer and send it to multiverso
Add delta to the parameter stored in the buffer and send it to multiverso
Add delta to the parameter stored in the buffer and send it to multiverso
int Trainer<T>::AddParameterToMultiverso(std::vector<int>& input_layer_nodes, std::vector<int>& output_layer_nodes, void* local_word2vector_neural_network)
{
	SkipGramMixtureNeuralNetwork<T>* word2vector_neural_network = (SkipGramMixtureNeuralNetwork<T>*)local_word2vector_neural_network;
	std::vector<T*> blocks; 
	for (int i = 0; i < input_layer_nodes.size(); ++i)
	{
		int table_id = kInputEmbeddingTableId;
		int row_id_base = m_word_sense_info->p_input_embedding[input_layer_nodes[i]];
		T* ptr = word2vector_neural_network->GetInputEmbeddingWeights(input_layer_nodes[i]);
		for (int j = 0, row_id = row_id_base; j < m_word_sense_info->word_sense_cnts_info[input_layer_nodes[i]]; ++j, ++row_id)
			AddParameterRowToMultiverso(ptr + m_option->embeding_size * j, table_id, row_id, m_option->embeding_size);
		blocks.push_back(ptr);
	}
	for (int i = 0; i < output_layer_nodes.size(); ++i)
	{
		int table_id = kEmbeddingOutputTableId;
		int row_id = output_layer_nodes[i];
		T* ptr = word2vector_neural_network->GetEmbeddingOutputWeights(row_id);
		AddParameterRowToMultiverso(ptr, table_id, row_id, m_option->embeding_size);
		blocks.push_back(ptr);
	}
	for (int i = 0; i < input_layer_nodes.size(); ++i)
	{
		if (m_word_sense_info->word_sense_cnts_info[input_layer_nodes[i]] > 1)
		{
			int table_id = kWordSensePriorTableId;
			int row_id = m_word_sense_info->p_wordidx2sense_idx[input_layer_nodes[i]];
			T* ptr = word2vector_neural_network->GetSensePriorWeights(input_layer_nodes[i]);
			T* para_ptr = word2vector_neural_network->GetSensePriorParaWeights(input_layer_nodes[i]);
			AddParameterRowToMultiverso(para_ptr, table_id, row_id, m_option->sense_num_multi, static_cast<real>(word2vector_neural_network->sense_prior_momentum));
			blocks.push_back(ptr);
			blocks.push_back(para_ptr);
		}
	}
	for (auto& x : blocks)
		free(x);
	return 0;
}
int Trainer < T > :: AddParameterToMultiverso ( std :: vector < int > & input_layer_nodes , std :: vector < int > & output_layer_nodes , void * local_word2vector_neural_network ) { SkipGramMixtureNeuralNetwork < T > * word2vector_neural_network = ( SkipGramMixtureNeuralNetwork < T > * ) local_word2vector_neural_network ; std :: vector < T * > blocks ; for ( int i = 0 ; i < input_layer_nodes . size ( ) ; ++ i ) { int table_id = kInputEmbeddingTableId ; int row_id_base = m_word_sense_info -> p_input_embedding [ input_layer_nodes [ i ] ] ; T * ptr = word2vector_neural_network -> GetInputEmbeddingWeights ( input_layer_nodes [ i ] ) ; for ( int j = 0 , row_id = row_id_base ; j < m_word_sense_info -> word_sense_cnts_info [ input_layer_nodes [ i ] ] ; ++ j , ++ row_id ) AddParameterRowToMultiverso ( ptr + m_option -> embeding_size * j , table_id , row_id , m_option -> embeding_size ) ; blocks . push_back ( ptr ) ; } for ( int i = 0 ; i < output_layer_nodes . size ( ) ; ++ i ) { int table_id = kEmbeddingOutputTableId ; int row_id = output_layer_nodes [ i ] ; T * ptr = word2vector_neural_network -> GetEmbeddingOutputWeights ( row_id ) ; AddParameterRowToMultiverso ( ptr , table_id , row_id , m_option -> embeding_size ) ; blocks . push_back ( ptr ) ; } for ( int i = 0 ; i < input_layer_nodes . size ( ) ; ++ i ) { if ( m_word_sense_info -> word_sense_cnts_info [ input_layer_nodes [ i ] ] > 1 ) { int table_id = kWordSensePriorTableId ; int row_id = m_word_sense_info -> p_wordidx2sense_idx [ input_layer_nodes [ i ] ] ; T * ptr = word2vector_neural_network -> GetSensePriorWeights ( input_layer_nodes [ i ] ) ; T * para_ptr = word2vector_neural_network -> GetSensePriorParaWeights ( input_layer_nodes [ i ] ) ; AddParameterRowToMultiverso ( para_ptr , table_id , row_id , m_option -> sense_num_multi , static_cast < real > ( word2vector_neural_network -> sense_prior_momentum ) ) ; blocks . push_back ( ptr ) ; blocks . push_back ( para_ptr ) ; } } for ( auto & x : blocks ) free ( x ) ; return 0 ; }
Add delta to the parameter stored in the buffer and send it to multiverso
Add delta to the parameter stored in the buffer and send it to multiverso
//used to store locally malloced memorys //Add input embeddings //Add output embeddings //Add sense priors