# Path: lamb/corpus.py
# class Corpus(object):
#   def __init__(self, data):
#   def data(self):
#   def size(self):
#   def __add__(self, other):
#   def instance_iterator(self, shuffle=False, start=None,
#                         max_instances=None, max_epochs=None):
#   def _effective_max_instances(self, max_instances, max_epochs):
#   def _share_of_iterator(self, n, num_iterators, i):
#   def ordered_iterators(self, num_iterators,
#                         max_instances=None, max_epochs=None):
#   def equidistant_iterators(self, num_iterators,
#                             random_starts=False, start_jitter=None,
#                             max_instances=None, max_epochs=None):
#           def start_fn(start=start):
#   def max_sentence_length(self):
#   def tokens(self):
# def maybe_truncate(seq, n):
# def read_character_based_corpus(filename, encoding='utf-8'):
# def read_word_based_corpus(filename, encoding='utf-8'):
# def get_episodic_batches(instance_generator, max_batch_size, vocab,
#                          num_steps, num_samples=1, max_batches=None,
#                          conditioning_separator=None):
#       def break_at_separator(seq):
#     def emit(batch_index):
# def get_non_episodic_batches(instance_generators, vocab,
#                              num_steps, num_samples=1, max_batches=None,
#                              add_eos=True):
#   def ensure_window(i):
#   def pop_window(i):
#   def emit_batch():
# def get_batches(corpus_, vocab, batch_size, num_steps, num_samples=1,
#                 episodic=None, deterministic=None, equidistant=True,
#                 max_instances=None, max_epochs=None, max_batches=None,
#                 conditioning_separator=None):


import math
import numpy as np
import six
import tensorflow.compat.v1 as tf
from absl import logging
from lamb import corpus
        if log_sum_probs is None:
          log_sum_probs = log_probs
        else:
          log_sum_probs = np.logaddexp(log_sum_probs, power*log_probs)
      # log_sum_probs is \ln \sum x_i^p. We need to divide by n
      # (i.e. subtract math.log(num_samples)), and raise to the
      # power 1/p (i.e. divide by power), then feed the results
      # through the softmax to renormalize.
      feed.update(
          {model.logits: (log_sum_probs -
                          math.log(num_samples))/power*temperature})
      xe = tf.get_default_session().run(model.xe_losses, feed)
      sum_xe1, sum_len1 = _sum_masked(source_len, xe)
      sum_xe += sum_xe1
      sum_len += sum_len1
      average_xe = sum_xe / sum_len
      if print_level >= 2:
        logging.info('%s xe: %6.5f (%s), batches: %s (ns=%s)',
                     dataset_name, average_xe, sum_len,
                     num_batches-num_batches_to_discard, num_samples)
    # Do a deterministic pass. We need this even in MC mode to get a
    # single last state to feed back for the next batch. This isn't
    # strictly correct, we should actually sample the state to be
    # fed back and the most obvious way to do that is to loop over
    # the entire dataset instead of just the batch, but then we'd
    # need to keep all those logits around.
    feed = _make_feed(model, cond, cond_len, source, source_len, target,
                      last_state, episodic, 0, 1.0)
    last_state = tf.get_default_session().run(model.last_state, feed)
    num_batches += 1

# Path: lamb/corpus.py
# class Corpus(object):
#   def __init__(self, data):
#   def data(self):
#   def size(self):
#   def __add__(self, other):
#   def instance_iterator(self, shuffle=False, start=None,
#                         max_instances=None, max_epochs=None):
#   def _effective_max_instances(self, max_instances, max_epochs):
#   def _share_of_iterator(self, n, num_iterators, i):
#   def ordered_iterators(self, num_iterators,
#                         max_instances=None, max_epochs=None):
#   def equidistant_iterators(self, num_iterators,
#                             random_starts=False, start_jitter=None,
#                             max_instances=None, max_epochs=None):
#           def start_fn(start=start):
#   def max_sentence_length(self):
#   def tokens(self):
# def maybe_truncate(seq, n):
# def read_character_based_corpus(filename, encoding='utf-8'):
# def read_word_based_corpus(filename, encoding='utf-8'):
# def get_episodic_batches(instance_generator, max_batch_size, vocab,
#                          num_steps, num_samples=1, max_batches=None,
#                          conditioning_separator=None):
#       def break_at_separator(seq):
#     def emit(batch_index):
# def get_non_episodic_batches(instance_generators, vocab,
#                              num_steps, num_samples=1, max_batches=None,
#                              add_eos=True):
#   def ensure_window(i):
#   def pop_window(i):
#   def emit_batch():
# def get_batches(corpus_, vocab, batch_size, num_steps, num_samples=1,
#                 episodic=None, deterministic=None, equidistant=True,
#                 max_instances=None, max_epochs=None, max_batches=None,
#                 conditioning_separator=None):


# Path: lamb/evaluation.py
import math
import numpy as np
import six
import tensorflow.compat.v1 as tf
from absl import logging
from lamb import corpus

        if log_sum_probs is None:
          log_sum_probs = log_probs
        else:
          log_sum_probs = np.logaddexp(log_sum_probs, power*log_probs)
      # log_sum_probs is \ln \sum x_i^p. We need to divide by n
      # (i.e. subtract math.log(num_samples)), and raise to the
      # power 1/p (i.e. divide by power), then feed the results
      # through the softmax to renormalize.
      feed.update(
          {model.logits: (log_sum_probs -
                          math.log(num_samples))/power*temperature})
      xe = tf.get_default_session().run(model.xe_losses, feed)
      sum_xe1, sum_len1 = _sum_masked(source_len, xe)
      sum_xe += sum_xe1
      sum_len += sum_len1
      average_xe = sum_xe / sum_len
      if print_level >= 2:
        logging.info('%s xe: %6.5f (%s), batches: %s (ns=%s)',
                     dataset_name, average_xe, sum_len,
                     num_batches-num_batches_to_discard, num_samples)
    # Do a deterministic pass. We need this even in MC mode to get a
    # single last state to feed back for the next batch. This isn't
    # strictly correct, we should actually sample the state to be
    # fed back and the most obvious way to do that is to loop over
    # the entire dataset instead of just the batch, but then we'd
    # need to keep all those logits around.
    feed = _make_feed(model, cond, cond_len, source, source_len, target,
                      last_state, episodic, 0, 1.0)
    last_state = tf.get_default_session().run(model.last_state, feed)
    num_batches += 1

  if print_level >= 1: