bert icon indicating copy to clipboard operation
bert copied to clipboard

can the pre-trained model be used as a language model?

Open wangwang110 opened this issue 8 years ago • 6 comments

how can we use the pre-trained model to get the probability of one sentence?

wangwang110 avatar Nov 02 '18 07:11 wangwang110

It can't, you can only use it to get probabilities if a single missing word in a sentence (or a small number of missing words). This is one of the fundamental ideas, that masked LMs give you deep bidirectionality, but you no longer have a well-formed probability distribution over the sentence (which in general, we don't care about).

jacobdevlin-google avatar Nov 02 '18 17:11 jacobdevlin-google

What about mask each word sequentially. Then score sentence by summary of word score.

xu-song avatar Nov 20 '18 09:11 xu-song

using BERT as a language Model · Issue #37 · huggingface/pytorch-pretrained-BERT

It's actually like what @jacobdevlin-google have said, bert is really not a language model.

hscspring avatar Apr 10 '19 08:04 hscspring

What about mask each word sequentially. Then score sentence by summary of word score.

That way your calculation won't be correct.

Let's say the sentence has only two tokens x1 and x2. Your calculation well give P(x1 | x2) * P(x2 | x1), which doesn't lead to the probability of the whole sentence. Note that this is not to say what you intended was not doable -- it's just that your way probably won't work.

WolfNiu avatar Apr 18 '19 22:04 WolfNiu

Alex Wang and Kyunghyun Cho are using in BERT has a Mouth, and It Must Speak: BERT as a Markov Random Field Language Model the unnormalized log-probabilities to rank a set of sentences. For this purpose it seems to work.

Bachstelze avatar Apr 30 '19 08:04 Bachstelze

You can fine-tune BERT to be LM: https://arxiv.org/abs/1904.09408

Shujian2015 avatar May 31 '19 13:05 Shujian2015