[irstlm] 24/126: added a pseudo topi model for debugging purpose

Giulio Paci giuliopaci-guest at moszumanska.debian.org
Tue May 17 07:46:41 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 9ae612ea4ea880b84132fb521cd9e69b8f0fc3a0
Author: Nicola Bertoldi <bertoldi at fbk.eu>
Date:   Wed Jul 22 18:19:29 2015 +0200

    added a pseudo topi model for debugging purpose
---
 src/lmContextDependent.cpp | 26 +++++++++++++++++++++++---
 src/lmContextDependent.h   | 21 ++++++++++++++++++++-
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/src/lmContextDependent.cpp b/src/lmContextDependent.cpp
index 9beb720..83fd1ae 100644
--- a/src/lmContextDependent.cpp
+++ b/src/lmContextDependent.cpp
@@ -109,22 +109,43 @@ namespace irstlm {
 		
 		//loading topic model and initialization
 		m_topicmodel_weight = (float) atof(words[0]);
-		//m_topic_model = new  xxxxxxxxxxxxxxxx
+		m_topicmodel = new  PseudoTopicModel();
+		m_topicmodel->load(words[1]);
 		
 		inp.close();
 	}
 	
 	double lmContextDependent::lprob(ngram ng, topic_map_t& topic_weights, double* bow,int* bol,char** maxsuffptr,unsigned int* statesize,bool* extendible)
 	{
+		std::vector<std::string> text;   // replace with the text passed as parameter
 		double lm_prob = m_lm->clprob(ng, bow, bol, maxsuffptr, statesize, extendible);
-		double topic_prob = 0.0;  // to_CHECK
+		double topic_prob = m_topicmodel->prob(text, topic_weights);
 		double ret_prob = m_lm_weight * lm_prob + m_topicmodel_weight * topic_prob;
+		VERBOSE(0, "lm_prob:" << lm_prob << " m_lm_weight:" << m_lm_weight << " topic_prob:" << topic_prob << " m_topicmodel_weight:" << m_topicmodel_weight << " ret_prob:" << ret_prob << std::endl);
 		
 		return ret_prob;
 	}
 	
+	double lmContextDependent::lprob(std::vector<std::string>& text, topic_map_t& topic_weights, double* bow,int* bol,char** maxsuffptr,unsigned int* statesize,bool* extendible)
+	{
+		VERBOSE(0,"lmContextDependent::lprob(int* codes, int sz, topic_map_t& topic_weights, " << std::endl);
+		//create the actual ngram
+		ngram ng(dict);
+		ng.pushw(text);
+		MY_ASSERT (ng.size == text.size());
+		
+		double lm_prob = m_lm->clprob(ng, bow, bol, maxsuffptr, statesize, extendible);
+		double topic_prob = m_topicmodel->prob(text, topic_weights);
+		
+		double ret_prob = m_lm_weight * lm_prob + m_topicmodel_weight * topic_prob;
+		VERBOSE(0, "lm_prob:" << lm_prob << " m_lm_weight:" << m_lm_weight << " topic_prob:" << topic_prob << " m_topicmodel_weight:" << m_topicmodel_weight << " ret_prob:" << ret_prob << std::endl);
+		
+		return ret_prob;	
+	}
+	
 	double lmContextDependent::lprob(int* codes, int sz, topic_map_t& topic_weights, double* bow,int* bol,char** maxsuffptr,unsigned int* statesize,bool* extendible)
 	{
+		VERBOSE(0,"lmContextDependent::lprob(int* codes, int sz, topic_map_t& topic_weights, " << std::endl);
 		//create the actual ngram
 		ngram ong(dict);
 		ong.pushc(codes,sz);
@@ -132,7 +153,6 @@ namespace irstlm {
 		
 		return lprob(ong, topic_weights, bow, bol, maxsuffptr, statesize, extendible);	
 	}
-	
 	double lmContextDependent::setlogOOVpenalty(int dub)
 	{
 		MY_ASSERT(dub > dict->size());
diff --git a/src/lmContextDependent.h b/src/lmContextDependent.h
index 2ca6b9e..835338d 100644
--- a/src/lmContextDependent.h
+++ b/src/lmContextDependent.h
@@ -34,6 +34,23 @@
 #include "lmContainer.h"
 
 namespace irstlm {
+	class PseudoTopicModel
+	{
+	public:
+		PseudoTopicModel(){};
+		~PseudoTopicModel(){};
+		
+		void load(const std::string &filename){};
+		
+		double prob(std::vector<std::string>& text, topic_map_t& topic_weights){
+			UNUSED(text);
+			UNUSED(topic_weights);
+			return 1.0;
+		}
+	};
+}
+
+namespace irstlm {
 	/*
 	 Context-dependent LM
 	 Wrapper LM which combines a standard ngram-based word-based LM
@@ -44,6 +61,7 @@ namespace irstlm {
 	
 	class lmContextDependent: public lmContainer
 	{
+	private:
 		static const bool debug=true;
 		int order;
 		int dictionary_upperbound; //set by user
@@ -56,7 +74,7 @@ namespace irstlm {
 		bool m_isinverted;
 		
 		//  TopicModel* m_topicmodel;
-		lmContainer* m_topicmodel;   //to remove when TopicModel is ready
+		PseudoTopicModel* m_topicmodel;   //to remove when TopicModel is ready
 		double m_lm_weight;
 		
 		double m_topicmodel_weight;
@@ -106,6 +124,7 @@ namespace irstlm {
 		};
 		virtual double lprob(int* ng, int ngsize, topic_map_t& topic_weights, double* bow=NULL,int* bol=NULL,char** maxsuffptr=NULL,unsigned int* statesize=NULL,bool* extendible=NULL);
 		virtual double lprob(ngram ng, topic_map_t& topic_weights, double* bow=NULL,int* bol=NULL,char** maxsuffptr=NULL,unsigned int* statesize=NULL,bool* extendible=NULL);
+		virtual double lprob(std::vector<std::string>& text, topic_map_t& topic_weights, double* bow=NULL,int* bol=NULL,char** maxsuffptr=NULL,unsigned int* statesize=NULL,bool* extendible=NULL);
 		
 		int maxlevel() const {
 			return maxlev;

-- 
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