How to get the probability of masked words with pre-trained model
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?
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.