BERT-keras icon indicating copy to clipboard operation
BERT-keras copied to clipboard

Poor performance and poor results

Open astariul opened this issue 6 years ago • 5 comments

I'm trying to fine tune BERT on STS-B dataset.

I used the following notebook to fine tune it using BERT-keras. (As described in the paper, I just added a classification layer using the CLS token of the output of BERT).

However, there is great differences in performance and results between this notebook and the script used in the official version for fine tuning :

BERT-keras Official BERT
Pearson 0.0254 0.8956
Spearman 0.0289 0.7942
MSE 2.2691 0.5456
Training time 9h 10min

Note : Pearson / Spearman and correlation metrics used to evaluate the accuracy on the STS-B dataset


Why there is such a difference between the 2 approach ?

astariul avatar Dec 20 '18 00:12 astariul

Hmm, 9 hours compared to 10 minutes? wow, that is horrible, sadly though I'm swamped with work and can't figure out what's wrong (I checked your code and it seems fine). @HighCWu do you have any ideas?

Separius avatar Dec 20 '18 12:12 Separius

I guess it should be caused by a small batch size. Have you used the same training batch size and the same epoch as the official? @Colanim large batch size keeps the training steady, but it also means that the training time will be longer. If it is the same batch size and epoch, then the problem may be in this implementation.

HighCWu avatar Dec 20 '18 13:12 HighCWu

Thanks for the answer. I used same epoch. With the official implementation I used batch size of 32, with this one batch size of 64, so I don't think the problem come from here.

I think there is a problem in my code, because 9h ! Compare to 10 with the tensorflow script, this is weird..

astariul avatar Dec 20 '18 23:12 astariul

I tried this code and https://github.com/hanxiao/bert-as-service to get sentence representation, and tensorflow is much faster, like 200ms vs 2000ms

MrKamiZhou avatar Jan 18 '19 09:01 MrKamiZhou

Thanks @MrKamiZhou, so I'm guessing that something is wrong here because Keras shouldn't be this slow. I will try to figure it out as soon as I have some free time.

Separius avatar Feb 02 '19 19:02 Separius