<commit_before>from keras.models import load_model
import numpy as np

if __name__ == '__main__':
    model = load_model("./saved/1480896779-06-0.40.hdf5")
    with open("log","w") as f:
        predictions = model.predict(np.zeros((2, 12, 8, 8))).flatten()
        f.write(str(predictions))<commit_msg>Add fn to get joint predictions<commit_after>import numpy as np
from data import Dataset
from tqdm import tqdm


def get_joint_accuracy(y_from, y_to, y_from_true, y_to_true):
    num_top = 3
    score = np.zeros((y_to.shape[0],))
    for i in tqdm(range(y_to.shape[0])):
        from_square_true = np.where(y_from_true[i] == 1)[0]
        to_square_true = np.where(y_to_true[i] == 1)[0]
        p = np.outer(y_from[i], y_to[i])
        p_shape = p.shape
        p = p.reshape((-1,))

        for j, idx in enumerate(np.argsort(p)[::-1]):
            if j >= num_top:
                break
            from_square, to_square = np.unravel_index(idx, p_shape)
            if from_square == from_square_true and to_square == to_square_true:
                score[i] = 1
                break
    print("Joint move accuracy: %f" % (score.sum() / score.shape[0]))

if __name__ == '__main__':
    d_test = Dataset('data/small_test.pgn')
    X_val, y_from_val, y_to_val = d_test.load(
        'white_state_action_sl',
        featurized=True,
        refresh=False)
    from keras.models import load_model
    model = load_model("./saved/policy/1481219504/94-4.61.hdf5")
    y_from, y_to = model.predict(X_val, verbose=1)
    get_joint_accuracy(y_from, y_to, y_from_val, y_to_val)
{'fraction_non_alphanumeric': 0.13396825396825396, 'fraction_numerical': 0.03111111111111111, 'mean_word_length': 2.8627450980392157, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5339284', 'n_tokens_mistral': 624, 'n_tokens_neox': 590, 'n_words': 119}