def graph(dirs, save_file, average_window=100):
    """ Plot the training and validation costs over iterations
    Params:
        dirs (list(str)): Directories where the model and costs are saved
        save_file (str): Filename of the output plot
        average_window (int): Window size for smoothening the graphs
    """
    fig, ax = plt.subplots()
    ax.set_xlabel('Iters')
    ax.set_ylabel('Loss')
    average_filter = np.ones(average_window) / float(average_window)

    for i, d in enumerate(dirs):
        name = os.path.basename(os.path.abspath(d))
        color = colors[i % len(colors)]
        costs = np.load(os.path.join(d, 'costs.npz'))
        train_costs = costs['train']
        valid_costs = costs['validation'].tolist()
        iters = train_costs.shape[0]
        valid_range = [500 * (i + 1) for i in range(iters // 500)]
        if len(valid_range) != len(valid_costs):
            valid_range.append(iters)
        if train_costs.ndim == 1:
            train_costs = np.convolve(train_costs, average_filter,
                                      mode='valid')
        ax.plot(train_costs, color=color, label=name + '_train', lw=1.5)
        ax.plot(valid_range, valid_costs[:len(valid_range)],
                '-o', color=color, label=name + '_valid')
    ax.grid(True)
    ax.legend(loc='best')
    plt.savefig(save_file)
 Plot the training and validation costs over iterations
    Params:
        dirs (list(str)): Directories where the model and costs are saved
        save_file (str): Filename of the output plot
        average_window (int): Window size for smoothening the graphs
    
plot.py