diff options
author | redpony <redpony@1f5c12ca-751b-0410-a591-d2e778427230> | 2006-07-18 07:33:09 +0400 |
---|---|---|
committer | redpony <redpony@1f5c12ca-751b-0410-a591-d2e778427230> | 2006-07-18 07:33:09 +0400 |
commit | f64cc96d7b16f26eb6dd8d8d9fb72b816e791a7e (patch) | |
tree | f4d36563e6d5e0928c8a63508030e1bb1acbbcb9 /moses | |
parent | 26b6d632da1c7f14d4e8ee9d104d2dfdebf78e40 (diff) |
fix performance bug in SRI lm access code
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@165 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'moses')
-rwxr-xr-x | moses/src/LanguageModel_SRI.cpp | 11 | ||||
-rwxr-xr-x | moses/src/LanguageModel_SRI.h | 2 | ||||
-rwxr-xr-x | moses/src/TypeDef.h | 1 |
3 files changed, 7 insertions, 7 deletions
diff --git a/moses/src/LanguageModel_SRI.cpp b/moses/src/LanguageModel_SRI.cpp index cb8ed46e2..30346e340 100755 --- a/moses/src/LanguageModel_SRI.cpp +++ b/moses/src/LanguageModel_SRI.cpp @@ -103,10 +103,10 @@ LmId LanguageModel_SRI::GetLmID( const std::string &str ) const return res; } -float LanguageModel_SRI::GetValue(LmId wordId, VocabIndex *context) const +float LanguageModel_SRI::GetValue(VocabIndex wordId, VocabIndex *context) const { LanguageModel_SRI *lm = const_cast<LanguageModel_SRI*>(this); // hack. not sure if supposed to cast this - float p = lm->m_srilmModel->wordProb( wordId.sri, context ); + float p = lm->m_srilmModel->wordProb( wordId, context ); return FloorSRIScore(TransformSRIScore(p)); // log10->log } @@ -114,16 +114,15 @@ float LanguageModel_SRI::GetValue(const vector<const Factor*> &contextFactor) co { // set up context size_t count = contextFactor.size(); - VocabIndex *context = (VocabIndex*) malloc(count * sizeof(VocabIndex)); + VocabIndex context[MAX_NGRAM_SIZE]; for (size_t i = 0 ; i < count - 1 ; i++) { - context[i] = GetLmID(contextFactor[count-2-i]).sri; + context[i] = contextFactor[count-2-i]->GetLmId().sri; } context[count-1] = Vocab_None; // call sri lm fn - float ret = GetValue(GetLmID(contextFactor[count-1]->GetString()), context); - free(context); + float ret = GetValue(contextFactor[count-1]->GetLmId().sri, context); return ret; } diff --git a/moses/src/LanguageModel_SRI.h b/moses/src/LanguageModel_SRI.h index 32e9b1b30..f1a0acbd5 100755 --- a/moses/src/LanguageModel_SRI.h +++ b/moses/src/LanguageModel_SRI.h @@ -56,7 +56,7 @@ protected: Vocab *m_srilmVocab; // TODO - make this a ptr, remove #include from header Ngram *m_srilmModel; // " " - float GetValue(LmId wordId, VocabIndex *context) const; + float GetValue(VocabIndex wordId, VocabIndex *context) const; LmId GetLmID( const Factor *factor ) const { diff --git a/moses/src/TypeDef.h b/moses/src/TypeDef.h index ed88dcc71..ff7107109 100755 --- a/moses/src/TypeDef.h +++ b/moses/src/TypeDef.h @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #define UNKNOWN_FACTOR "UNK" #define NOT_FOUND std::numeric_limits<size_t>::max() +#define MAX_NGRAM_SIZE 20 const size_t DEFAULT_MAX_HYPOSTACK_SIZE = 200; const size_t ARRAY_SIZE_INCR = 20; //amount by which a hypostack gets resized when necessary |