How to load a google's bert ckpt using tf2
Is there any way to load a google released ckpt inhttps://github.com/google-research/bert(because some settings are not provided in hf transformers) using tf 2+ ?I’ve found docs on loading those models and converting them to pytorch models in here:https://huggingface.co/transformers/converting_tensorflow_models.htmlHowever, it only works with pytorch.
2020-08-06T17:15:57Z
Have you looked at using the keras-bert library (instead of using huggingface transformers library)?GitHubGitHub - CyberZHG/keras-bert: Implementation of BERT that could load official...Implementation of BERT that could load official pre-trained models for feature extraction and prediction - GitHub - CyberZHG/keras-bert: Implementation of BERT that could load official pre-trained ...keras-bert works with TF2.   I used it to load a bert model from the tensorflow hub into colab.   I copied it onto my google drive first, and loaded from that copy, but I believe it is also possible to load directly using!wget -qhttps://storage.googleapis.com/bert_models/2018_10_18/uncased_L-12_H-768_A-12.zip!unzip -o uncased_L-12_H-768_A-12.zipSo far as I can tell, models loaded with keras-bert are not compatible with transformers.  I tried to get my fine-tuned model into transformers format (because I wanted to use Jesse Vig’s visualisations), but I never got it to work.I believe there is something about the way the transformers code is written that means you can’t use non-transformers models in place of transformers models, or at least not without some serious poking of the python.   However, I could be mistaken.
2020-08-07T10:19:40Z
Hello again, it looks like I was mistaken.The suggestion to use keras-bert instead still stands, but I’ve had another look at the transformers documentation and it certainly looks like it should be possible to use the google models within transformers.  See eg this issuehttps://github.com/huggingface/transformers/issues/3070.Are you explicitly loading the google model’s config file?What happens if you try using the first part of the pytorch conversion script to read the google model in?
2020-08-14T11:41:17Z
Thanks a lot for your comments!Yes I’m explicitly loading the config file, which I believe is almost the same in both tf and pytorch.I’ve tried to use the pytorch conversion script to load the model in pytorch and then convert the pytorch model to tensorflow model, but I can’t find any scripts to convert the pytorch model to tensorflow one…However, I’ve found a workaround, which is a temper fix: Since the may problem is the mismatch of tensor names, I load the google checkpoint file and rename tensors to match those in transformers. Fortunately the mismatches are easily located and only need sightly modification.