# Path: cam/sgnmt/utils.py
# GO_ID = 1
# EOS_ID = 2
# UNK_ID = 0
# NOTAPPLICABLE_ID = 3
# NEG_INF = float("-inf")
# INF = float("inf")
# EPS_P = 0.00001
#     GO_ID = 0
#     EOS_ID = 2
#     UNK_ID = 3
#     GO_ID = 2 # Usually not used
#     EOS_ID = 1
#     UNK_ID = 3 # Don't rely on this: UNK not standardized in T2T
# TMP_FILENAME = '/tmp/sgnmt.%s.fst' % os.getpid()
# MESSAGE_TYPE_DEFAULT = 1
# MESSAGE_TYPE_POSTERIOR = 2
# MESSAGE_TYPE_FULL_HYPO = 3
# def switch_to_fairseq_indexing():
# def switch_to_t2t_indexing():
# def log_sum_tropical_semiring(vals):
# def log_sum_log_semiring(vals):
# def oov_to_unk(seq, vocab_size, unk_idx=None):
# def argmax_n(arr, n):
# def argmax(arr):
# def common_viewkeys(obj):
# def common_iterable(obj):
# def common_get(obj, key, default):
# def common_contains(obj, key):
# def w2f(fstweight):
# def load_fst(path):
# def get_path(tmpl, sub = 1):
# def split_comma(s, func=None):
#     def notify(self, message, message_type = MESSAGE_TYPE_DEFAULT):
#     def __init__(self):
#     def add_observer(self, observer):
#     def notify_observers(self, message, message_type = MESSAGE_TYPE_DEFAULT):
# class Observer(object):
# class Observable(object):
# 
# Path: cam/sgnmt/tf_utils.py
# def session_config(n_cpu_threads=-1):
# def create_session(checkpoint_path, n_cpu_threads=-1):


from cam.sgnmt import utils, tf_utils
from abc import abstractmethod
    from tensorflow.python.training import saver
    from tensorflow.python.training import training
    from tensorflow.contrib.training.python.training import hparam
    from sgnmt_moe.model import MOEModel
import numpy as np
import logging
    import tensorflow as tf
    """This class implements a predictor-level Mixture of Experts (MoE)
    model. In this scenario, we have a neural model which predicts 
    predictor weights from the predictor outputs. See the sgnmt_moe 
    project on how to train this gating network with TensorFlow.
    """

    def __init__(self, num_experts, args):
        """Creates the computation graph of the MoE network and loads
        the checkpoint file. Following fields are fetched from ``args``

            moe_config: Comma-separated <key>=<value> pairs specifying
              the MoE network. See the command line arguments of 
              sgnmt_moe for a full description. Available keys:
              vocab_size, embed_size, activation, hidden_layer_size,
              preprocessing.
            moe_checkpoint_dir (string): Checkpoint directory
            n_cpu_threads (int): Number of CPU threads for TensorFlow

        Args:
            num_experts (int): Number of predictors under the MoE model
            args (object): SGNMT configuration object
        """
        super(MoEInterpolationStrategy, self).__init__()
        config = dict(el.split("=", 1) for el in args.moe_config.split(";"))
        self._create_hparams(num_experts, config)
        self.model = MOEModel(self.params)
        logging.info("MoE HParams: %s" % self.params)
        moe_graph = tf.Graph()
        with moe_graph.as_default() as g:
          self.model.initialize()

# Path: cam/sgnmt/utils.py
# GO_ID = 1
# EOS_ID = 2
# UNK_ID = 0
# NOTAPPLICABLE_ID = 3
# NEG_INF = float("-inf")
# INF = float("inf")
# EPS_P = 0.00001
#     GO_ID = 0
#     EOS_ID = 2
#     UNK_ID = 3
#     GO_ID = 2 # Usually not used
#     EOS_ID = 1
#     UNK_ID = 3 # Don't rely on this: UNK not standardized in T2T
# TMP_FILENAME = '/tmp/sgnmt.%s.fst' % os.getpid()
# MESSAGE_TYPE_DEFAULT = 1
# MESSAGE_TYPE_POSTERIOR = 2
# MESSAGE_TYPE_FULL_HYPO = 3
# def switch_to_fairseq_indexing():
# def switch_to_t2t_indexing():
# def log_sum_tropical_semiring(vals):
# def log_sum_log_semiring(vals):
# def oov_to_unk(seq, vocab_size, unk_idx=None):
# def argmax_n(arr, n):
# def argmax(arr):
# def common_viewkeys(obj):
# def common_iterable(obj):
# def common_get(obj, key, default):
# def common_contains(obj, key):
# def w2f(fstweight):
# def load_fst(path):
# def get_path(tmpl, sub = 1):
# def split_comma(s, func=None):
#     def notify(self, message, message_type = MESSAGE_TYPE_DEFAULT):
#     def __init__(self):
#     def add_observer(self, observer):
#     def notify_observers(self, message, message_type = MESSAGE_TYPE_DEFAULT):
# class Observer(object):
# class Observable(object):
# 
# Path: cam/sgnmt/tf_utils.py
# def session_config(n_cpu_threads=-1):
# def create_session(checkpoint_path, n_cpu_threads=-1):


# Path: cam/sgnmt/decoding/interpolation.py
from cam.sgnmt import utils, tf_utils
from abc import abstractmethod
    from tensorflow.python.training import saver
    from tensorflow.python.training import training
    from tensorflow.contrib.training.python.training import hparam
    from sgnmt_moe.model import MOEModel
import numpy as np
import logging
    import tensorflow as tf

    """This class implements a predictor-level Mixture of Experts (MoE)
    model. In this scenario, we have a neural model which predicts 
    predictor weights from the predictor outputs. See the sgnmt_moe 
    project on how to train this gating network with TensorFlow.
    """

    def __init__(self, num_experts, args):
        """Creates the computation graph of the MoE network and loads
        the checkpoint file. Following fields are fetched from ``args``

            moe_config: Comma-separated <key>=<value> pairs specifying
              the MoE network. See the command line arguments of 
              sgnmt_moe for a full description. Available keys:
              vocab_size, embed_size, activation, hidden_layer_size,
              preprocessing.
            moe_checkpoint_dir (string): Checkpoint directory
            n_cpu_threads (int): Number of CPU threads for TensorFlow

        Args:
            num_experts (int): Number of predictors under the MoE model
            args (object): SGNMT configuration object
        """
        super(MoEInterpolationStrategy, self).__init__()
        config = dict(el.split("=", 1) for el in args.moe_config.split(";"))
        self._create_hparams(num_experts, config)
        self.model = MOEModel(self.params)
        logging.info("MoE HParams: %s" % self.params)
        moe_graph = tf.Graph()
        with moe_graph.as_default() as g:
          self.model.initialize()

          self.sess = tf_utils.create_session(args.moe_checkpoint_dir,