32
$\begingroup$

I am a new learner in NLP. I am interested in the sentence generating task. As far as I am concerned, one state-of-the-art method is the CharRNN, which uses RNN to generate a sequence of words.

However, BERT has come out several weeks ago and is very powerful. Therefore, I am wondering whether this task can also be done with the help of BERT? I am a new learner in this field, and thank you for any advice!

$\endgroup$
2
  • 2
    $\begingroup$ Can OpenAI GPT be used for this? I believe OpenAI GPT has different architecture and is used for text generation $\endgroup$ Commented Mar 20, 2019 at 16:17
  • $\begingroup$ I believe CharRNN is definitely not SOTA, due to the limited context length, from working at the scale of characters. Instead, there is work on subwords, and byte-pair encodings $\endgroup$ Commented Mar 23, 2020 at 0:27

3 Answers 3

35
$\begingroup$

For newbies, NO.

Sentence generation requires sampling from a language model, which gives the probability distribution of the next word given previous contexts. But BERT can't do this due to its bidirectional nature.


For advanced researchers, YES.

You can start with a sentence of all [MASK] tokens, and generate words one by one in arbitrary order (instead of the common left-to-right chain decomposition). Though the text generation quality is hard to control.

Here's the technical report BERT has a Mouth, and It Must Speak: BERT as a Markov Random Field Language Model, its errata and the source code.


In summary:

  • If you would like to do some research in the area of decoding with BERT, there is a huge space to explore
  • If you would like to generate high quality texts, personally I recommend you to check GPT-2.
$\endgroup$
1
  • $\begingroup$ Wouldn’t it be easier for the model, though, to generate high quality text if you let it generate the words from left to right, just like with a language model, instead of having it generate the words in an arbitrary order? I can just imagine if I had to write all words in an arbitrary order whenever I wrote a sentence; it would be pretty difficult to know which word I should write at position seven, for example, if I hadn’t written any word before that. $\endgroup$ Commented Jan 7, 2023 at 13:20
9
$\begingroup$

this experiment by Stephen Mayhew suggests that BERT is lousy at sequential text generation:

http://mayhewsw.github.io/2019/01/16/can-bert-generate-text/

although he had already eaten a large meal, he was still very hungry

As before, I masked “hungry” to see what BERT would predict. If it could predict it correctly without any right context, we might be in good shape for generation.

This failed. BERT predicted “much” as the last word. Maybe this is because BERT thinks the absence of a period means the sentence should continue. Maybe it’s just so used to complete sentences it gets confused. I’m not sure.

One might argue that we should continue predicting after “much”. Maybe it’s going to produce something meaningful. To that I would say: first, this was meant to be a dead giveaway, and any human would predict “hungry”. Second, I tried it, and it keeps predicting dumb stuff. After “much”, the next token is “,”.

So, at least using these trivial methods, BERT can’t generate text.

$\endgroup$
2
$\begingroup$

No. Sentence generating is directly related to language modelling (given the previous words in the sentence, what is the next word). Because of bi-directionality of BERT, BERT cannot be used as a language model. If it cannot be used as language model, I don't see how you can generate a sentence using BERT.

$\endgroup$
4
  • 3
    $\begingroup$ My answer is no longer correct. You may want to accept @soloice 's answer $\endgroup$
    – Astariul
    Commented Feb 18, 2019 at 23:51
  • $\begingroup$ Do alternate options exist for this? $\endgroup$ Commented Jan 31, 2020 at 7:41
  • $\begingroup$ Could one generate a sentence that doesn't make sense? My understanding is the possible combinations of natural language words in a string is infinite (definitely countably infinite, but possibly uncountably infinite.) Although most of the text generated would lack semantic significance, that random generation would also produce plenty of meaningful natural language sentences, given sufficient time and space? $\endgroup$
    – DukeZhou
    Commented Sep 22, 2021 at 21:53
  • $\begingroup$ @Astariul Your answer was never correct, as it was possible all along to generate text with BERT; we just hadn’t realized it yet ;) $\endgroup$ Commented Jan 7, 2023 at 13:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .