Huge embedding output file
Hi, I am trying to extract BERT embeddings in order to put them as initial embeddings of a DNN for a sentiment classification task. My dataset is made of 95k examples of sentences and my idea is to extract BERT features for every sentence (I don't know if it's the best idea), like the documentation proposes (https://github.com/google-research/bert#using-bert-to-extract-fixed-feature-vectors-like-elmo).
Extracting features only for 1k examples for last 4 hidden layers for every token of every sentence, I got a very big output file (1.9 GB), so I think that for about 100k examples I would get a file of 190 GB for my entire dataset (didn't try :) ). Is there something that I am missing ? Any advice is accepted.
Thanks
Yes I mention this in the README, there's no great solution for it and it's one of the major downsides of the feature-based approach (people have really struggled with this for ELMo also, even inside of Google).
A few possibilities are:
(1) Change the script to average the output of the last 4 layers rather than print them all out. This doesn't do as well as concatenation but still does better than using a single layer. This will save you 4x.
(2) Change the script to output a binary format instead of json. This should save you a bit (and will also make loading them in much faster). Converting them to tf.train.Example serialized to a TFRecordIO is the standard way of doing this.
(3) Extract out the vectors on the fly. This will make fine-tuning much slower but the memory requirements of BERT are much less when you're not backprogating.
@jacobdevlin-google In the above, you mentioned Extract out the vectors on the fly, but how? Can you provide more details? thanks very much!!!
You just have to integrate the BERT model in your code.