import collections
import numpy



# classes

class Data:
  def __init__(self, documents, labels):
    assert isinstance(documents, numpy.ndarray)
    assert isinstance(labels, numpy.ndarray)
    assert documents.shape[0] == labels.shape[0]
    self._documents = documents
    self._labels = labels

  @property
  def documents(self):
    return self._documents

  @property
  def labels(self):
    return self._labels

  @property
  def size(self):
    return self._documents.shape[0]



# functions

def batches(data, batch_size):
  for index in range(0, data.size, batch_size):
    index_range = slice(index, index + batch_size)
    yield Data(data.documents[index_range],
               data.labels[index_range])


def sample(data, sample_data_size):
  shuffled_data = shuffle(data)
  return Data(shuffled_data.documents[:sample_data_size],
              shuffled_data.labels[:sample_data_size])


def shuffle(data):
  indices = numpy.random.permutation(data.size)
  return Data(data.documents[indices], data.labels[indices])

@@ -378,112 +378,914 @@
 def 
-labels(self):%0A    return self._labels%0A%0A  @property%0A  def size(self):%0A    return self._documents.shape%5B0%5D
+forward_documents(self):%0A    if not hasattr(self, %22_forward_documents%22):%0A      self._forward_documents %5C%0A          = numpy.array(%5Bself._reverse_document(array)%0A                         for array in self.backward_documents%5D)%0A    return self._forward_documents%0A%0A  @property%0A  def backward_documents(self):%0A    if not hasattr(self, %22_backward_documents%22):%0A      self._backward_documents = numpy.fliplr(self._documents)%0A    return self._backward_documents%0A%0A  @property%0A  def labels(self):%0A    return self._labels%0A%0A  @property%0A  def size(self):%0A    return self._documents.shape%5B0%5D%0A%0A  @staticmethod%0A  def _reverse_document(array):%0A    if array%5B0%5D != 0:%0A      return array%5B::-1%5D%0A    padding_length = (array != 0).argmax(axis=0)%0A    return numpy.concatenate((numpy.zeros((padding_length,),%0A                                          dtype=numpy.int32),%0A                             array%5B:(padding_length - 1):-1%5D))
 %0A%0A%0A%0A

Add forward_documents and backward_documents properties to data.Data class