-
Notifications
You must be signed in to change notification settings - Fork 0
/
RescoreModule.cpp
76 lines (58 loc) · 1.68 KB
/
RescoreModule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* RescoreModule.cpp
*
* Created on: Feb 21, 2017
* Author: louis
*/
#include "RescoreModule.h"
#include "Logging.h"
namespace SLM {
RescoreModule::RescoreModule(SLM::BackoffStrategy* bo, const std::string& outputDirectory)
: backoffStrategy(bo), outputDirectory(outputDirectory)
{
// TODO Auto-generated constructor stub
}
RescoreModule::~RescoreModule() {
// TODO Auto-generated destructor stub
}
void RescoreModule::nextFile(const std::string& originalFileName)
{
this->originalFileName = originalFileName;
nbestList = SLM::NBestList();
}
void RescoreModule::addLine(const std::string& originalSentenceString, int originalRank, double acousticModelScore, double languageModelScore, int numberOfWords)
{
currentLine = new SLM::NBestItem(originalSentenceString, originalRank, acousticModelScore, languageModelScore, numberOfWords);
lprob = 0.0;
oovs = 0;
usedPatternsForLine = 0;
}
void RescoreModule::rescoreLine()
{
L_V << "RescoreModule: rescore ppl =" << pow(2, (-lprob)/usedPatternsForLine) << " P:" << lprob << " U:" << usedPatternsForLine << "\n";
// currentLine->setRescore(pow(2, lprob/usedPatternsForLine));
currentLine->setRescore(lprob);
nbestList.add(currentLine);
}
void RescoreModule::rescoreFile()
{
nbestList.determineNewRanks();
nbestList.printToFile(originalFileName, outputDirectory);
}
void RescoreModule::evaluatePattern(const Pattern& focus, const Pattern& context, bool isOOV)
{
double prob = backoffStrategy->prob(context, focus, isOOV);
if(isOOV)
{
L_P << "RescoreModule: ***";
++oovs;
} else
{
L_P << "RescoreModule: ";
++usedPatterns;
++usedPatternsForLine;
lprob += prob;
}
L_P << "prob =" << prob << "\n";
}
} /* namespace SLM */