import os
# Restrict the script to run on CPU
os.environ ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = ""

# Import Keras Tensoflow Backend
# from keras import backend as K
import tensorflow as tf
# Configure it to use only specific CPU Cores
config = tf.ConfigProto(intra_op_parallelism_threads=4,
                        inter_op_parallelism_threads=4,
                        device_count={"CPU": 1, "GPU": 0},
                        allow_soft_placement=True)

# import tensorflow as tf
import numpy as np
from IEOMAP_dataset_AC import dataset, IeomapSentenceIterator
from sklearn.metrics import confusion_matrix
from models_AC import SentenceModel
import json
import os


def emotion_recognition(n_run, epochs, batch_size, embedding_size, first_rnn_size, dropout, embedding, num_speakers):
    ########################################################################################################################
    # Hyper-parameters
    ########################################################################################################################
    split_size = 0.8  # Split proportion of train and test data

    #log_dir = './logs_AC/RNN_without_ID/1'
    log_dir = './logs_AC/RNN_' \
                         + str(num_speakers) + '/' + str(n_run) + '/'
    #log_dir = './logs_AC/RNN_' + embedding + 'Emb' + str(embedding_size) + '_1layer' + str(2*first_rnn_size) + '/' + str(n_run)
    train_log_dir = log_dir + 'train'
    val_log_dir = log_dir + 'val'

    ########################################################################################################################
    # Initialize the Data set
    ########################################################################################################################
    sentences, targets, data_info, speakers = dataset(mode='sentences', embedding=embedding, embedding_size=embedding_size)

    train_data = IeomapSentenceIterator(sentences[0], targets[0], data_info['sentences_length'][0], speakers[0])
    val_data = IeomapSentenceIterator(sentences[1], targets[1], data_info['sentences_length'][1], speakers[1])
    test_data = IeomapSentenceIterator(sentences[2], targets[2], data_info['sentences_length'][2], speakers[2])

    ########################################################################################################################
    # Initialize the model
    ########################################################################################################################
    g = SentenceModel(vocab_size=(data_info['vocabulary_size'] + 1),
                      embedding_size=embedding_size,
                      first_rnn_size=first_rnn_size,
                      num_classes=data_info['num_classes'],
                      dropout=dropout,
                      embedding=embedding,
                      num_speakers=num_speakers)

    # Store model setup
    model_setup = {'vocab_size': (data_info['vocabulary_size'] + 1),
                    'embedding_size': embedding_size,
                    'first_rnn_size': first_rnn_size,
                    'num_classes': data_info['num_classes'],
                    'dropout': dropout,
                    'embedding': embedding,
                    'num_speakers': num_speakers}

    dirname = os.path.dirname(log_dir)
    if not os.path.exists(dirname):
        os.makedirs(dirname)

    with open(log_dir + 'model_setup.p', 'w') as file:
        json.dump(model_setup, file, indent=4)

    ########################################################################################################################
    # Initialize the parameters
    ########################################################################################################################
    sess = tf.Session(config=config)
    sess.run(tf.global_variables_initializer())
    sess.run(tf.local_variables_initializer())
    saver = tf.train.Saver()
    epoch = 0
    best_epoch = 0
    train_conf_matrix = 0
    val_conf_matrix = 0
    test_conf_matrix = 0
    best_acc = 0

    ########################################################################################################################
    # Performance Indicators
    ########################################################################################################################
    writer_train = tf.summary.FileWriter(train_log_dir, sess.graph)
    writer_val = tf.summary.FileWriter(val_log_dir)

    accuracy_tf = tf.placeholder(tf.float32, [])
    precision_tf = tf.placeholder(tf.float32, [])
    recall_tf = tf.placeholder(tf.float32, [])

    summary_op = tf.summary.scalar('accuracy', accuracy_tf)
    summary_op = tf.summary.scalar('precision', precision_tf)
    summary_op = tf.summary.scalar('recall', recall_tf)

    ########################################################################################################################
    # Model training procedure
    ########################################################################################################################
    while train_data.epoch < epochs:  # and train_data.epoch < best_epoch + 20:
        sentences_batch, sentences_length_batch, targets_batch, speakers_batch = train_data.next_batch(batch_size)
        preds, _ = sess.run([g['preds'],
                             g['ts']],
                            feed_dict={g['x']: np.array(sentences_batch),
                                       g['y']: np.array(targets_batch).reshape(len(targets_batch)),
                                       g['speaker']: np.array(speakers_batch),
                                       g['seqlen']: np.array(sentences_length_batch).reshape(len(targets_batch))})

        ####################################################################################################################
        # Calculate the Train data Confusion Matrix
        ####################################################################################################################
        train_conf_matrix += confusion_matrix(targets_batch, preds, labels=range(data_info['num_classes']))

        ####################################################################################################################
        # Add the end of each training epoch compute the validation results and store the relevant information
        ####################################################################################################################
        if train_data.epoch != epoch:
            while val_data.epoch == epoch:
                sentences_batch, sentences_length_batch, targets_batch, speakers_batch = val_data.next_batch(batch_size)
                preds = sess.run([g['preds']],
                                 feed_dict={g['x']: np.array(sentences_batch),
                                            g['y']: np.array(targets_batch).reshape(len(targets_batch)),
                                            g['speaker']: np.array(speakers_batch),
                                            g['seqlen']: np.array(sentences_length_batch).reshape(
                                                len(targets_batch))})
                ############################################################################################################
                # Calculate the Test data Confusion Matrix
                ############################################################################################################
                val_conf_matrix += confusion_matrix(targets_batch, preds[0], labels=range(data_info['num_classes']))

            ################################################################################################################
            # Compute Accuracy, Precision and Recall
            ################################################################################################################
            train_CM_size = len(train_conf_matrix)
            total_train = sum(sum(train_conf_matrix))

            train_TP = np.diagonal(train_conf_matrix)
            train_FP = [sum(train_conf_matrix[:, i]) - train_TP[i] for i in range(train_CM_size)]
            train_FN = [sum(train_conf_matrix[i, :]) - train_TP[i] for i in range(train_CM_size)]
            train_TN = train_CM_size - train_TP - train_FP - train_FN

            train_precision = train_TP / (train_TP + train_FP)  # aka True Positive Rate
            train_recall = train_TP / (train_TP + train_FN)

            total_train_correct = sum(train_TP)
            total_train_accuracy = total_train_correct / total_train
            total_train_precision = sum(train_precision) / train_CM_size
            total_train_recall = sum(train_recall) / train_CM_size

            val_CM_size = len(val_conf_matrix)
            total_val = sum(sum(val_conf_matrix))

            val_TP = np.diagonal(val_conf_matrix)
            val_FP = [sum(val_conf_matrix[:, i]) - val_TP[i] for i in range(val_CM_size)]
            val_FN = [sum(val_conf_matrix[i, :]) - val_TP[i] for i in range(val_CM_size)]
            val_TN = val_CM_size - val_TP - val_FP - val_FN

            val_precision = val_TP / (val_TP + val_FP)
            val_recall = val_TP / (val_TP + val_FN)

            total_val_correct = sum(val_TP)
            total_val_accuracy = total_val_correct / total_val
            total_val_precision = sum(val_precision) / val_CM_size
            total_val_recall = sum(val_recall) / val_CM_size

            ################################################################################################################
            # Store Accuracy Precision Recall
            ################################################################################################################
            train_acc_summary = tf.Summary(
                value=[tf.Summary.Value(tag="accuracy", simple_value=total_train_accuracy), ])
            train_prec_summary = tf.Summary(
                value=[tf.Summary.Value(tag="precision", simple_value=total_train_precision), ])
            train_rec_summary = tf.Summary(value=[tf.Summary.Value(tag="recall", simple_value=total_train_recall), ])

            val_acc_summary = tf.Summary(value=[tf.Summary.Value(tag="accuracy", simple_value=total_val_accuracy), ])
            val_prec_summary = tf.Summary(
                value=[tf.Summary.Value(tag="precision", simple_value=total_val_precision), ])
            val_rec_summary = tf.Summary(value=[tf.Summary.Value(tag="recall", simple_value=total_val_recall), ])

            writer_train.add_summary(train_acc_summary, epoch)
            writer_train.add_summary(train_prec_summary, epoch)
            writer_train.add_summary(train_rec_summary, epoch)

            writer_val.add_summary(val_acc_summary, epoch)
            writer_val.add_summary(val_prec_summary, epoch)
            writer_val.add_summary(val_rec_summary, epoch)

            writer_train.flush()
            writer_val.flush()

            ################################################################################################################
            # Print the confusion matrix and store important information
            ################################################################################################################
            print(train_conf_matrix)
            print(val_conf_matrix)

            if best_acc < total_val_accuracy:
                saver.save(sess, log_dir + "acc_best_validation_model.ckpt")
                best_acc = total_val_accuracy
                best_epoch = epoch
                store_info = {'epoch': best_epoch,
                              'train_conf_matrix': list([list(x) for x in train_conf_matrix]),
                              'train_accuracy': total_train_accuracy,
                              'train_precision': list(train_precision),
                              'total_train_precision': total_train_precision,
                              'train_recall': list(train_recall),
                              'total_train_recall': total_train_recall,
                              'val_conf_matrix': list([list(x) for x in val_conf_matrix]),
                              'val_accuracy': total_val_accuracy,
                              'val_precision': list(val_precision),
                              'total_val_precision': total_val_precision,
                              'val_recall': list(val_recall),
                              'total_val_recall': total_val_recall}

            store_convergence_info = {'epoch': train_data.epoch,
                                      'train_conf_matrix': list([list(x) for x in train_conf_matrix]),
                                      'train_accuracy': total_train_accuracy,
                                      'train_precision': list(train_precision),
                                      'total_train_precision': total_train_precision,
                                      'train_recall': list(train_recall),
                                      'total_train_recall': total_train_recall,
                                      'val_conf_matrix': list([list(x) for x in val_conf_matrix]),
                                      'val_accuracy': total_val_accuracy,
                                      'val_precision': list(val_precision),
                                      'total_val_precision': total_val_precision,
                                      'val_recall': list(val_recall),
                                      'total_val_recall': total_val_recall}

            ################################################################################################################
            # Get ready for the next epoch
            ################################################################################################################
            epoch += 1
            train_conf_matrix = 0
            val_conf_matrix = 0
            ################################################################################################################

    ####################################################################################################################
    # Add the end of training compute the test results and store the relevant information
    ####################################################################################################################
    while test_data.epoch == 0:
        sentences_batch, sentences_length_batch, targets_batch, speakers_batch = test_data.next_batch(batch_size)
        preds = sess.run([g['preds']],
                         feed_dict={g['x']: np.array(sentences_batch),
                                    g['y']: np.array(targets_batch).reshape(len(targets_batch)),
                                    g['speaker']: np.array(speakers_batch),
                                    g['seqlen']: np.array(sentences_length_batch).reshape(
                                        len(targets_batch))})
        ############################################################################################################
        # Calculate the Test data Confusion Matrix
        ############################################################################################################
        test_conf_matrix += confusion_matrix(targets_batch, preds[0], labels=range(data_info['num_classes']))

    ################################################################################################################
    # Compute Accuracy, Precision and Recall
    ################################################################################################################
    test_CM_size = len(test_conf_matrix)
    total_test = sum(sum(test_conf_matrix))

    test_TP = np.diagonal(test_conf_matrix)
    test_FP = [sum(test_conf_matrix[:, i]) - test_TP[i] for i in range(test_CM_size)]
    test_FN = [sum(test_conf_matrix[i, :]) - test_TP[i] for i in range(test_CM_size)]
    test_TN = test_CM_size - test_TP - test_FP - test_FN

    test_precision = test_TP / (test_TP + test_FP)
    test_recall = test_TP / (test_TP + test_FN)

    total_test_correct = sum(test_TP)
    total_test_accuracy = total_test_correct / total_test
    total_test_precision = sum(test_precision) / test_CM_size
    total_test_recall = sum(test_recall) / test_CM_size

    ################################################################################################################
    # Print the confusion matrix and store important information
    ################################################################################################################
    print(test_conf_matrix)

    store_convergence_info['test_conf_matrix'] = list([list(x) for x in test_conf_matrix])
    store_convergence_info['test_accuracy'] = total_test_accuracy
    store_convergence_info['test_precision'] = list(test_precision)
    store_convergence_info['total_test_precision'] = total_test_precision
    store_convergence_info['test_recall'] = list(test_recall)
    store_convergence_info['total_test_recall'] = total_test_recall

    # trick to be able to save numpy.int64 into json
    def default(o):
        if isinstance(o, np.int64): return int(o)
        raise TypeError

    with open(log_dir + 'convergence_results.p', 'w') as file:
        json.dump(store_convergence_info, file, default=default, indent=4)

    saver.save(sess, log_dir + "convergence_model.ckpt")

    ####################################################################################################################
    # Add the end of training compute the test results of the best validation model and store the relevant information
    ####################################################################################################################
    saver.restore(sess, log_dir + "acc_best_validation_model.ckpt")

    test_conf_matrix = 0
    while test_data.epoch == 1:
        sentences_batch, sentences_length_batch, targets_batch, speakers_batch = test_data.next_batch(batch_size)
        preds = sess.run([g['preds']],
                         feed_dict={g['x']: np.array(sentences_batch),
                                    g['y']: np.array(targets_batch).reshape(len(targets_batch)),
                                    g['speaker']: np.array(speakers_batch),
                                    g['seqlen']: np.array(sentences_length_batch).reshape(
                                        len(targets_batch))})
        ############################################################################################################
        # Calculate the Test data Confusion Matrix
        ############################################################################################################
        test_conf_matrix += confusion_matrix(targets_batch, preds[0], labels=range(data_info['num_classes']))

    ################################################################################################################
    # Compute Accuracy, Precision and Recall
    ################################################################################################################
    test_CM_size = len(test_conf_matrix)
    total_test = sum(sum(test_conf_matrix))

    test_TP = np.diagonal(test_conf_matrix)
    test_FP = [sum(test_conf_matrix[:, i]) - test_TP[i] for i in range(test_CM_size)]
    test_FN = [sum(test_conf_matrix[i, :]) - test_TP[i] for i in range(test_CM_size)]
    test_TN = test_CM_size - test_TP - test_FP - test_FN

    test_precision = test_TP / (test_TP + test_FP)
    test_recall = test_TP / (test_TP + test_FN)

    total_test_correct = sum(test_TP)
    total_test_accuracy = total_test_correct / total_test
    total_test_precision = sum(test_precision) / test_CM_size
    total_test_recall = sum(test_recall) / test_CM_size

    ################################################################################################################
    # Print the confusion matrix and store important information
    ################################################################################################################
    print(test_conf_matrix)

    store_info['test_conf_matrix'] = list([list(x) for x in test_conf_matrix])
    store_info['test_accuracy'] = total_test_accuracy
    store_info['test_precision'] = list(test_precision)
    store_info['total_test_precision'] = total_test_precision
    store_info['test_recall'] = list(test_recall)
    store_info['total_test_recall'] = total_test_recall

    with open(log_dir + 'acc_best_validation_results.p', 'w') as file:
        json.dump(store_info, file, default=default, indent=4)

[((280, 425), 'tensorflow.ConfigProto', 'tf.ConfigProto', ([], {'intra_op_parallelism_threads': '(4)', 'inter_op_parallelism_threads': '(4)', 'device_count': "{'CPU': 1, 'GPU': 0}", 'allow_soft_placement': '(True)'}), "(intra_op_parallelism_threads=4, inter_op_parallelism_threads\n    =4, device_count={'CPU': 1, 'GPU': 0}, allow_soft_placement=True)\n", (294, 425), True, 'import tensorflow as tf\n'), ((1837, 1914), 'IEOMAP_dataset_AC.dataset', 'dataset', ([], {'mode': '"""sentences"""', 'embedding': 'embedding', 'embedding_size': 'embedding_size'}), "(mode='sentences', embedding=embedding, embedding_size=embedding_size)\n", (1844, 1914), False, 'from IEOMAP_dataset_AC import dataset, IeomapSentenceIterator\n'), ((1933, 2033), 'IEOMAP_dataset_AC.IeomapSentenceIterator', 'IeomapSentenceIterator', (['sentences[0]', 'targets[0]', "data_info['sentences_length'][0]", 'speakers[0]'], {}), "(sentences[0], targets[0], data_info[\n    'sentences_length'][0], speakers[0])\n", (1955, 2033), False, 'from IEOMAP_dataset_AC import dataset, IeomapSentenceIterator\n'), ((2044, 2144), 'IEOMAP_dataset_AC.IeomapSentenceIterator', 'IeomapSentenceIterator', (['sentences[1]', 'targets[1]', "data_info['sentences_length'][1]", 'speakers[1]'], {}), "(sentences[1], targets[1], data_info[\n    'sentences_length'][1], speakers[1])\n", (2066, 2144), False, 'from IEOMAP_dataset_AC import dataset, IeomapSentenceIterator\n'), ((2156, 2256), 'IEOMAP_dataset_AC.IeomapSentenceIterator', 'IeomapSentenceIterator', (['sentences[2]', 'targets[2]', "data_info['sentences_length'][2]", 'speakers[2]'], {}), "(sentences[2], targets[2], data_info[\n    'sentences_length'][2], speakers[2])\n", (2178, 2256), False, 'from IEOMAP_dataset_AC import dataset, IeomapSentenceIterator\n'), ((2538, 2776), 'models_AC.SentenceModel', 'SentenceModel', ([], {'vocab_size': "(data_info['vocabulary_size'] + 1)", 'embedding_size': 'embedding_size', 'first_rnn_size': 'first_rnn_size', 'num_classes': "data_info['num_classes']", 'dropout': 'dropout', 'embedding': 'embedding', 'num_speakers': 'num_speakers'}), "(vocab_size=data_info['vocabulary_size'] + 1, embedding_size=\n    embedding_size, first_rnn_size=first_rnn_size, num_classes=data_info[\n    'num_classes'], dropout=dropout, embedding=embedding, num_speakers=\n    num_speakers)\n", (2551, 2776), False, 'from models_AC import SentenceModel\n'), ((3308, 3332), 'os.path.dirname', 'os.path.dirname', (['log_dir'], {}), '(log_dir)\n', (3323, 3332), False, 'import os\n'), ((3795, 3820), 'tensorflow.Session', 'tf.Session', ([], {'config': 'config'}), '(config=config)\n', (3805, 3820), True, 'import tensorflow as tf\n'), ((3928, 3944), 'tensorflow.train.Saver', 'tf.train.Saver', ([], {}), '()\n', (3942, 3944), True, 'import tensorflow as tf\n'), ((4369, 4417), 'tensorflow.summary.FileWriter', 'tf.summary.FileWriter', (['train_log_dir', 'sess.graph'], {}), '(train_log_dir, sess.graph)\n', (4390, 4417), True, 'import tensorflow as tf\n'), ((4435, 4469), 'tensorflow.summary.FileWriter', 'tf.summary.FileWriter', (['val_log_dir'], {}), '(val_log_dir)\n', (4456, 4469), True, 'import tensorflow as tf\n'), ((4489, 4519), 'tensorflow.placeholder', 'tf.placeholder', (['tf.float32', '[]'], {}), '(tf.float32, [])\n', (4503, 4519), True, 'import tensorflow as tf\n'), ((4539, 4569), 'tensorflow.placeholder', 'tf.placeholder', (['tf.float32', '[]'], {}), '(tf.float32, [])\n', (4553, 4569), True, 'import tensorflow as tf\n'), ((4586, 4616), 'tensorflow.placeholder', 'tf.placeholder', (['tf.float32', '[]'], {}), '(tf.float32, [])\n', (4600, 4616), True, 'import tensorflow as tf\n'), ((4635, 4677), 'tensorflow.summary.scalar', 'tf.summary.scalar', (['"""accuracy"""', 'accuracy_tf'], {}), "('accuracy', accuracy_tf)\n", (4652, 4677), True, 'import tensorflow as tf\n'), ((4695, 4739), 'tensorflow.summary.scalar', 'tf.summary.scalar', (['"""precision"""', 'precision_tf'], {}), "('precision', precision_tf)\n", (4712, 4739), True, 'import tensorflow as tf\n'), ((4757, 4795), 'tensorflow.summary.scalar', 'tf.summary.scalar', (['"""recall"""', 'recall_tf'], {}), "('recall', recall_tf)\n", (4774, 4795), True, 'import tensorflow as tf\n'), ((15755, 15784), 'numpy.diagonal', 'np.diagonal', (['test_conf_matrix'], {}), '(test_conf_matrix)\n', (15766, 15784), True, 'import numpy as np\n'), ((19245, 19274), 'numpy.diagonal', 'np.diagonal', (['test_conf_matrix'], {}), '(test_conf_matrix)\n', (19256, 19274), True, 'import numpy as np\n'), ((3344, 3367), 'os.path.exists', 'os.path.exists', (['dirname'], {}), '(dirname)\n', (3358, 3367), False, 'import os\n'), ((3377, 3397), 'os.makedirs', 'os.makedirs', (['dirname'], {}), '(dirname)\n', (3388, 3397), False, 'import os\n'), ((3462, 3500), 'json.dump', 'json.dump', (['model_setup', 'file'], {'indent': '(4)'}), '(model_setup, file, indent=4)\n', (3471, 3500), False, 'import json\n'), ((3834, 3867), 'tensorflow.global_variables_initializer', 'tf.global_variables_initializer', ([], {}), '()\n', (3865, 3867), True, 'import tensorflow as tf\n'), ((3882, 3914), 'tensorflow.local_variables_initializer', 'tf.local_variables_initializer', ([], {}), '()\n', (3912, 3914), True, 'import tensorflow as tf\n'), ((17307, 17373), 'json.dump', 'json.dump', (['store_convergence_info', 'file'], {'default': 'default', 'indent': '(4)'}), '(store_convergence_info, file, default=default, indent=4)\n', (17316, 17373), False, 'import json\n'), ((20585, 20639), 'json.dump', 'json.dump', (['store_info', 'file'], {'default': 'default', 'indent': '(4)'}), '(store_info, file, default=default, indent=4)\n', (20594, 20639), False, 'import json\n'), ((8039, 8069), 'numpy.diagonal', 'np.diagonal', (['train_conf_matrix'], {}), '(train_conf_matrix)\n', (8050, 8069), True, 'import numpy as np\n'), ((8864, 8892), 'numpy.diagonal', 'np.diagonal', (['val_conf_matrix'], {}), '(val_conf_matrix)\n', (8875, 8892), True, 'import numpy as np\n'), ((5400, 5425), 'numpy.array', 'np.array', (['sentences_batch'], {}), '(sentences_batch)\n', (5408, 5425), True, 'import numpy as np\n'), ((5580, 5604), 'numpy.array', 'np.array', (['speakers_batch'], {}), '(speakers_batch)\n', (5588, 5604), True, 'import numpy as np\n'), ((14627, 14652), 'numpy.array', 'np.array', (['sentences_batch'], {}), '(sentences_batch)\n', (14635, 14652), True, 'import numpy as np\n'), ((14801, 14825), 'numpy.array', 'np.array', (['speakers_batch'], {}), '(speakers_batch)\n', (14809, 14825), True, 'import numpy as np\n'), ((18117, 18142), 'numpy.array', 'np.array', (['sentences_batch'], {}), '(sentences_batch)\n', (18125, 18142), True, 'import numpy as np\n'), ((18291, 18315), 'numpy.array', 'np.array', (['speakers_batch'], {}), '(speakers_batch)\n', (18299, 18315), True, 'import numpy as np\n'), ((9841, 9908), 'tensorflow.Summary.Value', 'tf.Summary.Value', ([], {'tag': '"""accuracy"""', 'simple_value': 'total_train_accuracy'}), "(tag='accuracy', simple_value=total_train_accuracy)\n", (9857, 9908), True, 'import tensorflow as tf\n'), ((9981, 10050), 'tensorflow.Summary.Value', 'tf.Summary.Value', ([], {'tag': '"""precision"""', 'simple_value': 'total_train_precision'}), "(tag='precision', simple_value=total_train_precision)\n", (9997, 10050), True, 'import tensorflow as tf\n'), ((10105, 10168), 'tensorflow.Summary.Value', 'tf.Summary.Value', ([], {'tag': '"""recall"""', 'simple_value': 'total_train_recall'}), "(tag='recall', simple_value=total_train_recall)\n", (10121, 10168), True, 'import tensorflow as tf\n'), ((10222, 10287), 'tensorflow.Summary.Value', 'tf.Summary.Value', ([], {'tag': '"""accuracy"""', 'simple_value': 'total_val_accuracy'}), "(tag='accuracy', simple_value=total_val_accuracy)\n", (10238, 10287), True, 'import tensorflow as tf\n'), ((10358, 10425), 'tensorflow.Summary.Value', 'tf.Summary.Value', ([], {'tag': '"""precision"""', 'simple_value': 'total_val_precision'}), "(tag='precision', simple_value=total_val_precision)\n", (10374, 10425), True, 'import tensorflow as tf\n'), ((10478, 10539), 'tensorflow.Summary.Value', 'tf.Summary.Value', ([], {'tag': '"""recall"""', 'simple_value': 'total_val_recall'}), "(tag='recall', simple_value=total_val_recall)\n", (10494, 10539), True, 'import tensorflow as tf\n'), ((5474, 5497), 'numpy.array', 'np.array', (['targets_batch'], {}), '(targets_batch)\n', (5482, 5497), True, 'import numpy as np\n'), ((5658, 5690), 'numpy.array', 'np.array', (['sentences_length_batch'], {}), '(sentences_length_batch)\n', (5666, 5690), True, 'import numpy as np\n'), ((6795, 6820), 'numpy.array', 'np.array', (['sentences_batch'], {}), '(sentences_batch)\n', (6803, 6820), True, 'import numpy as np\n'), ((6985, 7009), 'numpy.array', 'np.array', (['speakers_batch'], {}), '(speakers_batch)\n', (6993, 7009), True, 'import numpy as np\n'), ((14698, 14721), 'numpy.array', 'np.array', (['targets_batch'], {}), '(targets_batch)\n', (14706, 14721), True, 'import numpy as np\n'), ((14876, 14908), 'numpy.array', 'np.array', (['sentences_length_batch'], {}), '(sentences_length_batch)\n', (14884, 14908), True, 'import numpy as np\n'), ((18188, 18211), 'numpy.array', 'np.array', (['targets_batch'], {}), '(targets_batch)\n', (18196, 18211), True, 'import numpy as np\n'), ((18366, 18398), 'numpy.array', 'np.array', (['sentences_length_batch'], {}), '(sentences_length_batch)\n', (18374, 18398), True, 'import numpy as np\n'), ((6874, 6897), 'numpy.array', 'np.array', (['targets_batch'], {}), '(targets_batch)\n', (6882, 6897), True, 'import numpy as np\n'), ((7068, 7100), 'numpy.array', 'np.array', (['sentences_length_batch'], {}), '(sentences_length_batch)\n', (7076, 7100), True, 'import numpy as np\n')]