[irstlm] 39/126: code cleanup ; bug fixed
Giulio Paci
giuliopaci-guest at moszumanska.debian.org
Tue May 17 07:46:43 UTC 2016
This is an automated email from the git hooks/post-receive script.
giuliopaci-guest pushed a commit to annotated tag adaptiveLM.v0.1
in repository irstlm.
commit d2234bbebb9204d2986d81865b635fa6296376f1
Author: Nicola Bertoldi <bertoldi at fbk.eu>
Date: Mon Aug 3 12:41:02 2015 +0200
code cleanup ; bug fixed
---
src/context-dependent-evaluation.cpp | 33 ++++++++++++++-------------------
src/context-similarity.cpp | 13 ++++++-------
src/lmContextDependent.cpp | 10 ++++++++--
3 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/src/context-dependent-evaluation.cpp b/src/context-dependent-evaluation.cpp
index 9a3cf1e..18de5da 100644
--- a/src/context-dependent-evaluation.cpp
+++ b/src/context-dependent-evaluation.cpp
@@ -170,7 +170,7 @@ int main(int argc, char **argv)
std::string line_str = line;
- VERBOSE(0,"line_str:|" << line_str << "|" << std::endl);
+ VERBOSE(1,"input_line:|" << line_str << "|" << std::endl);
//getting sentence string;
std::string sentence;
@@ -178,9 +178,8 @@ int main(int argc, char **argv)
((lmContextDependent*) lmt)->GetSentenceAndContext(sentence,context,line_str);
- VERBOSE(0,"sentence:|" << sentence << "|" << std::endl);
- VERBOSE(0,"context:|" << context << "|" << std::endl);
- VERBOSE(0,"line_str:|" << line_str << "|" << std::endl);
+ VERBOSE(1,"sentence:|" << sentence << "|" << std::endl);
+ VERBOSE(1,"context:|" << context << "|" << std::endl);
//getting apriori topic weights
topic_map_t apriori_topic_map;
@@ -201,7 +200,7 @@ int main(int argc, char **argv)
topic_map_t sentence_topic_map;
- VERBOSE(0,"word_vec.size():|" << word_vec.size() << "|" << std::endl);
+ VERBOSE(1,"word_vec.size():|" << word_vec.size() << "|" << std::endl);
for (size_t i=0; i<word_vec.size(); ++i){
++size;
size=(size<order)?size:order;
@@ -213,7 +212,7 @@ int main(int argc, char **argv)
}
first = last - size;
- VERBOSE(0,"topic scores for first:|" << first << "| last:|" << last << "| size:" << size << std::endl);
+ VERBOSE(2,"topic scores for first:|" << first << "| last:|" << last << "| size:" << size << std::endl);
string_vec_t tmp_word_vec(word_vec.begin() + first, word_vec.begin() +last);
if (size>=1) {
@@ -235,7 +234,6 @@ int main(int argc, char **argv)
apriori_topic_map.clear();
}
-
delete lmt;
return 0;
}
@@ -278,16 +276,15 @@ int main(int argc, char **argv)
std::string line_str = line;
- VERBOSE(0,"line_str:|" << line_str << "|" << std::endl);
+ VERBOSE(1,"input_line:|" << line_str << "|" << std::endl);
//getting sentence string;
std::string sentence;
std::string context;
((lmContextDependent*) lmt)->GetSentenceAndContext(sentence,context,line_str);
- VERBOSE(0,"sentence:|" << sentence << "|" << std::endl);
- VERBOSE(0,"context:|" << context << "|" << std::endl);
- VERBOSE(0,"line_str:|" << line_str << "|" << std::endl);
+ VERBOSE(1,"sentence:|" << sentence << "|" << std::endl);
+ VERBOSE(1,"context:|" << context << "|" << std::endl);
//getting apriori topic weights
topic_map_t apriori_topic_map;
@@ -305,7 +302,7 @@ int main(int argc, char **argv)
size_t size=0;
size_t order = lmt->maxlevel();
- VERBOSE(0,"word_vec.size():|" << word_vec.size() << "|" << std::endl);
+ VERBOSE(1,"word_vec.size():|" << word_vec.size() << "|" << std::endl);
for (size_t i=0; i<word_vec.size(); ++i){
++size;
size=(size<order)?size:order;
@@ -317,22 +314,22 @@ int main(int argc, char **argv)
}
first = last - size;
- VERBOSE(0,"prob for first:|" << first << "| last:|" << last << "| size:" << size << std::endl);
+ VERBOSE(2,"prob for first:|" << first << "| last:|" << last << "| size:" << size << std::endl);
string_vec_t tmp_word_vec(word_vec.begin() + first, word_vec.begin() +last);
if (size>=1) {
- VERBOSE(0,"computing prob for first:|" << first << "| and last:|" << last << "|" << std::endl);
+ VERBOSE(2,"computing prob for first:|" << first << "| and last:|" << last << "|" << std::endl);
Pr=lmt->clprob(tmp_word_vec, apriori_topic_map, &bow, &bol, &msp, &statesize);
- VERBOSE(0," --> prob for first:|" << first << "| and last:|" << last << "| is Pr=" << Pr << std::endl);
+ VERBOSE(2," --> prob for first:|" << first << "| and last:|" << last << "| is Pr=" << Pr << std::endl);
logPr+=Pr;
sent_logPr+=Pr;
- VERBOSE(0,"sent_logPr:|" << sent_logPr << " logPr:|" << logPr << std::endl);
+ VERBOSE(2,"sent_logPr:|" << sent_logPr << " logPr:|" << logPr << std::endl);
if (debug==1) {
std::cout << "first:|" << first << "| and last:| [" << size-bol << "]" << " " << std::endl;
}
- VERBOSE(0,"word_vec.at(i):|" << word_vec.at(i) << " lmt->getDict()->OOV():|" << lmt->getDict()->OOV() << std::endl);
+ VERBOSE(2,"word_vec.at(i):|" << word_vec.at(i) << " lmt->getDict()->OOV():|" << lmt->getDict()->OOV() << std::endl);
if (lmt->getDict()->encode(word_vec.at(i).c_str()) == lmt->getDict()->oovcode()) {
Noov++;
sent_Noov++;
@@ -363,8 +360,6 @@ int main(int argc, char **argv)
sent_logPr=0.0;
}
-
-
apriori_topic_map.clear();
}
diff --git a/src/context-similarity.cpp b/src/context-similarity.cpp
index cc86337..65d53df 100644
--- a/src/context-similarity.cpp
+++ b/src/context-similarity.cpp
@@ -77,13 +77,9 @@ namespace irstlm {
double ContextSimilarity::score(string_vec_t& text, topic_map_t& topic_weights)
{
VERBOSE(4, "double ContextSimilarity::score(string_vec_t& text, topic_map_t& topic_weights)" << std::endl);
- double ret_logprob = SIMILARITY_LOWER_BOUND;
+ double ret_logprob;
- if (topic_weights.size() == 0){
- //a-priori topic distribution is "empty", i.e. there is nore score for any topic
- //return a "constant" lower-bound score, SIMILARITY_LOWER_BOUND = log(0.0)
- ret_logprob = SIMILARITY_LOWER_BOUND;
- }else{
+ if (topic_weights.size() > 0){
ngram base_num_ng(m_num_lm->getDict());
ngram base_den_ng(m_den_lm->getDict());
@@ -105,9 +101,12 @@ namespace irstlm {
}
VERBOSE(4, "CURRENT ret_logprob:" << ret_logprob << std::endl);
}
+ }else{
+ //a-priori topic distribution is "empty", i.e. there is nore score for any topic
+ //return a "constant" lower-bound score, SIMILARITY_LOWER_BOUND = log(0.0)
+ ret_logprob = SIMILARITY_LOWER_BOUND;
}
-
VERBOSE(3, "ret_logprob:" << ret_logprob << std::endl);
return ret_logprob;
}
diff --git a/src/lmContextDependent.cpp b/src/lmContextDependent.cpp
index dc8e768..34e4640 100644
--- a/src/lmContextDependent.cpp
+++ b/src/lmContextDependent.cpp
@@ -144,7 +144,10 @@ namespace irstlm {
string_vec_t text; // replace with the text passed as parameter
double lm_logprob = m_lm->clprob(ng, bow, bol, maxsuffptr, statesize, extendible);
double similarity_score = m_similaritymodel->score(text, topic_weights);
- double ret_logprob = lm_logprob + m_similaritymodel_weight * similarity_score;
+ double ret_logprob = lm_logprob;
+ if (similarity_score != SIMILARITY_LOWER_BOUND){
+ ret_logprob += m_similaritymodel_weight * similarity_score;
+ }
VERBOSE(0, "lm_logprob:" << lm_logprob << " similarity_score:" << similarity_score << " m_similaritymodel_weight:" << m_similaritymodel_weight << " ret_logprob:" << ret_logprob << std::endl);
return ret_logprob;
@@ -161,7 +164,10 @@ namespace irstlm {
MY_ASSERT (ng.size == (int) text.size());
double lm_logprob = m_lm->clprob(ng, bow, bol, maxsuffptr, statesize, extendible);
double similarity_score = m_similaritymodel->score(text, topic_weights);
- double ret_logprob = lm_logprob + m_similaritymodel_weight * similarity_score;
+ double ret_logprob = lm_logprob;
+ if (similarity_score != SIMILARITY_LOWER_BOUND){
+ ret_logprob += m_similaritymodel_weight * similarity_score;
+ }
VERBOSE(0, "lm_logprob:" << lm_logprob << " similarity_score:" << similarity_score << " m_similaritymodel_weight:" << m_similaritymodel_weight << " ret_logprob:" << ret_logprob << std::endl);
return ret_logprob;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/irstlm.git
More information about the debian-science-commits
mailing list