From d5a1c96e4cc6dfc6278595f1b30f23e5bfb4446b Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@lis-lab.fr>
Date: Sat, 11 Apr 2020 12:35:04 +0200
Subject: [PATCH] Fixed a bug with focused indexes where comments where not
 ignored during training

---
 reading_machine/src/Config.cpp          | 5 +++--
 torch_modules/src/FocusedColumnLSTM.cpp | 5 +++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/reading_machine/src/Config.cpp b/reading_machine/src/Config.cpp
index 4e5b42e..50e7f61 100644
--- a/reading_machine/src/Config.cpp
+++ b/reading_machine/src/Config.cpp
@@ -375,8 +375,9 @@ bool Config::isComment(std::size_t lineIndex) const
 
 bool Config::isCommentPredicted(std::size_t lineIndex) const
 {
-  auto & col0 = getAsFeature(0, lineIndex);
-  return !util::isEmpty(col0) and col0.get()[0] == '#';
+  auto & col0Pred = getAsFeature(0, lineIndex);
+  auto & col0Gold = getConst(0, lineIndex, 0);
+  return (!util::isEmpty(col0Pred) and col0Pred.get()[0] == '#') or (!util::isEmpty(col0Gold) and col0Gold.get()[0] == '#');
 }
 
 bool Config::isMultiword(std::size_t lineIndex) const
diff --git a/torch_modules/src/FocusedColumnLSTM.cpp b/torch_modules/src/FocusedColumnLSTM.cpp
index 9b5f52f..4e0da0e 100644
--- a/torch_modules/src/FocusedColumnLSTM.cpp
+++ b/torch_modules/src/FocusedColumnLSTM.cpp
@@ -78,6 +78,11 @@ void FocusedColumnLSTMImpl::addToContext(std::vector<std::vector<long>> & contex
         else if (config.isEmptyNodePredicted(index))
           elements.emplace_back("ID(EMPTYNODE)");
       }
+      else if (column == "EOS")
+      {
+        bool isEOS = config.getAsFeature(Config::EOSColName, index) == Config::EOSSymbol1;
+        elements.emplace_back(fmt::format("EOS({})", isEOS));
+      }
       else
       {
         elements.emplace_back(config.getAsFeature(column, index));
-- 
GitLab