bert icon indicating copy to clipboard operation
bert copied to clipboard

How to get the probability of masked words with pre-trained model

Open liweitj47 opened this issue 8 years ago • 1 comments

I want to re-use the projection layer in "tf.variable_scope("cls/predictions")" in run_pretraining.py besides the features, so that I can directly take advantage of the pre-trained model to do tasks like cloze-style problems. Is there an easy way to do so?

liweitj47 avatar Nov 06 '18 09:11 liweitj47

If you just look at the code for run_pretraining.py you can see how the loss is computed, which is giving you log probabilities over the vocabulary. So you can just construct your input like the man went to the [MASK] and bought a gallon of milk and then use the same code from that script.

The catch is that this distribution is over WordPieces, not words. It wasn't really trained to model the joint probability of multiple [MASK] tokens in a row so just multiplying those probabilities probably wont give you what you want.

jacobdevlin-google avatar Nov 06 '18 18:11 jacobdevlin-google