sgrvinod / a-PyTorch-Tutorial-to-Image-Captioning

Show, Attend, and Tell | a PyTorch Tutorial to Image Captioning
MIT License
2.77k stars 716 forks source link

Why do you use log_softmax in sampling? #38

Open RodinIvan opened 5 years ago

RodinIvan commented 5 years ago

In line 94 in caption.py you use: scores = F.log_softmax(scores, dim=1)

Could you explain the reason for log_softmax here? You did not use it in forward() method.

More than that, I tried your model on my dataset and got BLEU = 0.16 on test set with that code for captioning. It produced almost similar captions for all images. But when i removed log_softmax line I got BLEU = 0.60... and I'm a little bit confused with that.

fawazsammani commented 5 years ago

@RodinIvan log_softmax is used to implement beam search. In beam search, you take the log_softmax of the concatenated scores, as opposed to taking the softmax only like after the cross entropy loss. This is how beam search is implemented.