'iterates over items in the batch and calls generators on them'

@staticmethod
def forward(batch, model, params, misc, predict_mode=False):

    F = np.row_stack((x['image']['feat'] for x in batch))
    We = model['We']
    be = model['be']
    Xe = (F.dot(We) + be)
    generator_str = params.get('generator', 'lstm')
    Generator = decodeGenerator(generator_str)
    wordtoix = misc['wordtoix']
    Ws = model['Ws']
    gen_caches = []
    Ys = []
    for (i, x) in enumerate(batch):
        ix = ([0] + [wordtoix[w] for w in x['sentence']['tokens'] if (w in wordtoix)])
        Xs = np.row_stack([Ws[j, :] for j in ix])
        Xi = Xe[i, :]
        (gen_Y, gen_cache) = Generator.forward(Xi, Xs, model, params, predict_mode=predict_mode)
        gen_caches.append((ix, gen_cache))
        Ys.append(gen_Y)
    cache = {}
    if (not predict_mode):
        cache['gen_caches'] = gen_caches
        cache['Xe'] = Xe
        cache['Ws_shape'] = Ws.shape
        cache['F'] = F
        cache['generator_str'] = generator_str
    return (Ys, cache)
