# Path: third_party/nmt/utils/misc_utils.py
# def check_tensorflow_version():
# def safe_exp(value):
# def print_time(s, start_time):
# def print_out(s, f=None, new_line=True):
# def print_hparams(hparams, skip_patterns=None, header=None):
# def load_hparams(model_dir):
# def maybe_parse_standard_hparams(hparams, hparams_path):
# def save_hparams(out_dir, hparams):
# def debug_tensor(s, msg=None, summarize=10):
# def add_summary(summary_writer, global_step, tag, value):
# def get_config_proto(log_device_placement=False, allow_soft_placement=True,
#                      num_intra_threads=0, num_inter_threads=0):
# def format_text(words):
# def format_bpe_text(symbols, delimiter=b"@@"):
# def format_spm_text(symbols):
# 
# Path: px/nmt/model_helper.py
# VOCAB_SIZE_THRESHOLD_CPU = 50000
# def get_initializer(init_op, seed=None, init_weight=None):
# def get_device_str(device_id, num_gpus):
# def create_train_model(model_creator,
#                        hparams,
#                        scope=None,
#                        num_workers=1,
#                        jobid=0,
#                        graph=None,
#                        extra_args=None,
#                        trie=None,
#                        use_placeholders=False):
# def create_train_model_for_server(model_creator,
#                                   hparams,
#                                   scope=None,
#                                   num_workers=1,
#                                   jobid=0,
#                                   graph=None,
#                                   extra_args=None,
#                                   trie=None):
# def create_eval_model(model_creator,
#                       hparams,
#                       scope=None,
#                       graph=None,
#                       extra_args=None,
#                       trie=None):
# def create_infer_model(model_creator,
#                        hparams,
#                        scope=None,
#                        graph=None,
#                        extra_args=None,
#                        trie=None):
# def _get_embed_device(vocab_size):
# def _create_pretrained_emb_from_txt(vocab_file,
#                                     embed_file,
#                                     num_trainable_tokens=3,
#                                     dtype=tf.float32,
#                                     scope=None):
# def _create_or_load_embed(embed_name, vocab_file, embed_file, vocab_size,
#                           embed_size, dtype):
# def create_emb_for_encoder_and_decoder(share_vocab,
#                                        src_vocab_size,
#                                        tgt_vocab_size,
#                                        src_embed_size,
#                                        tgt_embed_size,
#                                        dtype=tf.float32,
#                                        num_partitions=0,
#                                        src_vocab_file=None,
#                                        tgt_vocab_file=None,
#                                        src_embed_file=None,
#                                        tgt_embed_file=None,
#                                        scope=None):
# def _single_cell(unit_type,
#                  num_units,
#                  forget_bias,
#                  dropout,
#                  mode,
#                  residual_connection=False,
#                  device_str=None,
#                  residual_fn=None):
# def _cell_list(unit_type,
#                num_units,
#                num_layers,
#                num_residual_layers,
#                forget_bias,
#                dropout,
#                mode,
#                num_gpus,
#                base_gpu=0,
#                single_cell_fn=None,
#                residual_fn=None):
# def create_rnn_cell(unit_type,
#                     num_units,
#                     num_layers,
#                     num_residual_layers,
#                     forget_bias,
#                     dropout,
#                     mode,
#                     num_gpus,
#                     base_gpu=0,
#                     single_cell_fn=None):
# def gradient_clip(gradients, max_gradient_norm):
# def load_model(model, ckpt, session, name):
# def avg_checkpoints(model_dir, num_last_checkpoints, global_step,
#                     global_step_name):
# def get_global_step(model, session):
# def create_or_load_model(model, model_dir, session, name):
# def compute_perplexity(hparams, model, sess, name):
# class ExtraArgs(
#     collections.namedtuple(
#         "ExtraArgs",
#         ("single_cell_fn", "model_device_fn", "attention_mechanism_fn"))):
# class TrainModel(
#     collections.namedtuple(
#         "TrainModel",
#         ("graph", "model", "iterator", "src_placeholder", "tgt_placeholder",
#          "annot_placeholder", "skip_count_placeholder"))):
# class TrainModelForServer(
#     collections.namedtuple(
#         "TrainModelForServer",
#         ("graph", "model", "iterator", "src_placeholder", "tgt_placeholder",
#          "wgt_placeholder", "batch_size_placeholder", "skip_count_placeholder"))
# ):
# class EvalModel(
#     collections.namedtuple(
#         "EvalModel",
#         ("graph", "model", "src_file_placeholder", "tgt_file_placeholder",
#          "ctx_file_placeholder", "annot_file_placeholder", "iterator"))):
# class InferModel(
#     collections.namedtuple(
#         "InferModel", ("graph", "model", "src_placeholder", "annot_placeholder",
#                        "ctx_placeholder", "trie_exclude_placeholder",
#                        "batch_size_placeholder", "iterator"))):


import tensorflow as tf
from third_party.nmt.utils import misc_utils as utils
from px.nmt import model_helper
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

"""Convert the context string into a vector."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function




# Path: third_party/nmt/utils/misc_utils.py
# def check_tensorflow_version():
# def safe_exp(value):
# def print_time(s, start_time):
# def print_out(s, f=None, new_line=True):
# def print_hparams(hparams, skip_patterns=None, header=None):
# def load_hparams(model_dir):
# def maybe_parse_standard_hparams(hparams, hparams_path):
# def save_hparams(out_dir, hparams):
# def debug_tensor(s, msg=None, summarize=10):
# def add_summary(summary_writer, global_step, tag, value):
# def get_config_proto(log_device_placement=False, allow_soft_placement=True,
#                      num_intra_threads=0, num_inter_threads=0):
# def format_text(words):
# def format_bpe_text(symbols, delimiter=b"@@"):
# def format_spm_text(symbols):
# 
# Path: px/nmt/model_helper.py
# VOCAB_SIZE_THRESHOLD_CPU = 50000
# def get_initializer(init_op, seed=None, init_weight=None):
# def get_device_str(device_id, num_gpus):
# def create_train_model(model_creator,
#                        hparams,
#                        scope=None,
#                        num_workers=1,
#                        jobid=0,
#                        graph=None,
#                        extra_args=None,
#                        trie=None,
#                        use_placeholders=False):
# def create_train_model_for_server(model_creator,
#                                   hparams,
#                                   scope=None,
#                                   num_workers=1,
#                                   jobid=0,
#                                   graph=None,
#                                   extra_args=None,
#                                   trie=None):
# def create_eval_model(model_creator,
#                       hparams,
#                       scope=None,
#                       graph=None,
#                       extra_args=None,
#                       trie=None):
# def create_infer_model(model_creator,
#                        hparams,
#                        scope=None,
#                        graph=None,
#                        extra_args=None,
#                        trie=None):
# def _get_embed_device(vocab_size):
# def _create_pretrained_emb_from_txt(vocab_file,
#                                     embed_file,
#                                     num_trainable_tokens=3,
#                                     dtype=tf.float32,
#                                     scope=None):
# def _create_or_load_embed(embed_name, vocab_file, embed_file, vocab_size,
#                           embed_size, dtype):
# def create_emb_for_encoder_and_decoder(share_vocab,
#                                        src_vocab_size,
#                                        tgt_vocab_size,
#                                        src_embed_size,
#                                        tgt_embed_size,
#                                        dtype=tf.float32,
#                                        num_partitions=0,
#                                        src_vocab_file=None,
#                                        tgt_vocab_file=None,
#                                        src_embed_file=None,
#                                        tgt_embed_file=None,
#                                        scope=None):
# def _single_cell(unit_type,
#                  num_units,
#                  forget_bias,
#                  dropout,
#                  mode,
#                  residual_connection=False,
#                  device_str=None,
#                  residual_fn=None):
# def _cell_list(unit_type,
#                num_units,
#                num_layers,
#                num_residual_layers,
#                forget_bias,
#                dropout,
#                mode,
#                num_gpus,
#                base_gpu=0,
#                single_cell_fn=None,
#                residual_fn=None):
# def create_rnn_cell(unit_type,
#                     num_units,
#                     num_layers,
#                     num_residual_layers,
#                     forget_bias,
#                     dropout,
#                     mode,
#                     num_gpus,
#                     base_gpu=0,
#                     single_cell_fn=None):
# def gradient_clip(gradients, max_gradient_norm):
# def load_model(model, ckpt, session, name):
# def avg_checkpoints(model_dir, num_last_checkpoints, global_step,
#                     global_step_name):
# def get_global_step(model, session):
# def create_or_load_model(model, model_dir, session, name):
# def compute_perplexity(hparams, model, sess, name):
# class ExtraArgs(
#     collections.namedtuple(
#         "ExtraArgs",
#         ("single_cell_fn", "model_device_fn", "attention_mechanism_fn"))):
# class TrainModel(
#     collections.namedtuple(
#         "TrainModel",
#         ("graph", "model", "iterator", "src_placeholder", "tgt_placeholder",
#          "annot_placeholder", "skip_count_placeholder"))):
# class TrainModelForServer(
#     collections.namedtuple(
#         "TrainModelForServer",
#         ("graph", "model", "iterator", "src_placeholder", "tgt_placeholder",
#          "wgt_placeholder", "batch_size_placeholder", "skip_count_placeholder"))
# ):
# class EvalModel(
#     collections.namedtuple(
#         "EvalModel",
#         ("graph", "model", "src_file_placeholder", "tgt_file_placeholder",
#          "ctx_file_placeholder", "annot_file_placeholder", "iterator"))):
# class InferModel(
#     collections.namedtuple(
#         "InferModel", ("graph", "model", "src_placeholder", "annot_placeholder",
#                        "ctx_placeholder", "trie_exclude_placeholder",
#                        "batch_size_placeholder", "iterator"))):


# Path: px/nmt/context_encoder.py
import tensorflow as tf
from third_party.nmt.utils import misc_utils as utils
from px.nmt import model_helper

# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

"""Convert the context string into a vector."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function




utils.check_tensorflow_version()