       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);

        else {
          break;
        }
        /* std::cout << "TMP " << nbestIndex<< " " << sentences2score.size() << std::endl; */

      }
      /* std::cout << "BATch size: " << sentences2score.size() << std::endl; */
      if (sentences2score.size() == 0 ) {
        index = boost::lexical_cast<size_t>(nbest[nbestIndex][0]);
        continue;

  size_t index = 0;
  size_t nbestIndex = 0;
  for (auto& in: input) {
    Encoder encoder(weights);
    Decoder decoder(weights);

