|
#ifndef LM_INTERPOLATE_MERGE_PROBABILITIES_H |
|
#define LM_INTERPOLATE_MERGE_PROBABILITIES_H |
|
|
|
#include "../common/ngram.hh" |
|
#include "bounded_sequence_encoding.hh" |
|
#include "../../util/fixed_array.hh" |
|
#include "../../util/stream/multi_stream.hh" |
|
|
|
#include <stdint.h> |
|
|
|
namespace lm { |
|
namespace interpolate { |
|
|
|
struct InterpolateInfo; |
|
|
|
|
|
|
|
|
|
|
|
BoundedSequenceEncoding MakeEncoder(const InterpolateInfo &info, uint8_t order); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MergeProbabilities { |
|
public: |
|
MergeProbabilities(const InterpolateInfo &info, util::FixedArray<util::stream::ChainPositions> &models_by_order) |
|
: info_(info), models_by_order_(models_by_order) {} |
|
|
|
void Run(const util::stream::ChainPositions &outputs); |
|
|
|
private: |
|
const InterpolateInfo &info_; |
|
util::FixedArray<util::stream::ChainPositions> &models_by_order_; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PartialProbGamma : public lm::NGramHeader { |
|
public: |
|
PartialProbGamma(std::size_t order, std::size_t backoff_bytes) |
|
: lm::NGramHeader(NULL, order), backoff_bytes_(backoff_bytes) { |
|
|
|
} |
|
|
|
std::size_t TotalSize() const { |
|
return sizeof(WordIndex) * Order() + sizeof(After) + backoff_bytes_; |
|
} |
|
|
|
|
|
static std::size_t TotalSize(const InterpolateInfo &info, uint8_t order) { |
|
return sizeof(WordIndex) * order + sizeof(After) + MakeEncoder(info, order).EncodedLength(); |
|
} |
|
|
|
float &Prob() { return Pay().prob; } |
|
float Prob() const { return Pay().prob; } |
|
|
|
float &LowerProb() { return Pay().lower_prob; } |
|
float LowerProb() const { return Pay().lower_prob; } |
|
|
|
const uint8_t *FromBegin() const { return Pay().from; } |
|
uint8_t *FromBegin() { return Pay().from; } |
|
|
|
private: |
|
struct After { |
|
|
|
float prob; |
|
float lower_prob; |
|
uint8_t from[]; |
|
}; |
|
const After &Pay() const { return *reinterpret_cast<const After *>(end()); } |
|
After &Pay() { return *reinterpret_cast<After*>(end()); } |
|
|
|
std::size_t backoff_bytes_; |
|
}; |
|
|
|
}} |
|
#endif |
|
|