Fixed bad config when creating language model from dialog

This commit is contained in:
Daniel Wolf 2016-10-21 21:17:17 +02:00
parent ea3e88fd62
commit 9cfe577612
3 changed files with 9 additions and 5 deletions

View File

@ -172,12 +172,12 @@ void createLanguageModelFile(const vector<string>& words, path filePath) {
file << "\\end\\" << endl; file << "\\end\\" << endl;
} }
lambda_unique_ptr<ngram_model_t> createLanguageModel(const vector<string>& words, logmath_t& logMath) { lambda_unique_ptr<ngram_model_t> createLanguageModel(const vector<string>& words, ps_decoder_t& decoder) {
path tempFilePath = getTempFilePath(); path tempFilePath = getTempFilePath();
createLanguageModelFile(words, tempFilePath); createLanguageModelFile(words, tempFilePath);
auto deleteTempFile = gsl::finally([&]() { boost::filesystem::remove(tempFilePath); }); auto deleteTempFile = gsl::finally([&]() { boost::filesystem::remove(tempFilePath); });
return lambda_unique_ptr<ngram_model_t>( return lambda_unique_ptr<ngram_model_t>(
ngram_model_read(nullptr, tempFilePath.string().c_str(), NGRAM_ARPA, &logMath), ngram_model_read(decoder.config, tempFilePath.string().c_str(), NGRAM_ARPA, decoder.lmath),
[](ngram_model_t* lm) { ngram_model_free(lm); }); [](ngram_model_t* lm) { ngram_model_free(lm); });
} }

View File

@ -1,6 +1,10 @@
#pragma once #pragma once
#include <sphinxbase/ngram_model.h>
#include <vector> #include <vector>
#include "tools.h" #include "tools.h"
lambda_unique_ptr<ngram_model_t> createLanguageModel(const std::vector<std::string>& words, logmath_t& logMath); extern "C" {
#include <pocketsphinx.h>
#include <ngram_search.h>
}
lambda_unique_ptr<ngram_model_t> createLanguageModel(const std::vector<std::string>& words, ps_decoder_t& decoder);

View File

@ -267,7 +267,7 @@ lambda_unique_ptr<ps_decoder_t> createDecoder(optional<u32string> dialog) {
vector<string> words = tokenizeText(*dialog, [&](const string& word) { return dictionaryContains(*decoder->dict, word); }); vector<string> words = tokenizeText(*dialog, [&](const string& word) { return dictionaryContains(*decoder->dict, word); });
words.insert(words.begin(), "<s>"); words.insert(words.begin(), "<s>");
words.push_back("</s>"); words.push_back("</s>");
languageModel = createLanguageModel(words, *decoder->lmath); languageModel = createLanguageModel(words, *decoder);
// Add any dialog-specific words to the dictionary // Add any dialog-specific words to the dictionary
addMissingDictionaryWords(words, *decoder); addMissingDictionaryWords(words, *decoder);