mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-01 00:12:27 +03:00
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
This commit is contained in:
parent
26b6d632da
commit
f64cc96d7b
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user