TRF Language Model
trf::Model Class Reference

TRF model. More...

#include <trf-model.h>

Inheritance diagram for trf::Model:
hrf::Model trf::Model_FastSample

Public Member Functions

 Model (Vocab *pv)
 constructor More...
 
 Model (Vocab *pv, int maxlen)
 constructor More...
 
 ~Model ()
 destructor More...
 
int GetMaxLen () const
 Get max-len. More...
 
VocabGetVocab () const
 Get Vocab. More...
 
int GetMaxOrder () const
 Get maximum order. More...
 
int GetParamNum () const
 Get parameter number. More...
 
void Reset (Vocab *pv, int maxlen)
 reset, the maxlen is the length excluding the beg/end symbols. More...
 
virtual void SetParam (PValue *pValue)
 Set the parameters. More...
 
void GetParam (PValue *pValue)
 Get the paremetre vector. More...
 
void SetPi (Prob *pPi)
 Set the pi. More...
 
template<typename T >
void SetZeta (T *pzeta)
 Set updated zeta. More...
 
template<typename T >
void GetZeta (T *pzeta)
 
LogP GetLogProb (Seq &seq, bool bNorm=true)
 calculate the probability More...
 
void LoadFromCorpus (const char *pcorpus, const char *pfeatstyle, int nOrder)
 load ngram features from corpus More...
 
void FeatCount (Seq &seq, double *pCount, double dadd=1.0)
 Count the feature number in a sequence. More...
 
void ReadT (const char *pfilename)
 Read Model. More...
 
void WriteT (const char *pfilename)
 Write Model. More...
 
LogP ClusterSum (Seq &seq, int nPos, int nOrder)
 Read Binary. More...
 
virtual double ExactNormalize (int nLen)
 [exact] Exact Normalization, return the logz of given length More...
 
virtual void ExactNormalize ()
 [exact] Exact Normalization More...
 
void GetNodeExp (int nLen, double *pExp)
 [exact] E_{p_l}[f]: Exactly calculate the expectation over x and h for length nLen More...
 
void GetNodeExp (double *pExp, Prob *pLenProb=NULL)
 [exact] sum_l { n_l/n * E_{p_l}[f] }: Exactly calculate the expectation over x and h More...
 
void Sample (Seq &seq)
 [sample] Perform one train-dimensional mixture sampling More...
 
void LocalJump (Seq &seq)
 [sample] Local Jump - sample a new length More...
 
virtual void MarkovMove (Seq &seq)
 [sample] Markov Move - perform the gibbs sampling More...
 
LogP ProposeLength (int nOld, int &nNew, bool bSample)
 [sample] Propose the length, using the variable m_matLenJump More...
 
LogP ProposeC0 (VocabID &ci, Seq &seq, int nPos, bool bSample)
 [sample] Propose the c_{i} at position i. Then return the propose probability R(c_i|h_i,c_{other}) More...
 
void ProposeCProbs (VecShell< LogP > &logps, Seq &seq, int nPos)
 [sample] Return the propose distribution of c_i at position nPos More...
 
LogP GetReducedModelForC (Seq &seq, int nPos)
 [sample] A unnormalized reduced model to sample class c_i. More...
 
LogP GetReducedModelForW (Seq &seq, int nPos)
 [sample] A unnormalized reduced model to sample word w_i. More...
 
LogP GetReducedModel (Seq &seq, int nPos)
 [sample] A unnormalized reduced depending on nPos. More...
 
LogP GetMarginalProbOfC (Seq &seq, int nPos)
 [sample] given c_i, summate the probabilities of x_i, i.e. P(c_i) More...
 
void SampleC (Seq &seq, int nPos)
 [sample] Sample the c_i at position nPos without x_i. More...
 
LogP SampleX (Seq &seq, int nPos, bool bSample=true)
 [sample] Sample the x_i at position nPos More...
 
LogP AISNormalize (int nLen, int nChain, int nInter)
 perform AIS to calculate the normalization constants, return the logz of given length More...
 
void AISNormalize (int nLenMin, int nLenMax, int nChain, int nInter)
 

Public Attributes

Featm_pFeat
 hash all the features More...
 
Vec< PValuem_value
 the value for each features More...
 
int m_maxlen
 the maximum length of model, excluding <s> and </s>. The min-len = 1 More...
 
Vec< Probm_pi
 the prior length distribution More...
 
Vec< LogPm_logz
 the normalization constants log Z_l More...
 
Vec< LogPm_zeta
 the estimated normalization constants (fix = 0) More...
 
Vocabm_pVocab
 
Mat< Probm_matLenJump
 [sample] used to propose a new length More...
 
int m_maxSampleLen
 [sample] the maximum sample length, default = m_maxlen + 2 More...
 
int m_nLenJumpAccTimes
 lenght jump the acceptance times More...
 
int m_nLenJumpTotalTime
 total times of length jump More...
 
int m_nSampleHAccTimes
 sample H the acceptance times More...
 
int m_nSampleHTotalTimes
 

Protected Attributes

AlgNode m_AlgNode
 the forward-backward calculation each node More...
 

Detailed Description

TRF model.

Definition at line 51 of file trf-model.h.

Constructor & Destructor Documentation

§ Model() [1/2]

trf::Model::Model ( Vocab pv)
inline

constructor

Definition at line 72 of file trf-model.h.

§ Model() [2/2]

trf::Model::Model ( Vocab pv,
int  maxlen 
)
inline

constructor

Definition at line 83 of file trf-model.h.

§ ~Model()

trf::Model::~Model ( )
inline

destructor

Definition at line 95 of file trf-model.h.

Member Function Documentation

§ AISNormalize() [1/2]

LogP trf::Model::AISNormalize ( int  nLen,
int  nChain,
int  nInter 
)

perform AIS to calculate the normalization constants, return the logz of given length

Definition at line 550 of file trf-model.cpp.

§ AISNormalize() [2/2]

void trf::Model::AISNormalize ( int  nLenMin,
int  nLenMax,
int  nChain,
int  nInter 
)

< record the log-prob for each word at each position

normalize, for the following sampling

Definition at line 631 of file trf-model.cpp.

§ ClusterSum()

LogP trf::Model::ClusterSum ( Seq seq,
int  nPos,
int  nOrder 
)

Read Binary.

[exact] Calculate the logP in each cluster. Only used for forward-backword algorithms ( class AlgNode)

Definition at line 185 of file trf-model.cpp.

§ ExactNormalize() [1/2]

double trf::Model::ExactNormalize ( int  nLen)
virtual

[exact] Exact Normalization, return the logz of given length

Reimplemented in hrf::Model.

Definition at line 213 of file trf-model.cpp.

§ ExactNormalize() [2/2]

void trf::Model::ExactNormalize ( )
virtual

[exact] Exact Normalization

Reimplemented in hrf::Model.

Definition at line 237 of file trf-model.cpp.

§ FeatCount()

void trf::Model::FeatCount ( Seq seq,
double *  pCount,
double  dadd = 1.0 
)

Count the feature number in a sequence.

Definition at line 106 of file trf-model.cpp.

§ GetLogProb()

LogP trf::Model::GetLogProb ( Seq seq,
bool  bNorm = true 
)

calculate the probability

Definition at line 74 of file trf-model.cpp.

§ GetMarginalProbOfC()

LogP trf::Model::GetMarginalProbOfC ( Seq seq,
int  nPos 
)

[sample] given c_i, summate the probabilities of x_i, i.e. P(c_i)

Definition at line 456 of file trf-model.cpp.

§ GetMaxLen()

int trf::Model::GetMaxLen ( ) const
inline

Get max-len.

Definition at line 100 of file trf-model.h.

§ GetMaxOrder()

int trf::Model::GetMaxOrder ( ) const
inline

Get maximum order.

Definition at line 104 of file trf-model.h.

§ GetNodeExp() [1/2]

void trf::Model::GetNodeExp ( int  nLen,
double *  pExp 
)

[exact] E_{p_l}[f]: Exactly calculate the expectation over x and h for length nLen

Definition at line 245 of file trf-model.cpp.

§ GetNodeExp() [2/2]

void trf::Model::GetNodeExp ( double *  pExp,
Prob pLenProb = NULL 
)

[exact] sum_l { n_l/n * E_{p_l}[f] }: Exactly calculate the expectation over x and h

< max-order

Definition at line 301 of file trf-model.cpp.

§ GetParam()

void trf::Model::GetParam ( PValue pValue)

Get the paremetre vector.

Definition at line 64 of file trf-model.cpp.

§ GetParamNum()

int trf::Model::GetParamNum ( ) const
inline

Get parameter number.

Definition at line 106 of file trf-model.h.

§ GetReducedModel()

LogP trf::Model::GetReducedModel ( Seq seq,
int  nPos 
)

[sample] A unnormalized reduced depending on nPos.

Definition at line 445 of file trf-model.cpp.

§ GetReducedModelForC()

LogP trf::Model::GetReducedModelForC ( Seq seq,
int  nPos 
)

[sample] A unnormalized reduced model to sample class c_i.

Definition at line 419 of file trf-model.cpp.

§ GetReducedModelForW()

LogP trf::Model::GetReducedModelForW ( Seq seq,
int  nPos 
)

[sample] A unnormalized reduced model to sample word w_i.

< containing word

Definition at line 434 of file trf-model.cpp.

§ GetVocab()

Vocab* trf::Model::GetVocab ( ) const
inline

Get Vocab.

Definition at line 102 of file trf-model.h.

§ GetZeta()

template<typename T >
void trf::Model::GetZeta ( T *  pzeta)
inline

Definition at line 126 of file trf-model.h.

§ LoadFromCorpus()

void trf::Model::LoadFromCorpus ( const char *  pcorpus,
const char *  pfeatstyle,
int  nOrder 
)

load ngram features from corpus

Definition at line 95 of file trf-model.cpp.

§ LocalJump()

void trf::Model::LocalJump ( Seq seq)

[sample] Local Jump - sample a new length

Definition at line 327 of file trf-model.cpp.

§ MarkovMove()

void trf::Model::MarkovMove ( Seq seq)
virtual

[sample] Markov Move - perform the gibbs sampling

Reimplemented in trf::Model_FastSample.

Definition at line 372 of file trf-model.cpp.

§ ProposeC0()

LogP trf::Model::ProposeC0 ( VocabID ci,
Seq seq,
int  nPos,
bool  bSample 
)

[sample] Propose the c_{i} at position i. Then return the propose probability R(c_i|h_i,c_{other})

Definition at line 389 of file trf-model.cpp.

§ ProposeCProbs()

void trf::Model::ProposeCProbs ( VecShell< LogP > &  logps,
Seq seq,
int  nPos 
)

[sample] Return the propose distribution of c_i at position nPos

Definition at line 406 of file trf-model.cpp.

§ ProposeLength()

LogP trf::Model::ProposeLength ( int  nOld,
int &  nNew,
bool  bSample 
)

[sample] Propose the length, using the variable m_matLenJump

Definition at line 381 of file trf-model.cpp.

§ ReadT()

void trf::Model::ReadT ( const char *  pfilename)

Read Model.

Definition at line 114 of file trf-model.cpp.

§ Reset()

void trf::Model::Reset ( Vocab pv,
int  maxlen 
)

reset, the maxlen is the length excluding the beg/end symbols.

Definition at line 28 of file trf-model.cpp.

§ Sample()

void trf::Model::Sample ( Seq seq)

[sample] Perform one train-dimensional mixture sampling

Definition at line 322 of file trf-model.cpp.

§ SampleC()

void trf::Model::SampleC ( Seq seq,
int  nPos 
)

[sample] Sample the c_i at position nPos without x_i.

Definition at line 474 of file trf-model.cpp.

§ SampleX()

LogP trf::Model::SampleX ( Seq seq,
int  nPos,
bool  bSample = true 
)

[sample] Sample the x_i at position nPos

Definition at line 507 of file trf-model.cpp.

§ SetParam()

void trf::Model::SetParam ( PValue pValue)
virtual

Set the parameters.

Reimplemented in hrf::Model.

Definition at line 58 of file trf-model.cpp.

§ SetPi()

void trf::Model::SetPi ( Prob pPi)

Set the pi.

Definition at line 70 of file trf-model.cpp.

§ SetZeta()

template<typename T >
void trf::Model::SetZeta ( T *  pzeta)
inline

Set updated zeta.

Definition at line 117 of file trf-model.h.

§ WriteT()

void trf::Model::WriteT ( const char *  pfilename)

Write Model.

Definition at line 158 of file trf-model.cpp.

Member Data Documentation

§ m_AlgNode

AlgNode trf::Model::m_AlgNode
protected

the forward-backward calculation each node

Definition at line 68 of file trf-model.h.

§ m_logz

Vec<LogP> trf::Model::m_logz

the normalization constants log Z_l

Definition at line 59 of file trf-model.h.

§ m_matLenJump

Mat<Prob> trf::Model::m_matLenJump

[sample] used to propose a new length

Definition at line 64 of file trf-model.h.

§ m_maxlen

int trf::Model::m_maxlen

the maximum length of model, excluding <s> and </s>. The min-len = 1

Definition at line 57 of file trf-model.h.

§ m_maxSampleLen

int trf::Model::m_maxSampleLen

[sample] the maximum sample length, default = m_maxlen + 2

Definition at line 65 of file trf-model.h.

§ m_nLenJumpAccTimes

int trf::Model::m_nLenJumpAccTimes

lenght jump the acceptance times

Definition at line 167 of file trf-model.h.

§ m_nLenJumpTotalTime

int trf::Model::m_nLenJumpTotalTime

total times of length jump

Definition at line 168 of file trf-model.h.

§ m_nSampleHAccTimes

int trf::Model::m_nSampleHAccTimes

sample H the acceptance times

Definition at line 169 of file trf-model.h.

§ m_nSampleHTotalTimes

int trf::Model::m_nSampleHTotalTimes

sample H the total times

Definition at line 170 of file trf-model.h.

§ m_pFeat

Feat* trf::Model::m_pFeat

hash all the features

Definition at line 54 of file trf-model.h.

§ m_pi

Vec<Prob> trf::Model::m_pi

the prior length distribution

Definition at line 58 of file trf-model.h.

§ m_pVocab

Vocab* trf::Model::m_pVocab

Definition at line 62 of file trf-model.h.

§ m_value

Vec<PValue> trf::Model::m_value

the value for each features

Definition at line 55 of file trf-model.h.

§ m_zeta

Vec<LogP> trf::Model::m_zeta

the estimated normalization constants (fix = 0)

Definition at line 60 of file trf-model.h.


The documentation for this class was generated from the following files: