     }
 }
 
+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;
 

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

      mblas::Matrix SourceContext;
      encoder.GetContext(sIndexes, SourceContext);

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

  std::vector<std::vector<std::string>> nbest;
  ParseNBestFile(nbestPath, nbest);

  Encoder encoder(weights);
  Decoder decoder(weights);

  size_t index = 0;
  size_t nbestIndex = 0;
  for (auto& in: input) {

    auto words = Split(in);
    auto sIndexes = svcb.Encode(words);
    mblas::Matrix SourceContext;
    encoder.GetContext(sIndexes, SourceContext);

    std::vector<std::vector<size_t> > sentences2score;
    while (nbestIndex < nbest.size()) {
