# Path: utils/io_utils.py
# _PAD = b"_PAD"      # Append to unused space for both encoder/decoder.
# _GO = b"_GO"       # Prepend to each decoder input.
# _EOS = b"_EOS"      # Append to outputs only. Stopping signal when decoding.
# _UNK = b"_UNK"      # For any symbols not in our vocabulary.
# _START_VOCAB = [_PAD, _GO, _EOS, _UNK]
# PAD_ID = 0
# GO_ID = 1
# EOS_ID = 2
# UNK_ID = 3
# _WORD_SPLIT = re.compile(b"([.,!?\"':;)(])")
# _DIGIT_RE = re.compile(br"\d")
# _FLAGS = Flags(pretrained_dir=None,
#                config=None,
#                debug=None,
#                model='{}',
#                dataset='{}',
#                model_params='{}',
#                dataset_params='{}')
# def save_hyper_params(hyper_params, fname):
# def get_sentence(lower=True):
# def update_config(config=None,
#                   config_path=None,
#                   return_config=True,
#                   **kwargs):
# def get_yaml_config(path, save_path=True):
# def load_pretrained_config(pretrained_dir):
# def print_non_defaults(config):
# def flags_to_dict(flags):
# def merge_dicts(default_dict, preference_dict):
# def parse_config(flags=None, pretrained_dir=None, config_path=None):
# def basic_tokenizer(sentence):
# def num_lines(file_path):
# def get_word_freqs(path, counter, norm_digits=True):
# def create_vocabulary(vocab_path, from_path, to_path, max_vocab_size, norm_digits=True):
# def get_vocab_dicts(vocabulary_path):
# def sentence_to_token_ids(sentence, vocabulary, normalize_digits=True):
# def data_to_token_ids(data_path, target_path, vocabulary_path, normalize_digits=True):
# def prepare_data(data_dir,
#                  vocab_size,
#                  from_train_path=None,
#                  to_train_path=None,
#                  from_valid_path=None,
#                  to_valid_path=None,
#                  optimize=True,
#                  config_path=None):
#     def maybe_set_param(param, file_name):
#     def get_vocab_path(vocab_size):
#     def append_to_paths(s, **paths):
# 
# Path: utils/bot_freezer.py
# def load_graph(frozen_model_dir):
# def unfreeze_bot(frozen_model_path):
# def unfreeze_and_chat(frozen_model_path):
#     def as_words(sentence):
#         def respond_to(sentence):
# def get_frozen_vocab(config):
#     def __init__(self, frozen_model_dir, vocab_size):
#     def as_words(self, sentence):
#     def __call__(self, sentence):
# class FrozenBot:


import time
import logging
import unittest
import numpy as np
import tensorflow as tf
import pydoc
import data
import chatbot
from pydoc import locate
from utils import io_utils, bot_freezer
from tests.utils import *
            dataset.word_to_idx)
        encoder_inputs = np.array([encoder_inputs[::-1]])
        bot.pipeline._feed_dict = {
            bot.pipeline.user_input: encoder_inputs}

        # Get output sentence from the chatbot.
        _, _, response = bot.step(forward_only=True)
        print("Robot:", dataset.as_words(response[0][:-1]))

        # ================================================
        # 3. Freeze the chattable bot.
        # ================================================
        logging.info("Calling bot.freeze() . . . ")
        bot.freeze()

        # ================================================
        # 4. Try to unfreeze and use it.
        # ================================================
        logging.info("Resetting default graph . . . ")
        tf.reset_default_graph()
        logging.info("Importing frozen graph into default . . . ")
        frozen_graph = bot_freezer.load_graph(bot.ckpt_dir)

        logging.info("Extracting input/output tensors.")
        tensors, frozen_graph = bot_freezer.unfreeze_bot(bot.ckpt_dir)
        self.assertIsNotNone(tensors['inputs'])
        self.assertIsNotNone(tensors['outputs'])

        with tf.Session(graph=frozen_graph) as sess:
            raw_input = "How's it going?"

# Path: utils/io_utils.py
# _PAD = b"_PAD"      # Append to unused space for both encoder/decoder.
# _GO = b"_GO"       # Prepend to each decoder input.
# _EOS = b"_EOS"      # Append to outputs only. Stopping signal when decoding.
# _UNK = b"_UNK"      # For any symbols not in our vocabulary.
# _START_VOCAB = [_PAD, _GO, _EOS, _UNK]
# PAD_ID = 0
# GO_ID = 1
# EOS_ID = 2
# UNK_ID = 3
# _WORD_SPLIT = re.compile(b"([.,!?\"':;)(])")
# _DIGIT_RE = re.compile(br"\d")
# _FLAGS = Flags(pretrained_dir=None,
#                config=None,
#                debug=None,
#                model='{}',
#                dataset='{}',
#                model_params='{}',
#                dataset_params='{}')
# def save_hyper_params(hyper_params, fname):
# def get_sentence(lower=True):
# def update_config(config=None,
#                   config_path=None,
#                   return_config=True,
#                   **kwargs):
# def get_yaml_config(path, save_path=True):
# def load_pretrained_config(pretrained_dir):
# def print_non_defaults(config):
# def flags_to_dict(flags):
# def merge_dicts(default_dict, preference_dict):
# def parse_config(flags=None, pretrained_dir=None, config_path=None):
# def basic_tokenizer(sentence):
# def num_lines(file_path):
# def get_word_freqs(path, counter, norm_digits=True):
# def create_vocabulary(vocab_path, from_path, to_path, max_vocab_size, norm_digits=True):
# def get_vocab_dicts(vocabulary_path):
# def sentence_to_token_ids(sentence, vocabulary, normalize_digits=True):
# def data_to_token_ids(data_path, target_path, vocabulary_path, normalize_digits=True):
# def prepare_data(data_dir,
#                  vocab_size,
#                  from_train_path=None,
#                  to_train_path=None,
#                  from_valid_path=None,
#                  to_valid_path=None,
#                  optimize=True,
#                  config_path=None):
#     def maybe_set_param(param, file_name):
#     def get_vocab_path(vocab_size):
#     def append_to_paths(s, **paths):
# 
# Path: utils/bot_freezer.py
# def load_graph(frozen_model_dir):
# def unfreeze_bot(frozen_model_path):
# def unfreeze_and_chat(frozen_model_path):
#     def as_words(sentence):
#         def respond_to(sentence):
# def get_frozen_vocab(config):
#     def __init__(self, frozen_model_dir, vocab_size):
#     def as_words(self, sentence):
#     def __call__(self, sentence):
# class FrozenBot:


# Path: tests/test_dynamic_models.py
import time
import logging
import unittest
import numpy as np
import tensorflow as tf
import pydoc
import data
import chatbot
from pydoc import locate
from utils import io_utils, bot_freezer
from tests.utils import *

            dataset.word_to_idx)
        encoder_inputs = np.array([encoder_inputs[::-1]])
        bot.pipeline._feed_dict = {
            bot.pipeline.user_input: encoder_inputs}

        # Get output sentence from the chatbot.
        _, _, response = bot.step(forward_only=True)
        print("Robot:", dataset.as_words(response[0][:-1]))

        # ================================================
        # 3. Freeze the chattable bot.
        # ================================================
        logging.info("Calling bot.freeze() . . . ")
        bot.freeze()

        # ================================================
        # 4. Try to unfreeze and use it.
        # ================================================
        logging.info("Resetting default graph . . . ")
        tf.reset_default_graph()
        logging.info("Importing frozen graph into default . . . ")
        frozen_graph = bot_freezer.load_graph(bot.ckpt_dir)

        logging.info("Extracting input/output tensors.")
        tensors, frozen_graph = bot_freezer.unfreeze_bot(bot.ckpt_dir)
        self.assertIsNotNone(tensors['inputs'])
        self.assertIsNotNone(tensors['outputs'])

        with tf.Session(graph=frozen_graph) as sess:
            raw_input = "How's it going?"

            encoder_inputs  = io_utils.sentence_to_token_ids(