import json
import multiprocessing

import matplotlib
matplotlib.use('TKAgg')

import matplotlib.pyplot as plt
import tqdm

plt.rc('font', size=6)

all_scores = json.load(open('test_verification_results_attention_scores_0_1022_34deba3839409dc19885.table.json', 'r'))
n_jobs = 10

def create_plot(index):

    tokens, scores = all_scores['data'][index]

    # Remove weird looking character (signaling that the token comes in the middle of the sentence?)
    # from each token
    tokens = [t.replace("Ġ", "") for t in tokens]

    for head in range(len(scores)):
        plt.figure(figsize=(25, 3), dpi=200)

        plt.bar(range(len(scores[head])), scores[head], width=0.5)

        plt.xticks(range(len(scores[head])), tokens, rotation='vertical')

        plt.savefig(str(head) + '_' + str(index) + '.png', bbox_inches='tight')

        plt.close()


with multiprocessing.Pool(n_jobs) as p:
    indexes = list(range(len(all_scores['data'])))
    results = list(tqdm.tqdm(p.imap(create_plot, indexes), total=len(indexes)))


import json
import multiprocessing

import matplotlib
matplotlib.use('TKAgg')

import matplotlib.pyplot as plt
import tqdm

plt.rc('font', size=6)

all_scores = json.load(open('test_verification_results_attention_scores_0_1022_34deba3839409dc19885.table.json', 'r'))
n_jobs = 10

def create_plot(index):

    tokens, scores = all_scores['data'][index]

    # Remove weird looking character (signaling that the token comes in the middle of the sentence?)
    # from each token
    tokens = [t.replace("Ġ", "") for t in tokens]

    for head in range(len(scores)):
        plt.figure(figsize=(25, 3), dpi=200)

        plt.bar(range(len(scores[head])), scores[head], width=0.5)

        plt.xticks(range(len(scores[head])), tokens, rotation='vertical')

        plt.savefig(str(head) + '_' + str(index) + '.png', bbox_inches='tight')

        plt.close()


with multiprocessing.Pool(n_jobs) as p:
    indexes = list(range(len(all_scores['data'])))
    results = list(tqdm.tqdm(p.imap(create_plot, indexes), total=len(indexes)))


# Remove weird looking character (signaling that the token comes in the middle of the sentence?) # from each token