<commit_before>import abc



class InvertibleLayer(abc.ABC):
  def forward(self, *args, **kwargs):
    return NotImplemented

  def backward(self, *args, **kwargs):
    return NotImplemented<commit_msg>Implement invertible.InvertibleNetwork class<commit_after>import abc
import functools



_FORWARD = "forward"
_BACKWARD = "backward"


class InvertibleLayer(abc.ABC):
  def forward(self, *args):
    return NotImplemented

  def backward(self, *args):
    return NotImplemented


class InvertibleNetwork(InvertibleLayer):
  def __init__(self, *layers):
    assert all(isinstance(layer, InvertibleLayer) for layer in layers)
    self._layers = layers

  def forward(self, *args):
    return _reduce_layers(_FORWARD, *args, **kwargs)

  def backward(self, *args):
    return _reduce_layers(_BACKWARD, *args, **kwargs)

  def _reduce_layers(self, method, *args):
    assert method in {_FORWARD, _BACKWARD}
    return functools.reduce(lambda args, layer: getattr(layer, method)(*args),
                            self._layers,
                            args)
{'fraction_non_alphanumeric': 0.10302457466918714, 'fraction_numerical': 0.0, 'mean_word_length': 3.8577981651376145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '716685', 'n_tokens_mistral': 336, 'n_tokens_neox': 317, 'n_words': 82}