BERT returns different embedding for same sentence
I am using pre-trained BERT for creating features, for same sentence it produces different result in two different runs. Do we have to set some random state to produce consistent result? I am using pytorch-transformers for reading pre-trained model.
Are you initializing from a pretrained model? If no, than this is normal behaviour: your weights are randomly initialized. If yes, make sure your model is in evaluation mode (model.eval()), this disables dropout and other random modules.
Thank you for quick response @srslynow . how to initialize weights and biases fora pre-trained model ? I thought weights and biases freezes after training.
you were right , I missed the model.eval() that's the reason I was getting slightly different embedding on each run becz of dropout layer.