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

Corrected bug where splittransitions were always no appliable

parent ed05ee4a
No related branches found
No related tags found
No related merge requests found
......@@ -41,11 +41,12 @@ void Beam::update(ReadingMachine & machine, bool debug)
classifier.setState(elements[index].config.getState());
auto appliableTransitions = machine.getTransitionSet().getAppliableTransitions(elements[index].config);
elements[index].config.setAppliableTransitions(appliableTransitions);
if (machine.hasSplitWordTransitionSet())
elements[index].config.setAppliableSplitTransitions(machine.getSplitWordTransitionSet().getNAppliableTransitions(elements[index].config, Config::maxNbAppliableSplitTransitions));
auto appliableTransitions = machine.getTransitionSet().getAppliableTransitions(elements[index].config);
elements[index].config.setAppliableTransitions(appliableTransitions);
auto context = classifier.getNN()->extractContext(elements[index].config).back();
auto neuralInput = torch::from_blob(context.data(), {(long)context.size()}, torch::kLong).clone().to(NeuralNetworkImpl::device);
auto prediction = torch::softmax(classifier.getNN()(neuralInput).squeeze(), 0);
......
......@@ -44,6 +44,7 @@ class Action
static Action addHypothesis(const std::string & colName, std::size_t lineIndex, const std::string & hypothesis);
static Action addToHypothesis(const std::string & colName, std::size_t lineIndex, const std::string & addition);
static Action addHypothesisRelative(const std::string & colName, Config::Object object, int relativeIndex, const std::string & hypothesis);
static Action addHypothesisRelativeRelaxed(const std::string & colName, Config::Object object, int relativeIndex, const std::string & hypothesis);
static Action addToHypothesisRelative(const std::string & colName, Config::Object object, int relativeIndex, const std::string & addition);
static Action pushWordIndexOnStack();
static Action popStack(int relIndex);
......
......@@ -239,6 +239,30 @@ Action Action::addHypothesisRelative(const std::string & colName, Config::Object
return {Type::Write, apply, undo, appliable};
}
Action Action::addHypothesisRelativeRelaxed(const std::string & colName, Config::Object object, int relativeIndex, const std::string & hypothesis)
{
auto apply = [colName, object, relativeIndex, hypothesis](Config & config, Action & a)
{
int lineIndex = config.getRelativeWordIndex(object, relativeIndex);
return addHypothesis(colName, lineIndex, hypothesis).apply(config, a);
};
auto undo = [colName, object, relativeIndex](Config & config, Action & a)
{
int lineIndex = config.getRelativeWordIndex(object, relativeIndex);
return addHypothesis(colName, lineIndex, "").undo(config, a);
};
auto appliable = [colName, object, relativeIndex](const Config & config, const Action & a)
{
return true;
};
return {Type::Write, apply, undo, appliable};
}
Action Action::pushWordIndexOnStack()
{
auto apply = [](Config & config, Action & a)
......
......@@ -213,7 +213,7 @@ void Transition::initSplitWord(std::vector<std::string> words)
sequence.emplace_back(Action::addLinesIfNeeded(words.size()));
sequence.emplace_back(Action::consumeCharacterIndex(consumedWord));
for (unsigned int i = 0; i < words.size(); i++)
sequence.emplace_back(Action::addHypothesisRelative("FORM", Config::Object::Buffer, i, words[i]));
sequence.emplace_back(Action::addHypothesisRelativeRelaxed("FORM", Config::Object::Buffer, i, words[i]));
sequence.emplace_back(Action::setMultiwordIds(words.size()-1));
cost = [words](const Config & config)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment