add shallow fusion (#147)

This commit is contained in:
PF Luo
2023-05-10 22:30:57 +08:00
committed by GitHub
parent 7969cf44ac
commit 824b0809a4
9 changed files with 104 additions and 125 deletions

View File

@@ -22,21 +22,27 @@ class OnlineRnnLM : public OnlineLM {
explicit OnlineRnnLM(const OnlineLMConfig &config);
std::vector<Ort::Value> GetInitStates() override;
std::pair<Ort::Value, std::vector<Ort::Value>> GetInitStates() override;
/** Rescore a batch of sentences.
/** ScoreToken a batch of sentences.
*
* @param x A 2-D tensor of shape (N, L) with data type int64.
* @param y A 2-D tensor of shape (N, L) with data type int64.
* @param states It contains the states for the LM model
* @return Return a pair containingo
* - negative loglike
* - log_prob of NN LM
* - updated states
*
* Caution: It returns negative log likelihood (nll), not log likelihood
*/
std::pair<Ort::Value, std::vector<Ort::Value>> Rescore(
Ort::Value x, Ort::Value y, std::vector<Ort::Value> states) override;
std::pair<Ort::Value, std::vector<Ort::Value>> ScoreToken(
Ort::Value x, std::vector<Ort::Value> states) override;
/** This function updates lm_lob_prob and nn_lm_scores of hyp
*
* @param scale LM score
* @param hyps It is changed in-place.
*
*/
void ComputeLMScore(float scale, Hypothesis *hyp) override;
private:
class Impl;