Longest Common Subsequence accuracy measure: calculate accuracy of each prediction as LCS/length

def accuracy_lcs(self, label, pred):
        """ Longest Common Subsequence accuracy measure: calculate accuracy of each prediction as LCS/length"""
        hit = 0.
        total = 0.
        batch_size = label.shape[0]
        for i in range(batch_size):
            l = self._remove_blank(label[i])
            p = []
            for k in range(self.seq_len):
                p.append(np.argmax(pred[k * batch_size + i]))
            p = self.ctc_label(p)
            hit += self._lcs(p, l) * 1.0 / len(l)
            total += 1.0
        assert total == batch_size
        return hit / total