<jupyter_start><jupyter_text>Table of Contents1&nbsp;&nbsp;Load libraries2&nbsp;&nbsp;Load data3&nbsp;&nbsp;Train model4&nbsp;&nbsp;Evaluation  Load libraries<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import evaluation
import _pickle as cPickle<jupyter_output><empty_output><jupyter_text>Load data<jupyter_code>data_dir = "./data/"  + "dataset/"

MFCC_LEN_LIM = 700
N_MFCC = 13
FOLDS = 10
def load_data(folds):
    X = []
    y = []
    for fold in folds:
        with open(data_dir + f"data_mfcc_{fold}.pkl", 'rb') as f:
            data_mfcc = cPickle.load(f)

        for i in range(len(data_mfcc['sentence_I'])):
            if data_mfcc['sentence_I'][i].shape[0] < MFCC_LEN_LIM:
                sentence_I = np.zeros((MFCC_LEN_LIM, N_MFCC), dtype=np.float32)
                sentence_I[-data_mfcc['sentence_I'][i].shape[0]:] = data_mfcc['sentence_I'][i]
            else:
                sentence_I = data_mfcc['sentence_I'][i]
                
            if data_mfcc['sentence_II'][i].shape[0] < MFCC_LEN_LIM:
                sentence_II = np.zeros((MFCC_LEN_LIM, N_MFCC), dtype=np.float32)
                sentence_II[-data_mfcc['sentence_II'][i].shape[0]:] = data_mfcc['sentence_II'][i]
            else:
                sentence_II = data_mfcc['sentence_II'][i]
            X.append([sentence_I, sentence_II])
            y.append(data_mfcc['same_speaker'][i])
    return np.array(X), np.array(y)
X_train, y_train = load_data([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
X_train.shape
np.save(data_dir + "data_mfcc_x.npy", X_train)
np.save(data_dir + "data_mfcc_y.npy", y_train)
X_train = np.load(data_dir + "data_mfcc_x.npy")
y_train = np.load(data_dir + "data_mfcc_y.npy")
X_val, y_val = load_data(["val"])
X_val.shape<jupyter_output><empty_output><jupyter_text>Train model<jupyter_code>from modeling.gru_gru import GRU_GRU

model = GRU_GRU(num_features=N_MFCC)
model.fit(X_train, y_train, epochs=100, early_stopping_rounds=7, X_val=X_val, y_val=y_val)
model.save_weights()
model.load_weights()
model.fit(X_train, y_train, epochs=100, early_stopping_rounds=100, X_val=X_val, y_val=y_val)
model.save_weights()<jupyter_output><empty_output><jupyter_text>Evaluation<jupyter_code>model.load_weights()
X_test, y_test = load_data(["test"])
y_pred = model.predict(X_test)
evaluation.plot_confusion_matrix(y_test, y_pred)
evaluation.print_classification_report(y_test, y_pred)
evaluation.get_f1_score(y_test, y_pred, average='macro')<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup