Skip to content
Snippets Groups Projects
Commit a71b3228 authored by Franck Dary's avatar Franck Dary
Browse files

beam collapse after every new sentence

parent ad1bcae0
No related branches found
No related tags found
No related merge requests found
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include "ProgramOutput.hpp" #include "ProgramOutput.hpp"
#include <chrono> #include <chrono>
//TODO : Faire se rejoindre les beam en debut de phrase, et faire la moyenne de totalentropy sur le nb d'actions de la phrase.
Decoder::Decoder(TransitionMachine & tm, Config & config) Decoder::Decoder(TransitionMachine & tm, Config & config)
: tm(tm), config(config) : tm(tm), config(config)
{ {
...@@ -181,10 +179,20 @@ struct BeamNode ...@@ -181,10 +179,20 @@ struct BeamNode
TransitionMachine tm; TransitionMachine tm;
Config config; Config config;
Action * action; Action * action;
int nbActions;
double getEntropy()
{
if (nbActions == 0)
return 0.0;
return totalEntropy / nbActions;
}
BeamNode(TransitionMachine & tm, Config & config) : tm(tm), config(config) BeamNode(TransitionMachine & tm, Config & config) : tm(tm), config(config)
{ {
totalEntropy = 0.0; totalEntropy = 0.0;
nbActions = 0;
config.setOutputFile(nullptr); config.setOutputFile(nullptr);
config.totalEntropy = totalEntropy; config.totalEntropy = totalEntropy;
} }
...@@ -192,6 +200,7 @@ struct BeamNode ...@@ -192,6 +200,7 @@ struct BeamNode
{ {
totalEntropy = other.totalEntropy + proba; totalEntropy = other.totalEntropy + proba;
this->action = action; this->action = action;
nbActions = other.nbActions + 1;
config.setOutputFile(nullptr); config.setOutputFile(nullptr);
config.totalEntropy = totalEntropy; config.totalEntropy = totalEntropy;
} }
...@@ -285,7 +294,7 @@ void Decoder::decodeBeam() ...@@ -285,7 +294,7 @@ void Decoder::decodeBeam()
{ {
std::sort(beam.begin(), beam.end(), [](std::shared_ptr<BeamNode> a, std::shared_ptr<BeamNode> b) std::sort(beam.begin(), beam.end(), [](std::shared_ptr<BeamNode> a, std::shared_ptr<BeamNode> b)
{ {
return a->totalEntropy > b->totalEntropy; return a->getEntropy() > b->getEntropy();
}); });
}; };
...@@ -355,6 +364,17 @@ void Decoder::decodeBeam() ...@@ -355,6 +364,17 @@ void Decoder::decodeBeam()
computeAndPrintSequenceEntropy(config, justFlipped, errors, entropyAccumulator, nbActionsInSequence); computeAndPrintSequenceEntropy(config, justFlipped, errors, entropyAccumulator, nbActionsInSequence);
} }
} }
if (justFlipped)
{
beam.resize(std::min(1,(int)beam.size()));
if (!beam.empty())
{
beam[0]->totalEntropy = 0.0;
beam[0]->config.totalEntropy = 0.0;
beam[0]->nbActions = 0;
}
}
} }
if (ProgramParameters::errorAnalysis) if (ProgramParameters::errorAnalysis)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment