Created
June 8, 2017 05:00
-
-
Save qiaohaijun/e385d426e2f63a46bedb296073671787 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` bash | |
[@nmyjs_176_98 web.web_dnn.20170601.a.qhj_desm]# svn diff http://svn.sogou-inc.com/svn/websearch4/web/web_dnn/branches/desm2opt http://svn.sogou-inc.com/svn/websearch4/web/web_dnn/trunk | |
Authentication realm: <http://svn.sogou-inc.com:80> Sogou SVN | |
Password for 'qiaohaijun': | |
Index: src/gpu_server.cfg | |
=================================================================== | |
--- src/gpu_server.cfg (.../branches/desm2opt) (revision 593977) | |
+++ src/gpu_server.cfg (.../trunk) (revision 593977) | |
@@ -10,7 +10,6 @@ | |
"DnnModelPath"="data/base/dnn.model" | |
"CnnDicPath"="data/base/word2vec.v2" | |
"CnnModelPath"="data/base/model.online.30yi.72.28" | |
-"DesmDicPath"="data/base/word2vec.mul" | |
"dump_request_num"="20000000" #dumpµòequest¸ | |
"dump_request_file"="Dump_test" #dumpµ½´ƅ̵òequestτ¼þµٖ· | |
"dump_request_interval"="1" #dumpȫȳµļ乴£¬}ɧÿ¸pһ¸ | |
Index: src/GPUPredictOnline.cu | |
=================================================================== | |
--- src/GPUPredictOnline.cu (.../branches/desm2opt) (revision 593977) | |
+++ src/GPUPredictOnline.cu (.../trunk) (revision 593977) | |
@@ -3,11 +3,9 @@ | |
#include <vector> | |
#include <assert.h> | |
#include <stdio.h> | |
-#include <math.h> | |
#include <iostream> | |
#include <fstream> | |
-#include <pthread.h> | |
-#include <omp.h> | |
+#include <pthread.h> | |
#include <cuda_runtime.h> | |
#include <cublas_v2.h> | |
#include <thrust/for_each.h> | |
@@ -157,22 +155,12 @@ | |
{ | |
public: | |
int m_size; | |
- int m_sense; | |
std::string m_unknownword; | |
- std::string m_unknownword_dnn; | |
typedef __gnu_cxx::hash_map<std::string, std::vector<float>, str_hash, str_equal> StrVecMap; | |
typedef StrVecMap::value_type StrVecMapType; | |
typedef StrVecMap::iterator hashmapiter; | |
- | |
- //For DESM | |
- StrVecMap m_word2vec_dict_Vg;//single meaning words | |
- StrVecMap m_word2vec_dict_Vs;//muti meaning words | |
- hashmapiter m_endit_tst_Vg; | |
- hashmapiter m_endit_tst_Vs; | |
- std::vector<float> m_mulunk; | |
- std::vector<float> m_dnnunk; | |
// For DNN. | |
StrVecMap m_fastMapDict; | |
thrust::host_vector<float> m_padmat0; | |
@@ -265,100 +253,6 @@ | |
} | |
return 0; | |
} | |
- | |
- int FastReadMulDict(const char* dictpath) | |
- { | |
- /** | |
- For Mul_EM(emb.txt.fine.07200) | |
- load pro and vec (1+100=101) | |
- */ | |
- long long words; | |
- long long veclinenum; | |
- //ifstream infile(dictpath,ios::in|ios::binary); | |
- std::ifstream infile(dictpath); | |
- if(!infile){ | |
- _INFO("load word2vec_mul fail"); | |
- return -1; | |
- } | |
- | |
- infile >> words; | |
- infile >> veclinenum; | |
- infile >> m_size; | |
- m_sense = 3; | |
- | |
- m_word2vec_dict_Vg.resize(words); | |
- m_word2vec_dict_Vs.resize(words); | |
- //float fea100; | |
- //float fea300; | |
- char cwords[512]; | |
- //float *feas = new float[m_size]; | |
- float *feas100 = new float[m_size+1]; | |
- _INFO("m_sense = %d", m_sense); | |
- float *feas300 = new float[(m_size+1) * m_sense]; | |
- m_unknownword="</s>"; | |
- m_unknownword_dnn="</dnn_unk>"; | |
- //int len; | |
- int w_sense; | |
- //_INFO("VAL words = %lld", words); | |
- //_INFO("VAL veclinenum = %lld", veclinenum); | |
- //_INFO("VAL m_size = %d", m_size); | |
- for(int i=0; i< words; ++i){ | |
- infile >> cwords; | |
- infile >> w_sense; | |
- //infile.read((char*)&len,sizeof(int));//len==length(termid) + 1? | |
- //infile.read(cwords,len); | |
- std::string cword(cwords); | |
- if (w_sense == 1){ | |
- for (int dim=0;dim<m_size+1;dim++){ | |
- infile >> feas100[dim]; | |
- } | |
- m_word2vec_dict_Vg.insert(StrVecMapType(cword, std::vector<float>(feas100, feas100 + m_size+1))); | |
- //if(i<10){ | |
- //_INFO("VAL %d:%s feas100[0] = %f feas100[1] = %f", i, cwords, feas100[0], feas100[1]); | |
- //} | |
- } | |
- else if (w_sense == 3){ | |
- for (int s=0;s<w_sense;s++){ | |
- for (int dim=0;dim<m_size+1;dim++){ | |
- infile >> feas300[(m_size+1)*s + dim]; | |
- } | |
- } | |
- m_word2vec_dict_Vs.insert(StrVecMapType(cword, std::vector<float>(feas300, feas300 + (m_size+1)*w_sense))); | |
- //if(i<10){ | |
- //_INFO("VAL %d:%s feas300[0] = %f feas300[1] = %f", i, cwords, feas300[0], feas300[1]); | |
- //} | |
- } | |
- else{ | |
- _INFO("read word2vec_mul error", m_size); | |
- return -1; | |
- } | |
- } | |
- | |
- m_mulunk = m_word2vec_dict_Vg[m_unknownword]; | |
- m_mulunk.erase(m_mulunk.begin());//erase the prob | |
- //_INFO("m_mulunk.size() = %d", m_mulunk.size()); | |
- | |
- m_dnnunk = m_word2vec_dict_Vg[m_unknownword_dnn]; | |
- m_dnnunk.erase(m_dnnunk.begin());//erase the prob | |
- //_INFO("m_dnnunk.size() = %d", m_dnnunk.size()); | |
- | |
- m_endit_tst_Vg = m_word2vec_dict_Vg.end(); | |
- m_endit_tst_Vs = m_word2vec_dict_Vs.end(); | |
- | |
- //_INFO("word2vec_dict_mul load words = %d + %d = %d", m_word2vec_dict_Vg.size(), m_word2vec_dict_Vs.size(), m_word2vec_dict_Vg.size()+m_word2vec_dict_Vs.size()); | |
- //cout<<"word2vec_dict load words = "<<m_word2vec_dict_Vg.size() + m_word2vec_dict_Vs.size()<<endl; | |
- //SS_DEBUG((LM_DEBUG,"xn0: before infile closed\n")); | |
- infile.close(); | |
- //delete [] feas; | |
- //SS_DEBUG((LM_DEBUG,"xn1: before delete fea100\n")); | |
- delete [] feas100; | |
- feas100 = NULL; | |
- //SS_DEBUG((LM_DEBUG,"xn2: before delete fea300\n")); | |
- delete [] feas300; | |
- feas300 = NULL; | |
- //SS_DEBUG((LM_DEBUG,"xn3: after delete fea100\n")); | |
- return 0; | |
- } | |
void LoadDicToGPUMemory(int deviceId) | |
{ | |
@@ -712,227 +606,8 @@ | |
} | |
}; | |
-class DESMPredict { | |
-public: | |
- std::vector<float> m_scores; | |
- static int m_size; | |
- static int m_sense; | |
- typedef __gnu_cxx::hash_map<std::string, std::vector<float>, str_hash, str_equal> StrVecMap; | |
- typedef StrVecMap::value_type StrVecMapType; | |
- typedef StrVecMap::iterator hashmapiter; | |
- bool CalculateScores (WordDictionary &wordDic, std::vector< std::vector< std::string > > &words){ | |
- std::vector<std::vector<std::vector<float> > > sentsWordsVecs; | |
- Words2Vecs(wordDic, words, sentsWordsVecs); | |
- | |
- std::vector<std::vector<float> > Tfeature; | |
- GetTitlesCentroid(sentsWordsVecs, Tfeature); | |
- QtDESMSim(sentsWordsVecs.back(), Tfeature, m_scores); | |
- | |
- Tfeature.clear(); | |
- std::vector <std::vector<float> > (Tfeature).swap(Tfeature); | |
- sentsWordsVecs.clear(); | |
- std::vector<std::vector<std::vector<float> > > (sentsWordsVecs).swap(sentsWordsVecs); | |
- return true; | |
- } | |
- | |
-private: | |
- | |
- void Words2Vecs(WordDictionary &desmWordsDic, const std::vector< std::vector< std::string > > &words, std::vector<std::vector<std::vector<float> > > &sentsWordsVecs){ | |
- for(int sentIndex=0; sentIndex<words.size(); sentIndex++){ | |
- std::vector<std::vector<float> > wordsVecs; | |
- int istrlen=words[sentIndex].size(); | |
- if (istrlen==0) | |
- { | |
- wordsVecs.push_back(desmWordsDic.m_dnnunk); | |
- sentsWordsVecs.push_back(wordsVecs); | |
- continue; | |
- } | |
- | |
- //<compute Vcontext | |
- //for simple: context window == sentence length, and not skip the current word | |
- std::vector<float> Vcontext; | |
- Vcontext.resize(m_size); | |
- int Rt = 0; | |
- | |
- #pragma omp parallel for | |
- for (int i = 0; i < istrlen; i++) | |
- { | |
- hashmapiter it = desmWordsDic.m_word2vec_dict_Vg.find(words[sentIndex][i]); | |
- if ( it != desmWordsDic.m_endit_tst_Vg ) | |
- { | |
- //xn_cuda:vec add | |
- #pragma omp parallel for | |
- for(int ii=0;ii<100;ii++) | |
- { | |
- Vcontext[ii] += (it->second)[ii+1]; | |
- } | |
- Rt++; | |
- } | |
- else | |
- { | |
- hashmapiter it_Vs = desmWordsDic.m_word2vec_dict_Vs.find(words[sentIndex][i]); | |
- if ( it_Vs != desmWordsDic.m_endit_tst_Vs ){ | |
- float maxprob = 0.0; | |
- int maxprob_sense; | |
- for (int s=0; s<m_sense; s++){ | |
- if ((it_Vs->second)[s*(m_size+1)] > maxprob){ | |
- maxprob = (it_Vs->second)[s*(m_size+1)]; | |
- maxprob_sense = s; | |
- } | |
- } | |
- //xn_cuda:vec add | |
- #pragma omp parallel for | |
- for(int ii=0;ii<100;ii++){ | |
- Vcontext[ii] += (it_Vs->second)[maxprob_sense*(m_size+1)+(ii+1)]; | |
- } | |
- Rt++; | |
- } | |
- } | |
- } | |
- if (Rt!=0){ | |
- //xn_cuda:vec/alpha | |
- #pragma omp parallel for | |
- for(int ii=0;ii<100;ii++){ | |
- Vcontext[ii] /= Rt; | |
- } | |
- } | |
- //compute Vcontext> | |
- | |
- #pragma omp parallel for | |
- for(int i=0; i < istrlen;i++) | |
- { | |
- //<choose max_s(sense) | |
- int max_s = 0; | |
- float max_sim = -1; | |
- | |
- std::vector<float> tmp; | |
- tmp.resize(100); | |
- hashmapiter it = desmWordsDic.m_word2vec_dict_Vg.find(words[sentIndex][i]); | |
- if ( it != desmWordsDic.m_endit_tst_Vg ) | |
- { | |
- #pragma omp parallel for | |
- for(int ii=0;ii<100;ii++) | |
- { | |
- tmp[ii] = (it->second)[ii+1]; | |
- } | |
- wordsVecs.push_back(tmp); | |
- } | |
- else | |
- { | |
- hashmapiter it_Vs = desmWordsDic.m_word2vec_dict_Vs.find(words[sentIndex][i]); | |
- if ( it_Vs != desmWordsDic.m_endit_tst_Vs ){ | |
- #pragma omp parallel for | |
- for (int s = 0; s < m_sense; s++){ | |
- float cos = -1, dot_product = 0, l_context = 0, l_u = 0; | |
- //xn_cuda:vec mul | |
- #pragma omp parallel for | |
- for(int ii=0;ii<100;ii++){ | |
- dot_product += Vcontext[ii] * (it_Vs->second)[(ii+1)+s*(m_size+1)]; | |
- l_context += Vcontext[ii] * Vcontext[ii]; | |
- l_u += (it_Vs->second)[(ii+1)+s*(m_size+1)] * (it_Vs->second)[(ii+1)+s*(m_size+1)]; | |
- } | |
- cos = dot_product / (sqrt(l_context)*sqrt(l_u)); | |
- if ( cos > max_sim) { | |
- max_sim = cos; | |
- max_s = s; | |
- } | |
- } | |
- #pragma omp parallel for | |
- for(int ii=0;ii<100;ii++) | |
- { | |
- tmp[ii] = (it_Vs->second)[(ii+1)+max_s*(m_size+1)]; | |
- } | |
- wordsVecs.push_back(tmp); | |
- } | |
- } | |
- tmp.clear(); | |
- std::vector<float>(tmp).swap(tmp); | |
- //choose max_s(sense)> | |
- } | |
- if (wordsVecs.size()==0) | |
- { | |
- wordsVecs.push_back(desmWordsDic.m_dnnunk); | |
- //return; | |
- } | |
- Vcontext.clear(); | |
- std::vector<float>(Vcontext).swap(Vcontext); | |
- sentsWordsVecs.push_back(wordsVecs); | |
- wordsVecs.clear(); | |
- std::vector<std::vector<float> >(wordsVecs).swap(wordsVecs); | |
- } | |
- } | |
- void GetTitlesCentroid(const std::vector<std::vector<std::vector<float> > > sentsWordsVecs, std::vector<std::vector<float> > &titlesCentroid){ | |
- for(int titleIndex=0; titleIndex<sentsWordsVecs.size(); titleIndex++){ | |
- std::vector<float> vec_sum; | |
- vec_sum.resize(m_size); | |
- | |
- for(int i=0; i<sentsWordsVecs[titleIndex].size();i++){ | |
- //fmat vec_norm = arma::sum(wordsVecs[i]%wordsVecs[i], 0);//fmat default is col vec | |
- //vec_norm = arma::sqrt(vec_norm); | |
- //vec_sum += (wordsVecs[i]/vec_norm(0)); | |
- | |
- float vec_norm = 0.0f; | |
- //xn_cuda:vec mul | |
- #pragma omp parallel for | |
- for(int j=0; j<m_size; j++){ | |
- vec_norm += sentsWordsVecs[titleIndex][i][j] * sentsWordsVecs[titleIndex][i][j]; | |
- } | |
- vec_norm = sqrt(vec_norm); | |
- //xn_cuda:vec/alpha | |
- #pragma omp parallel for | |
- for(int j=0; j<m_size; j++){ | |
- vec_sum[j] += sentsWordsVecs[titleIndex][i][j]/vec_norm; | |
- } | |
- } | |
- //SS_DEBUG((LM_DEBUG,"xnMul:before compute titleCentroid <getTitleCentroidMul>")); | |
- //titleCentroid = vec_sum/wordsVecs.size(); | |
- //xn_cuda:vec/alpha | |
- #pragma omp parallel for | |
- for(int i=0; i<m_size; i++){ | |
- vec_sum[i] /= sentsWordsVecs[titleIndex].size(); | |
- } | |
- titlesCentroid.push_back(vec_sum); | |
- //SS_DEBUG((LM_DEBUG,"xnMul:Outof getTitleCentroidMul")); | |
- vec_sum.clear(); | |
- std::vector<float> (vec_sum).swap(vec_sum); | |
- } | |
- } | |
- void QtDESMSim(const std::vector <std::vector<float> > wordsVecs, const std::vector<std::vector<float> > Tfeature,std::vector<float> & qtscore){ | |
- //SS_DEBUG((LM_DEBUG,"Tfeature.n_cols=%d",Tfeature.n_cols)); | |
- //qtscore.set_size(Tfeature.n_cols,1); | |
- qtscore.resize(Tfeature.size()); | |
- | |
- for (int titleIndex=0;titleIndex<Tfeature.size();titleIndex++){ | |
- //SS_DEBUG((LM_DEBUG,"Tfeature %d",i)); | |
- float desm = 0.0f; | |
- #pragma omp parallel for | |
- for(int i=0;i<wordsVecs.size();i++){ | |
- float vec_dot = 0.0f, vec1_norm = 0.0f, vec2_norm = 0.0f, cosin = 0.0f; | |
- //xn_cuda:vec mul | |
- #pragma omp parallel for | |
- for(int j=0;j<Tfeature[titleIndex].size();j++){ | |
- vec_dot += wordsVecs[i][j] * Tfeature[titleIndex][j]; | |
- vec1_norm += wordsVecs[i][j] * wordsVecs[i][j]; | |
- vec2_norm += Tfeature[titleIndex][j] * Tfeature[titleIndex][j]; | |
- } | |
- vec1_norm = sqrt(vec1_norm); | |
- vec2_norm = sqrt(vec2_norm); | |
- cosin = vec_dot/(vec1_norm*vec2_norm); | |
- desm += cosin; | |
- } | |
- desm /= wordsVecs.size(); | |
- //float cosin = DESM(wordsVecs, Tfeature[i]); | |
- //qtscore(i,0) = cosin; | |
- qtscore[titleIndex] = desm; | |
- //SS_DEBUG((LM_DEBUG,"xnMul:i:%d cosin:%f", i, cosin)); | |
- } | |
- } | |
- | |
-}; | |
-int DESMPredict::m_size = 100; | |
-int DESMPredict::m_sense = 3; | |
//////////////////////////////////////////////////////////////// | |
// DNNCore | |
//////////////////////////////////////////////////////////////// | |
@@ -2085,7 +1760,6 @@ | |
WordDictionary wordDic; | |
WordDictionary cnnWordsDic; | |
-WordDictionary desmWordsDic; | |
float* CNNConvDic::FindWord(const std::string& word) { | |
__gnu_cxx::hash_map<std::string, ConvMapKV*, str_hash, str_equal>::iterator it = proc_map.find(word); | |
@@ -2401,7 +2075,6 @@ | |
int m_threadId; | |
DNNPredict m_dnn; | |
CNNPredict m_cnn; | |
- DESMPredict m_desm; | |
WordDictionaryGPU m_wordDicGPUForDNN; | |
WordDictionaryGPU m_wordDicGPUForCNN; | |
}; | |
@@ -2412,8 +2085,7 @@ | |
const char *dnnDicPath, | |
const char *dnnModelPath, | |
const char *cnnDicPath, | |
- const char *cnnModelPath, | |
- const char *desmDicPath | |
+ const char *cnnModelPath | |
) | |
{ | |
DataMembers *pDataMembers = new DataMembers(); | |
@@ -2422,7 +2094,6 @@ | |
m_dnnModelPath = dnnModelPath; | |
m_cnnDicPath = cnnDicPath; | |
m_cnnModelPath = cnnModelPath; | |
- m_desmDicPath = desmDicPath; | |
ThreadArg *pArg = (ThreadArg*)arg; | |
pDataMembers->m_threadId = pArg->threadId; | |
@@ -2456,8 +2127,6 @@ | |
cnnWordsDic.FastReadBinaryDict(m_cnnDicPath, false); | |
cnnWordsDic.PrepareForCNN(pDataMembers->m_cnn.m_CovMat); | |
cnn_conv_dict.GenHash(pDataMembers->m_cnn.m_CovMat, pArg->threadNum, pDataMembers->m_cnn.getMaxCols()); | |
- | |
- desmWordsDic.FastReadMulDict(m_desmDicPath); | |
_INFO("Load dictionarys into main memory finish."); | |
} | |
@@ -2489,16 +2158,13 @@ | |
GPUPredictOnline::RtnCode GPUPredictOnline::ProcessRequest( | |
std::vector<std::vector<std::string> > &dnn_words_vec, | |
std::vector<std::vector<std::string> > &cnn_words_vec, | |
- std::vector<std::vector<std::string> > &desm_words_vec, | |
std::vector<DnnScore> &dnnScores, | |
- std::vector<CnnScore> &cnnScores, | |
- std::vector<DesmScore> &desmScores | |
+ std::vector<CnnScore> &cnnScores | |
) | |
{ | |
DataMembers *pDataMembers = (DataMembers*)m_pDataMembers; | |
int dnn_sentence_count = dnn_words_vec.size(); | |
int cnn_sentence_count = cnn_words_vec.size(); | |
- int desm_sentence_count = desm_words_vec.size(); | |
{// 1. DNN | |
int sentence_count = dnn_words_vec.size(); | |
@@ -2537,12 +2203,10 @@ | |
{ | |
dnnScores[startId + i].score_5002 = pDataMembers->m_dnn.m_scores_FirstLayer[i]; | |
dnnScores[startId + i].score_5003 = pDataMembers->m_dnn.m_scores[i]; | |
- //_INFO("DNN:%d:score_5002:%f score_5003:%f",i,dnnScores[startId + i].score_5002,dnnScores[startId + i].score_5003); | |
} | |
// Query-self score. | |
dnnScores[sentence_count - 1].score_5002 = pDataMembers->m_dnn.m_scores_FirstLayer[curBatchSize - 1]; | |
- dnnScores[sentence_count - 1].score_5003 = pDataMembers->m_dnn.m_scores[curBatchSize - 1]; | |
- //_INFO("DNN:Query-self:score_5002:%f score_5003:%f",dnnScores[sentence_count - 1].score_5002,dnnScores[sentence_count - 1].score_5003); | |
+ dnnScores[sentence_count - 1].score_5003 = pDataMembers->m_dnn.m_scores[curBatchSize - 1]; | |
} | |
} | |
#ifdef CHECK_CNN_CORRECTION | |
@@ -2603,67 +2267,13 @@ | |
{ | |
cnnScores[startId + i].score_5000 = pDataMembers->m_cnn.m_scores_FirstLayer[i]; | |
cnnScores[startId + i].score_5001 = pDataMembers->m_cnn.m_scores[i]; | |
- //_INFO("CNN:%d:score_5000:%f score_5001:%f",i,cnnScores[i].score_5000,cnnScores[i].score_5001); | |
} | |
// Query-self score. | |
cnnScores[sentence_count - 1].score_5000 = pDataMembers->m_cnn.m_scores_FirstLayer[curBatchSize - 1]; | |
cnnScores[sentence_count - 1].score_5001 = pDataMembers->m_cnn.m_scores[curBatchSize - 1]; | |
- //_INFO("CNN:Query-self:score_5000:%f score_5001:%f",cnnScores[sentence_count - 1].score_5000,cnnScores[sentence_count - 1].score_5001); | |
} | |
}// End 2. CNN | |
- {// 3. DESM | |
- int sentence_count = desm_words_vec.size(); | |
- if (!(sentence_count >= 2 && sentence_count <= MAX_MINIBATCH_SIZE)) // [2, MAX_MINIBATCH_SIZE] | |
- { | |
- return DesmSentenceCountOutOfRange; | |
- } | |
- desmScores.resize(sentence_count); | |
- for (int startId = 0; startId < sentence_count - 1; startId += (MINIBATCH_BUFFER_SIZE - 1)) | |
- { | |
- int endId = startId + (MINIBATCH_BUFFER_SIZE - 1); | |
- if (endId > sentence_count - 1) | |
- { | |
- endId = sentence_count - 1; | |
- } | |
- int curBatchSize = endId - startId + 1; | |
- std::vector<std::vector<std::string> > desm_words_vec_batch(curBatchSize); | |
- for (int i = startId; i < endId; ++i) | |
- { | |
- desm_words_vec_batch[i - startId] = desm_words_vec[i]; | |
- } | |
- desm_words_vec_batch[endId - startId] = desm_words_vec.back(); | |
- | |
- bool isValid; | |
- isValid = pDataMembers->m_desm.CalculateScores(desmWordsDic, desm_words_vec_batch); | |
- if (!isValid){ | |
- return DesmException; | |
- } | |
- /* | |
- bool isValid = pDataMembers->m_dnn.MaxPooling(wordDic, pDataMembers->m_wordDicGPUForDNN, dnn_words_vec_batch); | |
- if (!isValid) | |
- { | |
- return DnnWordsOverflow; | |
- } | |
- pDataMembers->m_dnn.SetMinibatchSize(curBatchSize); | |
- pDataMembers->m_dnn.Forward(); | |
- pDataMembers->m_dnn.CosSim_FirstLayer(); | |
- pDataMembers->m_dnn.CosSim(); | |
- */ | |
- | |
- // Query-Title scores. | |
- for (int i = 0; i < curBatchSize - 1; ++i) | |
- { | |
- //dnnScores[startId + i].score_5002 = pDataMembers->m_dnn.m_scores_FirstLayer[i]; | |
- desmScores[startId + i].score_5004 = pDataMembers->m_desm.m_scores[i]; | |
- //_INFO("DESM:%d:score_5004:%f",i,desmScores[startId + i].score_5004); | |
- } | |
- // Query-self score. | |
- //dnnScores[sentence_count - 1].score_5002 = pDataMembers->m_dnn.m_scores_FirstLayer[curBatchSize - 1]; | |
- desmScores[sentence_count - 1].score_5004 = pDataMembers->m_desm.m_scores[curBatchSize - 1]; | |
- //_INFO("DESM:Query-self:score_5004:%f",desmScores[sentence_count - 1].score_5004); | |
- } | |
- } | |
return OK; | |
} | |
Index: src/server_configuration.hpp | |
=================================================================== | |
--- src/server_configuration.hpp (.../branches/desm2opt) (revision 593977) | |
+++ src/server_configuration.hpp (.../trunk) (revision 593977) | |
@@ -27,7 +27,6 @@ | |
std::string dnn_model_path; | |
std::string cnn_dic_path; | |
std::string cnn_model_path; | |
- std::string desm_dic_path; | |
std::string dump_request_file; | |
int dump_request_num; | |
int dump_request_interval; | |
Index: src/gpu_calc_handler.cpp | |
=================================================================== | |
--- src/gpu_calc_handler.cpp (.../branches/desm2opt) (revision 593977) | |
+++ src/gpu_calc_handler.cpp (.../trunk) (revision 593977) | |
@@ -35,13 +35,12 @@ | |
return server_task::open(DEFAULT_GPU_HANDLER_THREAD_NUM, stack_size); | |
} | |
-int gpu_calc_handler::initialize(const std::string& dnn_dic_path, const std::string& dnn_model_path, const std::string& cnn_dic_path, const std::string& cnn_model_path, const std::string& desm_dic_path, int query_timeout) | |
+int gpu_calc_handler::initialize(const std::string& dnn_dic_path, const std::string& dnn_model_path, const std::string& cnn_dic_path, const std::string& cnn_model_path, int query_timeout) | |
{ | |
dnn_dic_path_ = dnn_dic_path; | |
dnn_model_path_ = dnn_model_path; | |
cnn_dic_path_ = cnn_dic_path; | |
cnn_model_path_ = cnn_model_path; | |
- desm_dic_path_ = desm_dic_path; | |
query_timeout_ = query_timeout; | |
} | |
@@ -52,7 +51,7 @@ | |
return 0; | |
} | |
-int gpu_calc_handler::convertRequest(ProtoContent::GpuRequest* request, std::vector<std::vector<std::string> >& dnn_words_vec, std::vector<std::vector<std::string> >& cnn_words_vec, std::vector<std::vector<std::string> >& desm_words_vec) | |
+int gpu_calc_handler::convertRequest(ProtoContent::GpuRequest* request, std::vector<std::vector<std::string> >& dnn_words_vec, std::vector<std::vector<std::string> >& cnn_words_vec) | |
{ | |
dnn_words_vec.resize( request->dnn_words_size()); | |
for (int i = 0; i < request->dnn_words_size(); i++) { | |
@@ -70,18 +69,10 @@ | |
cnn_words_vec[i].push_back(cnn_words->words(j)); | |
} | |
} | |
- desm_words_vec.resize( request->dnn_words_size());//xn:cnn desm | |
- for (int i = 0; i < request->dnn_words_size(); i++) { | |
- ProtoContent::TitleTerms* dnn_words = request->mutable_dnn_words(i); | |
- for (int j=0;j<dnn_words->words_size();j++) | |
- { | |
- desm_words_vec[i].push_back(dnn_words->words(j)); | |
- } | |
- } | |
return 0; | |
} | |
-int gpu_calc_handler::convertResult(ProtoContent::GpuResult* result, std::vector<DnnScore>& dnnScores, std::vector<CnnScore>& cnnScores, std::vector<DesmScore>& desmScores) | |
+int gpu_calc_handler::convertResult(ProtoContent::GpuResult* result, std::vector<DnnScore>& dnnScores, std::vector<CnnScore>& cnnScores) | |
{ | |
if (dnnScores.size() != cnnScores.size()) { | |
return -1; | |
@@ -92,7 +83,6 @@ | |
doc->set_dnn_5001(cnnScores[i].score_5001); | |
doc->set_dnn_5002(dnnScores[i].score_5002); | |
doc->set_dnn_5003(dnnScores[i].score_5003); | |
- doc->set_dnn_5004(desmScores[i].score_5004);//xn: | |
} | |
const int default_dnn_cnn_version = 11; | |
result->set_dnn_version(default_dnn_cnn_version); | |
@@ -115,7 +105,7 @@ | |
threadArg.p_predict_mutex = &predict_mutex_; | |
pthread_mutex_unlock(&thread_mutex_); | |
- predict.Initialize(&threadArg, dnn_dic_path_.c_str(), dnn_model_path_.c_str(), cnn_dic_path_.c_str(), cnn_model_path_.c_str(), desm_dic_path_.c_str()); | |
+ predict.Initialize(&threadArg, dnn_dic_path_.c_str(), dnn_model_path_.c_str(), cnn_dic_path_.c_str(), cnn_model_path_.c_str()); | |
pthread_barrier_wait(&init_barr_); | |
while ((worker = m_task_list.get()) != NULL) | |
@@ -133,8 +123,7 @@ | |
std::vector<std::vector<std::string> > dnn_words_vec; | |
std::vector<std::vector<std::string> > cnn_words_vec; | |
- std::vector<std::vector<std::string> > desm_words_vec; | |
- if (convertRequest(worker->request, dnn_words_vec, cnn_words_vec, desm_words_vec)) | |
+ if (convertRequest(worker->request, dnn_words_vec, cnn_words_vec)) | |
{ | |
_INFO("convertRequest Failed, req(%08x)", worker->request_id); | |
m_manager->dispatch_worker(worker, this); | |
@@ -143,9 +132,8 @@ | |
std::vector<DnnScore> dnnScores; | |
std::vector<CnnScore> cnnScores; | |
- std::vector<DesmScore> desmScores; | |
ACE_Time_Value t1 = ACE_OS::gettimeofday(); | |
- GPUPredictOnline::RtnCode rtn = predict.ProcessRequest(dnn_words_vec, cnn_words_vec, desm_words_vec, dnnScores, cnnScores, desmScores); | |
+ GPUPredictOnline::RtnCode rtn = predict.ProcessRequest(dnn_words_vec, cnn_words_vec, dnnScores, cnnScores); | |
ACE_Time_Value t2 = ACE_OS::gettimeofday(); | |
if (rtn != GPUPredictOnline::OK) | |
{ | |
@@ -153,7 +141,7 @@ | |
m_manager->dispatch_worker(worker, this); | |
continue; | |
} | |
- convertResult(worker->result, dnnScores, cnnScores, desmScores); | |
+ convertResult(worker->result, dnnScores, cnnScores); | |
m_manager->dispatch_worker(worker, this); | |
} | |
Index: src/gpu_calc_handler.hpp | |
=================================================================== | |
--- src/gpu_calc_handler.hpp (.../branches/desm2opt) (revision 593977) | |
+++ src/gpu_calc_handler.hpp (.../trunk) (revision 593977) | |
@@ -11,13 +11,13 @@ | |
virtual int open(size_t thread_num, size_t stack_size); | |
void wait_init_finish(); | |
- virtual int initialize(const std::string& dnn_dic_path, const std::string& dnn_model_path, const std::string& cnn_dic_path, const std::string& cnn_model_path, const std::string& desm_dic_path, int query_timeout); | |
+ virtual int initialize(const std::string& dnn_dic_path, const std::string& dnn_model_path, const std::string& cnn_dic_path, const std::string& cnn_model_path, int query_timeout); | |
virtual int stop(); | |
virtual int svc(); | |
private: | |
- int convertRequest(ProtoContent::GpuRequest* request, std::vector<std::vector<std::string> >& dnn_words_vec, std::vector<std::vector<std::string> >& cnn_words_vec, std::vector<std::vector<std::string> >& desm_words_vec); | |
- int convertResult(ProtoContent::GpuResult* result, std::vector<DnnScore>& dnnScores, std::vector<CnnScore>& cnnScores, std::vector<DesmScore>& desmScores); | |
+ int convertRequest(ProtoContent::GpuRequest* request, std::vector<std::vector<std::string> >& dnn_words_vec, std::vector<std::vector<std::string> >& cnn_words_vec); | |
+ int convertResult(ProtoContent::GpuResult* result, std::vector<DnnScore>& dnnScores, std::vector<CnnScore>& cnnScores); | |
private: | |
int thread_index_; | |
@@ -29,7 +29,6 @@ | |
std::string dnn_model_path_; | |
std::string cnn_dic_path_; | |
std::string cnn_model_path_; | |
- std::string desm_dic_path_; | |
int query_timeout_; | |
}; | |
Index: src/ProtoContent.proto | |
=================================================================== | |
--- src/ProtoContent.proto (.../branches/desm2opt) (revision 593977) | |
+++ src/ProtoContent.proto (.../trunk) (revision 593977) | |
@@ -21,7 +21,6 @@ | |
required float dnn_5001 = 3; | |
required float dnn_5002 = 4; | |
required float dnn_5003 = 5; | |
- optional float dnn_5004 = 6; | |
} | |
message GpuResult | |
Index: src/GPUPredictOnline.h | |
=================================================================== | |
--- src/GPUPredictOnline.h (.../branches/desm2opt) (revision 593977) | |
+++ src/GPUPredictOnline.h (.../trunk) (revision 593977) | |
@@ -18,10 +18,6 @@ | |
float score_5000; | |
float score_5001; | |
}; | |
-struct DesmScore | |
-{ | |
- float score_5004; | |
-}; | |
class GPUPredictOnline | |
{ | |
@@ -33,8 +29,6 @@ | |
DnnWordsOverflow, | |
CnnSentenceCountOutOfRange, | |
CnnWordsOverflow, | |
- DesmSentenceCountOutOfRange, | |
- DesmException, | |
}; | |
public: | |
void Initialize( | |
@@ -42,16 +36,13 @@ | |
const char *dnnDicPath, | |
const char *dnnModelPath, | |
const char *cnnDicPath, | |
- const char *cnnModelPath, | |
- const char *desmDicPath | |
+ const char *cnnModelPath | |
); | |
RtnCode ProcessRequest( | |
std::vector<std::vector<std::string> > &dnn_words_vec, | |
std::vector<std::vector<std::string> > &cnn_words_vec, | |
- std::vector<std::vector<std::string> > &desm_words_vec, | |
std::vector<DnnScore> &dnnScores, | |
- std::vector<CnnScore> &cnnScores, | |
- std::vector<DesmScore> &desmScores | |
+ std::vector<CnnScore> &cnnScores | |
); | |
private: | |
void* m_pDataMembers; | |
@@ -59,5 +50,4 @@ | |
const char *m_dnnModelPath; | |
const char *m_cnnDicPath; | |
const char *m_cnnModelPath; | |
- const char *m_desmDicPath; | |
}; | |
Index: src/main.cpp | |
=================================================================== | |
--- src/main.cpp (.../branches/desm2opt) (revision 593977) | |
+++ src/main.cpp (.../trunk) (revision 593977) | |
@@ -93,7 +93,7 @@ | |
manager.register_task(&task_reply); | |
task_receive.addr(config.listen_port); | |
- task_gpu_calc.initialize(config.dnn_dic_path, config.dnn_model_path, config.cnn_dic_path, config.cnn_model_path, config.desm_dic_path, config.query_timeout); | |
+ task_gpu_calc.initialize(config.dnn_dic_path, config.dnn_model_path, config.cnn_dic_path, config.cnn_model_path, config.query_timeout); | |
task_receive.set_dump_params(config.dump_request_file, config.dump_request_num, config.dump_request_interval); | |
Index: src/server_configuration.cpp | |
=================================================================== | |
--- src/server_configuration.cpp (.../branches/desm2opt) (revision 593977) | |
+++ src/server_configuration.cpp (.../trunk) (revision 593977) | |
@@ -64,11 +64,7 @@ | |
return -1; | |
cnn_model_path.assign(value); | |
- if (config.get_value("DesmDicPath", value)) | |
- return -1; | |
- desm_dic_path.assign(value); | |
- | |
dump_request_num = 0; | |
if(config.get_value("dump_request_num",value) == 0) | |
dump_request_num = atoi(value); | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment