def get_captions(captions):
    """ Group captions by image """
    image_captions = {}
    for caption in captions:
        img_id = caption['image_id']
        if not img_id in image_captions:
            image_captions[img_id] = []
        parsed_caption = caption['caption'].strip()
        parsed_caption = ''.join(parsed_caption.split('\n'))  # remove '\n' from the end of the caption
        image_captions[img_id].append(parsed_caption)
    return image_captions