     }
 }
 
+std::vector<float> ScoreBatch(
+    Encoder& encoder,
+    Decoder& decoder,
+    mblas::Matrix& SourceContext,
+    std::vector<std::vector<size_t>>& batch) {
+  mblas::Matrix PrevState;
+  mblas::Matrix PrevEmbedding;
+
+  mblas::Matrix AlignedSourceContext;
+  mblas::Matrix Probs;
+
+  mblas::Matrix State;
+  mblas::Matrix Embedding;
+  size_t batchSize = batch[0].size();
+
+  decoder.EmptyState(PrevState, SourceContext, batchSize);
+  decoder.EmptyEmbedding(PrevEmbedding, batchSize);
+
+  std::vector<float> scores(batch[0].size(), 0.0f);
+  size_t lengthIndex = 0;
+  for (auto& w : batch) {
+    decoder.GetProbs(Probs, AlignedSourceContext,
+                     PrevState, PrevEmbedding, SourceContext);
+
+    for (size_t j = 0; j < w.size(); ++j) {
+      if (batch[lengthIndex][j]) {
+        float p = Probs(j, w[j]);
+        scores[j] += log(p);
+      }
+    }
+
+    decoder.Lookup(Embedding, w);
+    decoder.GetNextState(State, Embedding,
+                          PrevState, AlignedSourceContext);
+
+    mblas::Swap(State, PrevState);
+    mblas::Swap(Embedding, PrevEmbedding);
+    ++lengthIndex;
+  }
+  return scores;
+}
+
 int main(int argc, char* argv[]) {
   std::string modelPath, svPath, tvPath, corpusPath, nbestPath;
 

          << nbest[nbestIndex - sentences2score.size() + j][3] << " ||| "
          << std::endl;
      }
      index = boost::lexical_cast<size_t>(nbest[nbestIndex][0]);
    }
  }
  return 0;

      std::vector<std::vector<size_t>> batch;
      PrepareBatch(sentences2score, batch);

      auto scores = ScoreBatch(encoder, decoder, SourceContext, batch);

      for (size_t j = 0; j < batch[0].size(); ++j) {
        std::cout
          << nbest[nbestIndex - sentences2score.size() + j][0] << " ||| "
