fixes an important bug in gen k mixture model
authorPeng Wu <alexepico@gmail.com>
Thu, 23 Jun 2011 02:28:24 +0000 (10:28 +0800)
committerPeng Wu <alexepico@gmail.com>
Thu, 23 Jun 2011 02:28:24 +0000 (10:28 +0800)
utils/training/gen_k_mixture_model.cpp
utils/training/k_mixture_model.h

index bd350b4..f89dce4 100644 (file)
@@ -221,6 +221,10 @@ static bool train_second_word(KMixtureModelBigram * bigram,
         return false;
     }
 
+    /* save the single gram. */
+    assert(bigram->store(token1, single_gram));
+    delete single_gram;
+
     KMixtureModelMagicHeader magic_header;
     if (!bigram->get_magic_header(magic_header)){
         /* the first time to access the new k mixture model file. */
@@ -234,9 +238,6 @@ static bool train_second_word(KMixtureModelBigram * bigram,
     magic_header.m_WC += delta;
     assert(bigram->set_magic_header(magic_header));
 
-    /* save the single gram. */
-    assert(bigram->store(token1, single_gram));
-    delete single_gram;
     return true;
 }
 
@@ -252,7 +253,6 @@ static bool post_processing_unigram(KMixtureModelBigram * bigram,
         guint32 token = GPOINTER_TO_UINT(key);
         guint32 freq = GPOINTER_TO_UINT(value);
         KMixtureModelArrayHeader array_header;
-        memset(&array_header, 0, sizeof(KMixtureModelArrayHeader));
         bool result = bigram->get_array_header(token, array_header);
         array_header.m_freq += freq;
         total_freq += freq;
index 9dda1c2..50218c2 100644 (file)
@@ -122,11 +122,8 @@ typedef struct{
 } KMixtureModelMagicHeader;
 
 typedef struct{
-    /* dummy varibles */
-    guint32 dummy[3];
     /* the total number of instances of word W1. */
     guint32 m_WC;
-    guint32 dummy2[3];
     /* the freq of uni-gram. see m_total_freq in magic header also. */
     guint32 m_freq;
 } KMixtureModelArrayHeader;