ã«ã¼ã«ãã¼ã¹juliusã®èª¤èªè対çã«SVMãå©ç¨ãã¦ã¿ãã
前回やったことの続きã§ãã
ã«ã¼ã«ãã¼ã¹ã®é³å£°èªèãjuliusã§ãã£ãã¨ãã«éå°ã«ããããã¾ããåé¡ã¸ã®å¯¾çã§ãã
ååãjuliusã®ã¯ã»ã観å¯ããç¬èªã®ã¹ã³ã¢ãªã³ã°ãããã¾ããã
å¤å°ã¯èª¤èªèã«å¼·ããªã£ãã®ã§ãããããã§ã人ã¨äººãä¼è©±ãè°è«ãããããªçæã®ããåãã«ãããããã¨ããã£ã±ã誤èªèãã¦ãã¾ãã¾ãã
SVM
ãããããã¯åç´ãªãã©ã¡ã¼ã¿ã®é¾å¤ã§ã¯ç¡çã§ãã
ããé¾å¤ããããè¶
ãããæ¨ã¦ããªã©ã®åç´ãªè©±ã§ã¯ãªãã®ã§ãã
è¤æ°ã®ãã©ã¡ã¼ã¿ãè¤éã«çµ¡ã¿åã£ãä¸çã§ãã
ããããã³ã²ã³ã®æã§è¦³å¯ããæ¨è«ãã¦ãã¦ã¯æéãè¨å¤§ã«ããã£ã¦ãã¾ãã¾ãã
人éã§ããã¨å¤§å¤ãªãã¨ã¯ãæ©æ¢°ã«ãããã¾ãããã
ã¨ãããããã§ãæ©æ¢°å¦ç¿ã§ãã
ä»åã¯ãæ©ä¼å¦ç¿ã®ä¸ããSVMãå©ç¨ãã¾ãã
SVMã¯ç²¾åº¦ããããã¨ãªãããå¦ç¿é度ã¯ããåé¡ããããã®ã®ãå¤å¥ã¯é«éã§ãããä½ããã©ã¤ãã©ãªãæ¯è¼çæã£ã¦ãããå°å
¥ããããããã¦ãã
ã©ã¤ãã©ãªãå
å®ãã¦ããã®ã§ããã©éã¨ããã§ããã¾ããããççºããã
ãã¦ãSVMã®ã©ã¤ãã©ãªã®ä¸ã§ã liblinearãä»åã¯å©ç¨ãã¾ãã
liblinearãªçç±ã¯ç¹ã«ãªããã§ããããªããæµè¡ã£ã¦ããã¨ããã ãã§ããããããã«ãã¼ãã¼ã§ãw
ãã¦ãSVMãå©ç¨ãã¦ãééã£ãèªèã¨æ£ããèªèãåãåãã¦ã¿ã¾ãã
ããããééã£ãèªèã¨ã¯ä½ãï¼
ç§éãä½ã£ã¦ããé³å£°èªèã§ã¯ãå¼ã³ãããã¼ã¯ã¼ã + å½ä»¤ ã¨ãã£ãæ§æã使ãã¾ãã
ååã¯ãã±ã¼ãã¨ããåèªã使ãã¾ããããä»å㯠ã³ã³ãã¥ã¼ã¿ ã¨ããåèªã使ãã¾ãã
ã³ã³ãã¥ã¼ã¿ã«ä»äºããããããã¨ãã¯ãé³å£°ã§ããã³ã³ãã¥ã¼ã¿ããå½ä»¤ããã¦ã ã¨ãããã¹ã£ã¦ä¾é ¼ãã¾ãã
ä¾ãã°ããã³ã³ãã¥ã¼ã¿ãã¨ã¢ã³ã³ãä»ãã¦ãã¨ãã£ãæãã§ãã
ãã®ã³ã³ãã¥ã¼ã¿ã¨ããã¯ã¼ããå¼ã³ããã¨èªãã§ãã¾ãã(åæã«å½åãã¾ãããã©ãã ã¾ãã£ããã)
ã§ããããªãã¨ããã®ã³ã³ãã¥ã¼ã¿ã¨ãã£ãå¼ã³ãããã¼ã¯ã¼ããæ£ããèªèã§ããã°ããããã§ãã
人ã¨äººã¨ãä¼è©±ãã¦ãããããªãçæã®é£ç¶ããã³ã³ãã¥ã¼ã¿ãã¨ããåèªã¨èª¤èªãã¦ãã¾ããé³å£°èªèãã¹ã¿ã¼ãããã¦ãã¾ãã¨ãã£ãã±ã¼ã¹ãåé¡ãªã®ã§ãã
ã³ã³ãã¥ã¼ã¿ã¨ãã£ãåèªãæ£ããèªèã§ããã°ãã»ã¨ãã©ã®èª¤åä½ã¯é²ãã¾ãã
ãã£ã¦ãé³å£°èªèã§èª¤èªèãé¿ããåé¡ã¯ãèªèããåèªãæ¬å½ã«ã³ã³ãã¥ã¼ã¿ã¨ããåèªãªã®ã調ã¹ãåé¡ã¨ããã¾ãã
ééã£ãå¼ã³ããããæ¤åºããªããã°ãæ´çºã¯é²ãã¾ãã
julius-plusã§ã¯ãå¼ã³ããé¨åã å¥é __temp__DictationCheck.wavã¨ãããã¡ã¤ã«ã«åºåãã¾ãã
ããã¯ãå¼ã³ããé¨åãããä¸åº¦ãå¥è¦ç¹ããè¦ãããã«ãé³å£°èªèã«å度ããããã¦ããããã§ãã
ãã®ãã¡ã¤ã«ãå©ç¨ãã¦ãSVMã«ããå¤å¥ãéãã¦ã¿ã¾ãã
âââââââââââââââââââââ
å¦ç¿ããã
SVMã§å¦ç¿ããã¢ãã«ãä½ãããã°ã©ã ãä½ãã¾ããã
githubã«ããã®ã§ãèªç±ã«ã使ããã ããã
https://github.com/rti7743/rtilabs/tree/master/files/asobiba/juliustest/linear
å¦ç¿ããã«ã¯ãå¦ç¿ãããã¼ã¿ãå¿
è¦ã§ãã
ã³ã³ãã¥ã¼ã¿ã¨ããåèªãæ£ããèãåãã wav ã ok_wavãã£ã¬ã¯ããªã«ã
ééã£ã¦èãã¨ã£ã wav ã bad_wav ã«å
¥ãã¾ãã
ããã ãã§ãã¢ãã«ã¯ä½ãã¾ãããã¢ãã«ã®å®æ度ãè¦ãããã«ãæªç¥ã®ãã¹ããã¼ã¿ãç¨æãã¾ãã
æ£ããã³ã³ãã¥ã¼ã¿ã¨ãã£ã¦ããwavã test_ok_wav ã«ã
ééã£ã¦ãã wav ã test_bad_wav ã«å
¥ãã¦ããã¾ãã
linear bad_wav 失æããå¼ã³ãããå ¥ããå ´æã å¦ç¿ãã¼ã¿ã¨ãã¦å©ç¨ãã¾ãã ok_wav æåããå¼ã³ãããå ¥ããå ´æã å¦ç¿ãã¼ã¿ã¨ãã¦å©ç¨ãã¾ãã test_bad_wav 失æããå¼ã³ãããå ¥ããå ´æã å¦ç¿ããã¢ãã«ã®ãã¹ãç¨ã«å©ç¨ãã¾ãã test_ok_wav æåããå¼ã³ãããå ¥ããå ´æã å¦ç¿ããã¢ãã«ã®ãã¹ãç¨ã«å©ç¨ãã¾ãã
ä»åã¯ã110åãããã®ãã¼ã¿ãç¨æãã¾ããã
ããã§ããã°ã©ã ãåããæºåã¯åºæ¥ã¾ããã
å®éã«åããã¦ã¿ã¾ãããã
ããã°ã©ã ãå®è¡ããã¨ã julius ã«ããèªèãã°ããã£ã¼ã¨ã§ã¦ç´ æ§ãè¨é²ãã¾ãã
ãã®ãã¨ã«ãSVMãã¢ãã«ãä½æããã¢ãã«ã®æ¤è¨¼ãè¡ãçµæãç»é¢ã«åºåãã¾ãã
ãã®ã¨ããã¢ãã«ã®ä¿åãè¡ãã¾ãã
å¦ç¿ãããã¼ã¿ãåãã¹ã: Accuracy = 100.000% (110/110) 詳細ã¯log_train.txt æªç¥ã®ãã¼ã¿ã§ã®ãã¹ã : Accuracy = 85.714% (24/28) 詳細ã¯log_test.txt
èªèç 8å²ä»¥ä¸ã
æ師ãã¼ã¿ã«ã¤ãã¦ã¯100%ã¯ãã¾ã¼ããã¨ãã¦ãæªç¥ã®ãã¼ã¿ã«å¯¾ãã¦ã 85%ã®ç²¾åº¦ã§æ£ããåé¡ã§ãã¦ãã¾ãã
ããã¯çµæ§ããããããªã¤ã«ã
ç´ æ§ã¯ï¼
SVMãªã®ã§èããããç´ æ§ãã¨ããããæãè¾¼ãã§ã¿ã¾ãw
//juliusèªèãããã¼ã¿ void g_output_result(Recog *recog, void *dummy) { //åã£ãæéã®ç·æ° const float mseclen = (float)recog->mfcclist->param->samplenum * (float)recog->jconf->input.period * (float)recog->jconf->input.frameshift / 10000.0f; //仮説ã®æ°ã«ããããã«ã㣠const int hypothesisPenalty = countHypothesisPenalty(recog); //1:æå 2:失æ if (g_OKorBAD) { *g_TrainFile << "1"; } else { *g_TrainFile << "2"; } for(const RecogProcess* r = recog->process_list; r ; r=r->next) { //ã´ããæ¶ãã¾ãã if (! r->live || r->result.status < 0 ) { continue; } // output results for all the obtained sentences const auto winfo = r->lm->winfo; for(auto n = 0; n < r->result.sentnum; n++) { // for all sentences const auto s = &(r->result.sent[n]); const auto seq = s->word; const auto seqnum = s->word_num; int i_seq; // output word sequence like Julius //0 , [1 , 2, 3, 4], 5, ã¨å é ã¨æå¾ãé¤ãã¦ãããéå§çµç«¯ãè¨å·ãæããã int i; for(i = 0;i<seqnum;i++) { //1åèª --> åèªã®éåãæã«ãªãã i_seq = seq[i]; //éå§ã¨çµäºãé£ã°ã if ( strcmp(winfo->woutput[i_seq] , "<s>") == 0 || strcmp(winfo->woutput[i_seq] , "</s>") == 0 ){ continue; } break; } if (i >= seqnum) { continue; } //dict ãã pluså´ã®rule ãæ±ãã int dict = atoi(winfo->wname[i_seq]); //ããããã¿ããªãåå¾ãã std::string yomi = ConvertYomi(winfo,i_seq); //cmscoreã®æ°å(ãã®ã¾ã¾ã§ã¯ä½¿ããªãåç¶æ ) auto cmscore = s->confidence[i]; //ç´ æ§1 cmsscore *g_TrainFile << " 1:" << cmscore; //julius ã®ã¹ã³ã¢ 尤度ãããããã¤ãã¹å¤ã0ã«è¿ãã»ã©æ£ãããããã //ããããã¸ãã¦ããªæç« ãå ¥ãã¦ããã¹ã³ã¢ãé«ããªã£ã¦ãã¾ãããé·ãæç« ãå ¥ããã¨ã¹ã³ã¢ã絶æçã«ä½ããªã //ã®ã§ããã®ã¾ã¾ã ã¨ä½¿ããªãã auto score = s->score; //ç´ æ§2 æç« ã¹ã³ã¢ *g_TrainFile << " 2:" << score; auto all_frame = r->result.num_frame; //ç´ æ§3 ãã¬ã¼ã æ° *g_TrainFile << " 3:" << all_frame; //ç´ æ§4 仮説ã®æ°ã«ããããã«ã㣠*g_TrainFile << " 4:" << hypothesisPenalty; //ç´ æ§5 é²é³æé *g_TrainFile << " 5:" << mseclen; //å¤å°ä½¿ããã¹ã³ã¢ãè¨ç®ãã¾ãã // oneSentence->plus_sentence_score = computePlusScore(oneSentence->nodes,s->score,r->result.sentnum,mseclen); auto plus_sentence_score = computePlusScore(cmscore,s->score,hypothesisPenalty,mseclen); //ç´ æ§6 plusã¹ã³ã¢ *g_TrainFile << " 6:" << plus_sentence_score; //ç´ æ§7 ãµã³ãã«æ°ï¼ *g_TrainFile << " 7:" << r->lm->am->mfcc->param->header.samplenum; //ç´ æ§8ã ãããããã¦ã«ãªã£ãã int feature = 8; for(int vecI = 0 ; vecI < r->lm->am->mfcc->param->header.samplenum ;vecI++ ) { for(int vecN = 0 ; vecN < r->lm->am->mfcc->param->veclen ;vecN++ ) { *g_TrainFile << " " << feature++ << ":" << r->lm->am->mfcc->param->parvec[vecI][vecN]; } } *g_TrainFile << std::endl; return ; } } }
ã¨ããããã 1ã 7 ã¾ã§ã¯ããã£ã½ãå¤æ°ã®å¤ãå
¥ãã¾ãã
æå¾ã® 8 ã㯠r->lm->am->mfcc->param->parvec ã®å¤ãå
¥ãã¦ãã¾ãã
ã ããã2000ç´ æ§ãå¤ããã®ã§5000ç´ æ§ããããçã¾ããããã§ãã
ãã®è¨å¤§ãªç´ æ§ã®ä¸ãããSVMã«ããè¦åæ§ãè¦ã¤ãåºããã¾ãã
æå㯠1ã7ã¾ã§ã®ç´ æ§ã§ãã£ã¦ããã®ã§ããããã®ã¨ãã¯ã70%ãããã®èªèçã§ããã
ãããã r->lm->am->mfcc->param->parvec ãå
¥ãããã¨ã§ 8å²ä»¥ä¸ã®èªèçã¨ãªãã¾ããã
r->lm->am->mfcc->param->parvecãå ¥ããªãå ´å
å¦ç¿ãããã¼ã¿ãåãã¹ã: Accuracy = 78.899% (86/109) 詳細ã¯log_train.txt æªç¥ã®ãã¼ã¿ã§ã®ãã¹ã : Accuracy = 71.429% (20/28) 詳細ã¯log_test.txt
r->lm->am->mfcc->param->parvecãå
¥ããå ´å
å¦ç¿ãããã¼ã¿ãåãã¹ã: Accuracy = 100.000% (110/110) 詳細ã¯log_train.txt æªç¥ã®ãã¼ã¿ã§ã®ãã¹ã : Accuracy = 85.714% (24/28) 詳細ã¯log_test.txt
ç´ æ§ã®è¦ã¤ãæ¹ã§ãããããã£ã½ããã®ãæã§å
¥ãããã¨ã¯ããããã¬ã§ recogå¤æ° ã dump ãã¦ãå¤æ°ãdiffãã¦å¤åãã¦ãã奴ãè¦ä»ãåºãã¦æ±ºãã¾ãããæ·±ãæå³ã¯ããã¾ããw
ãããªããå æ¸ãªãã¨ããã£ã¦ããã®ã«ã8å²ä»¥ä¸åããèªèã¢ãã«ãä½ããSVMããã¯ç´ æµã§ããã
俺éã«ã§ããªããã¨ãå¹³ç¶ã¨ãã£ã¦ããããããããã³ããæ§ããã
å¦ç¿çµæã®èªã¿æ¹
ããã°ã©ã ã«ããããã¤ãã®ãã¡ã¤ã«ãã«ã¬ã³ãã«åºåããã¾ãã
ãã¡ã¤ã«å | å½¹å² |
__svm_model.dat | SVMå¦ç¿çµæãæ ¼ç´ããã¢ãã«ã§ãããããå©ç¨ãã¦å¤å¥ãè¡ãã¾ãã |
train.txt | æ師ãã¼ã¿ãå¦ç¿ããããã¼ã¿ãè¨é²ãããã¡ã¤ã«ã§ããliblinearã®ãã©ã¼ãããã§ãã |
log_train.txt | ä½ã£ãã¢ãã«ã§æ師ãã¼ã¿ãæ¤è¨¼ããçµæã§ããå é ã«æ£ããåé¡ãããã°OK ãéãã°BADãå ¥ãã¾ãã |
log_test.txt | æªç¥ã®ãã¼ã¿ã§æ¤è¨¼ããçµæã§ããå é ã«æ£ããåé¡ãããã°OK ãéãã°BADãå ¥ãã¾ãã |
r->lm->am->mfcc->param->parvecãå
¥ããã¨ç´ æ§ãççºãã¦é常ã«èªã¿ã¥ãããªãã¾ãããããã¯ãæå¬ã¨ãããã¨ã§ã
ããã§ä½ã£ã __svm_model.dat ã¢ãã«ã julius ã«çµã¿è¾¼ãã§ã¿ã¾ãããã
SVMãå©ç¨ããjulius
julius-plus ã«SVMãæè¼ããã¦ã¿ã¾ããã
githubã«ããã®ã§ãèªç±ã«ã使ããã ããã
https://github.com/rti7743/rtilabs/tree/master/files/asobiba/juliustest/julius-4.2.1_with_svm
ãã®ããã°ã©ã 㯠windows/linuxã®ã¯ãã¹ãã©ãããã©ã¼ã ã§åä½ãã¾ãã
windows VS2010 㧠julius-4.2.1\msvc\julius-plus.sln ãéãã¦ãã ããã linux sudo apt-get install flex g++ 'libboost*-dev' libboost-thread-dev binutils-dev libboost-system-dev libasound2-dev ./configure --with-mictype=alsa make cd julius-plus make ./julius-plus å¦ç¿ãã¼ã¿ãåæ§ç¯ããå ´åã¯ã次ã®ãã¡ã¤ã«ã«ä¸æ¸ããã¦ãã ãã windowsã®äºº julius-4.2.1_with_svm\msvc\julius-plus\__svm_model.dat ã¨ãã¦ã³ãã£ã¦ãã ããã linuxã®äºº julius-4.2.1_with_svm/julius-plus/__svm_model.dat ã¨ãã¦ã³ãã£ã¦ãã ããã
1æ¥ç¨åº¦åããã¦ã¿ãã®ã§ãããã¹ã³ã¢ã使ã£ã¦ããæãããæ度ãä¸ãã£ãããã«æãã¾ãã
ä»ã¾ã§ãåç´ãªé¾å¤ã§åã£ã¦ããã®ãSVMã«ãªã£ããã¨ã§ãè³¢ãä¼æ¡ãè¡ããã¦ããããã§ãã
ä»ã®ã¨ããã誤èªèã¯ããã¾ããã§ããã
ãã ã幸éãªã ããªã®ããããã¾ãããã»ã»ã»å¼ãç¶ããã¹ããç¶ãããã¨æãã¾ãw
課é¡
ä»ã®ã¨ããã3ã¤ã»ã©èª²é¡ãããã¾ãã
1ã¤ã¯ããªã³ã©ã¤ã³å¦ç¿ãã§ããªããã¨ã
ä»å liblinearãå©ç¨ãããããåçã«å¦ç¿ãããªã³ã©ã¤ã³å¦ç¿ã¯å©ç¨ã§ãã¾ããã
ãã¨ãã°ãééã£ãèªèãããã¨ããã¦ã¼ã¶ãããã¯ã¡ããããã¨ãã£ãå ´åããããã¤ã©å¦ç¿ãããã¨ãã§ãã¾ããã
SVMã§ããªã³ã©ã¤ã³å¦ç¿ããææ³ã¯ãããã¼ãªãã§ãããSVMãå®è£
ãããã¯ã¼ããªãã®ã§ãã¬ã¬ã£ã¦ããã¨ããã§ãã
2ã¤ç®ã¯ããªã r->lm->am->mfcc->param->parvec ãå
¥ããã精度ãä¸ãã£ãã®ãããããããªãã¨ããã¨ããã
ç´ æ§ãæ大5000ç´ æ§ã¨ãªã£ã¦ããã®ã§ããã¯äººéã®ç®ã§è¦ãã®ã¯ä¸å¯è½ã§ãã
ãã£ããä½ã決ãæã«ãªã£ãã®ã¯ãããããã¾ããã
3ã¤ç®ããr->lm->am->mfcc->param->parvecãå
¥ãããã¨ã«ãããç§ã®å£°ã«ç¹åãã¦ãã¾ã£ãã®ã§ã¯ãªããï¼ã¨ãããã¨ã
ä»ã®äººã®å£°ã§ã©ãåå¿ããã®ãï¼ããã¯ã¾ã ããããã£ã¦ãã¾ããw
ä¸äººæ®ããã®è¾ãã¨ããã§ããwwww orz
ã¾ã¨ã
SVMãããã