BLIP icon indicating copy to clipboard operation
BLIP copied to clipboard

add support for num_return_sequences to BLIP_Decoder.generate ?

Open labenz opened this issue 3 years ago • 3 comments

Congrats on creating such an effective image captioner! I'm using it in a project, and noticing that it's popping up in quite a few other places as well.

Inspired in part by this paper – https://arxiv.org/pdf/2205.10747.pdf  – I was wondering if it would be possible to generate multiple candidate captions instead of just one?

It looks like it is possible, at least using the nucleus sampling method, but the value of num_return_sequences is hard-coded = 1 in the Blip_Decoder generate method – see here: https://github.com/salesforce/BLIP/blob/main/models/blip.py#L149

Would it be possible to add num_return_sequences to the generate method arguments and thus get multiple candidate captions?

Thank you!

labenz avatar Jun 12 '22 17:06 labenz

Thanks for the suggestion. It is definitely possible to generate multiple sentences. We do not plan to change the code now in case it break other codes, but feel free to clone the code and change num_return_sequences for yourself.

LiJunnan1992 avatar Jun 13 '22 09:06 LiJunnan1992

Thank you! It seems this only works for nucleus sampling method – is that right? Thanks again. :)

labenz avatar Jun 13 '22 16:06 labenz

You can also return multiple sentences with beam search, please refer to the generate function description here: https://huggingface.co/docs/transformers/main/en/main_classes/text_generation

LiJunnan1992 avatar Jun 14 '22 01:06 LiJunnan1992