TRF Language Model
|
TRF model. More...
#include <trf-model.h>
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... | |
Vocab * | GetVocab () 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 | |
Feat * | m_pFeat |
hash all the features More... | |
Vec< PValue > | m_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< Prob > | m_pi |
the prior length distribution More... | |
Vec< LogP > | m_logz |
the normalization constants log Z_l More... | |
Vec< LogP > | m_zeta |
the estimated normalization constants (fix = 0) More... | |
Vocab * | m_pVocab |
Mat< Prob > | m_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... | |
TRF model.
Definition at line 51 of file trf-model.h.
|
inline |
constructor
Definition at line 72 of file trf-model.h.
|
inline |
constructor
Definition at line 83 of file trf-model.h.
|
inline |
destructor
Definition at line 95 of file trf-model.h.
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.
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.
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.
|
virtual |
[exact] Exact Normalization, return the logz of given length
Reimplemented in hrf::Model.
Definition at line 213 of file trf-model.cpp.
|
virtual |
[exact] Exact Normalization
Reimplemented in hrf::Model.
Definition at line 237 of file trf-model.cpp.
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.
calculate the probability
Definition at line 74 of file trf-model.cpp.
[sample] given c_i, summate the probabilities of x_i, i.e. P(c_i)
Definition at line 456 of file trf-model.cpp.
|
inline |
Get max-len.
Definition at line 100 of file trf-model.h.
|
inline |
Get maximum order.
Definition at line 104 of file trf-model.h.
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.
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.
void trf::Model::GetParam | ( | PValue * | pValue | ) |
Get the paremetre vector.
Definition at line 64 of file trf-model.cpp.
|
inline |
Get parameter number.
Definition at line 106 of file trf-model.h.
[sample] A unnormalized reduced depending on nPos.
Definition at line 445 of file trf-model.cpp.
[sample] A unnormalized reduced model to sample class c_i.
Definition at line 419 of file trf-model.cpp.
[sample] A unnormalized reduced model to sample word w_i.
< containing word
Definition at line 434 of file trf-model.cpp.
|
inline |
Get Vocab.
Definition at line 102 of file trf-model.h.
|
inline |
Definition at line 126 of file trf-model.h.
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.
void trf::Model::LocalJump | ( | Seq & | seq | ) |
[sample] Local Jump - sample a new length
Definition at line 327 of file trf-model.cpp.
|
virtual |
[sample] Markov Move - perform the gibbs sampling
Reimplemented in trf::Model_FastSample.
Definition at line 372 of file trf-model.cpp.
[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.
[sample] Return the propose distribution of c_i at position nPos
Definition at line 406 of file trf-model.cpp.
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.
void trf::Model::ReadT | ( | const char * | pfilename | ) |
Read Model.
Definition at line 114 of file trf-model.cpp.
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.
void trf::Model::Sample | ( | Seq & | seq | ) |
[sample] Perform one train-dimensional mixture sampling
Definition at line 322 of file trf-model.cpp.
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.
[sample] Sample the x_i at position nPos
Definition at line 507 of file trf-model.cpp.
|
virtual |
void trf::Model::SetPi | ( | Prob * | pPi | ) |
Set the pi.
Definition at line 70 of file trf-model.cpp.
|
inline |
Set updated zeta.
Definition at line 117 of file trf-model.h.
void trf::Model::WriteT | ( | const char * | pfilename | ) |
Write Model.
Definition at line 158 of file trf-model.cpp.
|
protected |
the forward-backward calculation each node
Definition at line 68 of file trf-model.h.
the normalization constants log Z_l
Definition at line 59 of file trf-model.h.
[sample] used to propose a new length
Definition at line 64 of file trf-model.h.
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.
int trf::Model::m_maxSampleLen |
[sample] the maximum sample length, default = m_maxlen + 2
Definition at line 65 of file trf-model.h.
int trf::Model::m_nLenJumpAccTimes |
lenght jump the acceptance times
Definition at line 167 of file trf-model.h.
int trf::Model::m_nLenJumpTotalTime |
total times of length jump
Definition at line 168 of file trf-model.h.
int trf::Model::m_nSampleHAccTimes |
sample H the acceptance times
Definition at line 169 of file trf-model.h.
int trf::Model::m_nSampleHTotalTimes |
sample H the total times
Definition at line 170 of file trf-model.h.
Feat* trf::Model::m_pFeat |
hash all the features
Definition at line 54 of file trf-model.h.
the prior length distribution
Definition at line 58 of file trf-model.h.
Vocab* trf::Model::m_pVocab |
Definition at line 62 of file trf-model.h.
the value for each features
Definition at line 55 of file trf-model.h.
the estimated normalization constants (fix = 0)
Definition at line 60 of file trf-model.h.