# BERT training on two tasks: what is the order of tasks?

I read that BERT has been trained on two tasks: Masked Language Modeling and Next Sentence Prediction. I want to gain clarity how exactly it was done.

Was it initially trained on Masked Language Modeling (where we predict masked token) and later on Sentence Prediction (where we predict isnext or not)? It seems like these two tasks would require different architecture. Does BERT has some common architecture for these two tasks with interchanging layer for individual tasks? Still question of ordering remains.

BERT is trained on both task at the same time.

• MLM is done using the token representations.
• NSP is done using the CLS representation.
• Thank you! As far as I underststand token representation in multi class and Sentence prediction is binary. How are they represented in cost function? Are these two tasks concatenated? Nov 8 '19 at 14:15
• You understood right :) To run the 2 tasks together they compute the loss of each task and sum it. You can see it here in the official source code. Nov 10 '19 at 23:30
• Great solution to look at source code! Nov 11 '19 at 12:32