21 const double & lambda_;
26 void backoff (std::string & context) {
27 size_t pos = context.find_first_not_of(
" ");
28 pos = context.find_first_of(
" ", pos);
29 if (pos == std::string::npos)
32 context = context.substr(pos);
44 : f_(f), V_(f.V()), lambda_(lambda) {}
56 double operator() (
const std::string & word, std::string context)
58 double kgram_count, penalization = 1.;
59 size_t n_backoffs = 0;
60 while ((kgram_count = f_.
query(context +
" " + word)) == 0) {
62 penalization *= lambda_;
64 if (n_backoffs > f_.
N() - 1)
67 return penalization * kgram_count / f_.
query(context);
90 : f_(f), V_(f.V()), k_(k) {}
102 double operator() (
const std::string & word, std::string context)
104 double num = f_.
query(context +
" " + word) + k_;
105 double den = f_.
query(context) + k_ * (V_ + 2);
138 double operator() (
const std::string & word, std::string context)
140 double den = f_.
query(context);
144 return f_.
query(context +
" " + word) / den;
size_t N() const
Maximum order of k-grams.
Definition: kgramFreqs.h:99
Maximum-Likelihood continuation probability smoother.
Definition: Smoothers.h:114
MLSmoother(kgramFreqs &f)
Initialize an AddkSmoother from a kgramFreqs object with a fixed constant 'k'.
Definition: Smoothers.h:125
double operator()(const std::string &word, std::string context)
Return Add-k continuation probability of a word given a context.
Definition: Smoothers.h:102
Definition of kgramFreqs class.
SBOSmoother(kgramFreqs &f, const double &lambda)
Initialize a SBOSmoother from a kgramFreqs object with a fixed backoff penalization.
Definition: Smoothers.h:43
AddkSmoother(kgramFreqs &f, const double &k)
Initialize an AddkSmoother from a kgramFreqs object with a fixed constant 'k'.
Definition: Smoothers.h:89
double operator()(const std::string &word, std::string context)
Return Stupid Backoff continuation score of a word given a context.
Definition: Smoothers.h:56
Stupid Backoff continuation probability smoother.
Definition: Smoothers.h:16
double operator()(const std::string &word, std::string context)
Return Maximum-Likelihood continuation probability of a word given a context.
Definition: Smoothers.h:138
Sample sequences from a k-gram language model.
Definition: Sampler.h:15
double query(std::string) const
Retrieve counts for a given k-gram.
Definition: kgramFreqs.cpp:82
Add-k continuation probability smoother.
Definition: Smoothers.h:75
Store k-gram frequency counts in hash tables
Definition: kgramFreqs.h:20