Fix lattice mbr grid search so that the full lattice is created and pruned correctly.

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@2929 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
bhaddow 2010-02-22 23:42:35 +00:00
parent 0e16a9c3c5
commit 0ade2ac432
4 changed files with 10 additions and 6 deletions

View File

@ -77,6 +77,7 @@ void pruneLatticeFB(Lattice & connectedHyp, map < const Hypothesis*, set <const
const vector< float> & estimatedScores, size_t edgeDensity) {
//Need hyp 0 in connectedHyp - Find empty hypothesis
VERBOSE(2,"Pruning lattice to edge density " << edgeDensity << endl);
const Hypothesis* emptyHyp = connectedHyp.at(0);
while (emptyHyp->GetId() != 0) {
emptyHyp = emptyHyp->GetPrevHypo();
@ -113,6 +114,7 @@ void pruneLatticeFB(Lattice & connectedHyp, map < const Hypothesis*, set <const
size_t numEdgesTotal = edgeDensity * connectedHyp[0]->GetWordsBitmap().GetSize();
size_t numEdgesCreated = 0;
VERBOSE(2, "Target edge count: " << numEdgesTotal << endl);
float prevScore = -999999;
@ -200,7 +202,7 @@ void pruneLatticeFB(Lattice & connectedHyp, map < const Hypothesis*, set <const
connectedHyp.push_back(*it);
}
VERBOSE(3, "Done! Num edges created : "<< numEdgesCreated << ", numEdges wanted " << numEdgesTotal << endl)
VERBOSE(2, "Done! Num edges created : "<< numEdgesCreated << ", numEdges wanted " << numEdgesTotal << endl)
IFVERBOSE(3) {
cerr << "Surviving hyps: " ;

View File

@ -35,9 +35,9 @@ POSSIBILITY OF SUCH DAMAGE.
EMNLP 2008 for details of the parameters.
The grid search is controlled by specifying comma separated lists for the lmbr parameters (-lmbr-p, -lmbr-r,
-lmbr-pruning-factor and -mbr-size). All other parameters are passed through to moses. If any of the lattice mbr
-lmbr-pruning-factor and -mbr-scale). All other parameters are passed through to moses. If any of the lattice mbr
parameters are missing, then they are set to their default values. Output is of the form:
sentence-id ||| p r prune size ||| translation-hypothesis
sentence-id ||| p r prune scale ||| translation-hypothesis
**/
#include <cstdlib>
@ -69,7 +69,7 @@ class Grid {
/** Parse the arguments, removing those that define the grid and returning a copy of the rest */
void parseArgs(int& argc, char**& argv) {
char** newargv = new char*[argc];
char** newargv = new char*[argc+1]; //Space to add mbr parameter
int newargc = 0;
for (int i = 0; i < argc; ++i) {
bool consumed = false;
@ -148,6 +148,7 @@ int main(int argc, char* argv[]) {
}
StaticData& staticData = const_cast<StaticData&>(StaticData::Instance());
staticData.SetUseLatticeMBR(true);
IOWrapper* ioWrapper = GetIODevice(staticData);
if (!ioWrapper) {

View File

@ -412,7 +412,7 @@ void Hypothesis::CleanupArcList()
*/
const StaticData &staticData = StaticData::Instance();
size_t nBestSize = staticData.GetNBestSize();
bool distinctNBest = staticData.GetDistinctNBest() || staticData.UseMBR() || staticData.GetOutputSearchGraph();
bool distinctNBest = staticData.GetDistinctNBest() || staticData.UseMBR() || staticData.GetOutputSearchGraph() || staticData.UseLatticeMBR() ;
if (!distinctNBest && m_arcList->size() > nBestSize * 5)
{ // prune arc list only if there too many arcs

View File

@ -465,6 +465,7 @@ public:
size_t GetMaxNumFactors() const { return m_maxNumFactors; }
bool UseMBR() const { return m_mbr; }
bool UseLatticeMBR() const { return m_useLatticeMBR ;}
void SetUseLatticeMBR(bool flag) {m_useLatticeMBR = flag; }
size_t GetMBRSize() const { return m_mbrSize; }
float GetMBRScale() const { return m_mbrScale; }
void SetMBRScale(float scale) {
@ -472,7 +473,7 @@ public:
}
size_t GetLatticeMBRPruningFactor() const { return m_lmbrPruning; }
void SetLatticeMBRPruningFactor(size_t prune) {
prune = m_lmbrPruning;
m_lmbrPruning = prune;
}
const std::vector<float>& GetLatticeMBRThetas() const {return m_lmbrThetas;}
bool UseLatticeHypSetForLatticeMBR() const { return m_useLatticeHypSetForLatticeMBR;}