{
  "id": 244294,
  "title": "TF hub BERT or HuggingFace BERT for competitions witout internet??",
  "url": "/competitions/coleridgeinitiative-show-us-the-data/discussion/244294",
  "author_name": "",
  "post_date": "2021-06-06T03:04:47.965617900Z",
  "votes": 5,
  "comment_count": 7,
  "views": 0,
  "content": "<p>Thanks for your time!!</p>\n<p>I am facing an issue, when trying to use BERT from tensorflow in the notebook without internet ON for predictions. </p>\n<p>I have downloaded TF BERT preprocessing and encoder pre-trained models and created a dataset. From dataset, tried to load these pre-trained models using tensorflow hub and getting errors.</p>\n<p>Few solutions on the net were like, install tensorflow_text(and import the same), and tensorflow_io etc … none didnt work and will not work, if internet is off.</p>\n<p>My question is, is it possible to use the tf hub models for competitions?? OR, huggingFace BERT is the alternative solution??</p>\n<pre><code>    import tensorflow as tf\n    import tensorflow_hub as hub\n\n    model_path = \"../input/bert-en-uncased-l12-h768-a124-jun5-2021/bert_en_uncased_preprocess_3\"\n    preprocessor = tf.keras.models.load_model(model_path)#hub.KerasLayer(hub.load(model_path))\n    #\"https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3\")\n    #\"https://tfhub.dev/tensorflow/albert_en_preprocess/3\")\n\n    encoder = hub.KerasLayer(\n    \"../input/bert-en-uncased-l12-h768-a124-jun5-2021/bert_en_uncased_L-12_H-768_A-12_4\",\n    #\"https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/3\",\n    #    \"https://tfhub.dev/tensorflow/albert_en_base/3\",\n    trainable=True)\n</code></pre>\n<p>Experts, please throw some light on using BERT models on Kaggle!<br>\nThanks.</p>",
  "messages": [
    {
      "id": "1337918",
      "postDate": "06/06/2021 03:04:47",
      "content": "<p>Thanks for your time!!</p>\n<p>I am facing an issue, when trying to use BERT from tensorflow in the notebook without internet ON for predictions. </p>\n<p>I have downloaded TF BERT preprocessing and encoder pre-trained models and created a dataset. From dataset, tried to load these pre-trained models using tensorflow hub and getting errors.</p>\n<p>Few solutions on the net were like, install tensorflow_text(and import the same), and tensorflow_io etc … none didnt work and will not work, if internet is off.</p>\n<p>My question is, is it possible to use the tf hub models for competitions?? OR, huggingFace BERT is the alternative solution??</p>\n<pre><code>    import tensorflow as tf\n    import tensorflow_hub as hub\n\n    model_path = \"../input/bert-en-uncased-l12-h768-a124-jun5-2021/bert_en_uncased_preprocess_3\"\n    preprocessor = tf.keras.models.load_model(model_path)#hub.KerasLayer(hub.load(model_path))\n    #\"https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3\")\n    #\"https://tfhub.dev/tensorflow/albert_en_preprocess/3\")\n\n    encoder = hub.KerasLayer(\n    \"../input/bert-en-uncased-l12-h768-a124-jun5-2021/bert_en_uncased_L-12_H-768_A-12_4\",\n    #\"https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/3\",\n    #    \"https://tfhub.dev/tensorflow/albert_en_base/3\",\n    trainable=True)\n</code></pre>\n<p>Experts, please throw some light on using BERT models on Kaggle!<br>\nThanks.</p>",
      "rawMarkdown": "Thanks for your time!!\n\nI am facing an issue, when trying to use BERT from tensorflow in the notebook without internet ON for predictions. \n\nI have downloaded TF BERT preprocessing and encoder pre-trained models and created a dataset. From dataset, tried to load these pre-trained models using tensorflow hub and getting errors.\n\nFew solutions on the net were like, install tensorflow_text(and import the same), and tensorflow_io etc ... none didnt work and will not work, if internet is off.\n\nMy question is, is it possible to use the tf hub models for competitions?? OR, huggingFace BERT is the alternative solution??\n\n```\n    import tensorflow as tf\n    import tensorflow_hub as hub\n\n    model_path = \"../input/bert-en-uncased-l12-h768-a124-jun5-2021/bert_en_uncased_preprocess_3\"\n    preprocessor = tf.keras.models.load_model(model_path)#hub.KerasLayer(hub.load(model_path))\n    #\"https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3\")\n    #\"https://tfhub.dev/tensorflow/albert_en_preprocess/3\")\n\n    encoder = hub.KerasLayer(\n    \"../input/bert-en-uncased-l12-h768-a124-jun5-2021/bert_en_uncased_L-12_H-768_A-12_4\",\n    #\"https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/3\",\n    #    \"https://tfhub.dev/tensorflow/albert_en_base/3\",\n    trainable=True)\n```\n\nExperts, please throw some light on using BERT models on Kaggle!\nThanks.",
      "votes": null
    },
    {
      "id": "1338055",
      "postDate": "06/06/2021 06:14:00",
      "content": "<p>I created Kaggle datasets for TF huggingface tokenizers and pretrained models as follows:</p>\n<ul>\n<li><a href=\"https://www.kaggle.com/jeongyoonlee/tfbert-base-uncased\" target=\"_blank\">TF BERT Base Uncased Pretrained Model/Tokenizer</a></li>\n<li><a href=\"https://www.kaggle.com/jeongyoonlee/tfbert-large-uncased\" target=\"_blank\">TF BERT Large Uncased Pretrained Model/Tokenizer</a></li>\n<li><a href=\"https://www.kaggle.com/jeongyoonlee/tfroberta-base\" target=\"_blank\">TF RoBERTa Base Model/Tokenizer</a></li>\n<li><a href=\"https://www.kaggle.com/jeongyoonlee/tfroberta-large\" target=\"_blank\">TF RoBERTa Large Model/Tokenizer</a></li>\n<li><a href=\"https://www.kaggle.com/jeongyoonlee/tfbart-base\" target=\"_blank\">TF BART Base Pretrained Model/Tokenizer</a></li>\n<li><a href=\"https://www.kaggle.com/jeongyoonlee/tfbart-large\" target=\"_blank\">TF BART Large Pretrained Model/Tokenizer</a></li>\n</ul>\n<p>You can add them as datasets to your notebook to use them. </p>",
      "rawMarkdown": "I created Kaggle datasets for TF huggingface tokenizers and pretrained models as follows:\n* [TF BERT Base Uncased Pretrained Model/Tokenizer](https://www.kaggle.com/jeongyoonlee/tfbert-base-uncased)\n* [TF BERT Large Uncased Pretrained Model/Tokenizer](https://www.kaggle.com/jeongyoonlee/tfbert-large-uncased)\n* [TF RoBERTa Base Model/Tokenizer](https://www.kaggle.com/jeongyoonlee/tfroberta-base)\n* [TF RoBERTa Large Model/Tokenizer](https://www.kaggle.com/jeongyoonlee/tfroberta-large)\n* [TF BART Base Pretrained Model/Tokenizer](https://www.kaggle.com/jeongyoonlee/tfbart-base)\n* [TF BART Large Pretrained Model/Tokenizer](https://www.kaggle.com/jeongyoonlee/tfbart-large)\n\nYou can add them as datasets to your notebook to use them.",
      "votes": null
    },
    {
      "id": "1338087",
      "postDate": "06/06/2021 06:56:58",
      "content": "<p>Great and thanks for the datasets. Checking out your notebooks on these datasets. Shall try out the code from there 👍🙏</p>\n<p><strong>EDIT</strong></p>\n<p>I was able to successfully load from above datasets using the code from your notebook <a href=\"https://www.kaggle.com/jeongyoonlee/tf-keras-bert-baseline-training-inference\" target=\"_blank\">link</a></p>",
      "rawMarkdown": "Great and thanks for the datasets. Checking out your notebooks on these datasets. Shall try out the code from there 👍🙏\n\n**EDIT**\n\nI was able to successfully load from above datasets using the code from your notebook [link](https://www.kaggle.com/jeongyoonlee/tf-keras-bert-baseline-training-inference)",
      "votes": null
    },
    {
      "id": "1338289",
      "postDate": "06/06/2021 10:26:45",
      "content": "<p>Hey <a href=\"https://www.kaggle.com/Jeong-Yoon\" target=\"_blank\">@Jeong-Yoon</a> Lee, Thanks for the above datasets. Do you have any documentation on how to save the tf hub models? I have tried using the .pb format but was unable to load the model successfully.</p>",
      "rawMarkdown": "Hey @Jeong-Yoon Lee, Thanks for the above datasets. Do you have any documentation on how to save the tf hub models? I have tried using the .pb format but was unable to load the model successfully.",
      "votes": null
    },
    {
      "id": "1338798",
      "postDate": "06/06/2021 18:28:41",
      "content": "<p>You can save them as HDF5 (tf_model.h5) instead of protobuf as follows:</p>\n<pre><code>bert_model = TFBertModel.from_pretrained(\"bert-large-uncased\", config=config)\nbert_model.save_pretrained(pretrained_dir)\n</code></pre>",
      "rawMarkdown": "You can save them as HDF5 (tf_model.h5) instead of protobuf as follows:\n```python\nbert_model = TFBertModel.from_pretrained(\"bert-large-uncased\", config=config)\nbert_model.save_pretrained(pretrained_dir)\n```",
      "votes": null
    },
    {
      "id": "1339335",
      "postDate": "06/07/2021 07:29:56",
      "content": "<p><a href=\"https://www.kaggle.com/mannyjain\" target=\"_blank\">@mannyjain</a> Are you asking about, how to download(and then save) from tf hub or do transfer learning on tf hub models and then save?? if it is second one, you can follow as in above comment.</p>",
      "rawMarkdown": "mannyjain Are you asking about, how to download(and then save) from tf hub or do transfer learning on tf hub models and then save?? if it is second one, you can follow as in above comment.",
      "votes": null
    },
    {
      "id": "1342118",
      "postDate": "06/09/2021 07:39:46",
      "content": "<p><a href=\"https://www.kaggle.com/jeongyoonlee\" target=\"_blank\">@jeongyoonlee</a> which BERT do you suggest for NER task??<br>\nCased vs uncased<br>\nbase vs large<br>\nBERT vs RoBERTa vs BART etc?<br>\nThanks</p>",
      "rawMarkdown": "jeongyoonlee which BERT do you suggest for NER task??\nCased vs uncased\nbase vs large\nBERT vs RoBERTa vs BART etc?\nThanks",
      "votes": null
    },
    {
      "id": "1342457",
      "postDate": "06/09/2021 13:22:09",
      "content": "<p>Generally speaking, large models perform better but require more resources (time, computation). So during initial prototyping, people experiment with base models, then move to large models later.</p>\n<p>If cases are important, I think, as in this competition, use cased. Otherwise use uncased.</p>\n<p>Most of PyTorch baselines use either BERT or RoBERTa. RoBERTa models seem to perform slightly better than BERT, but at the end, you need to try them all and see which one performs best in each competition.</p>\n<p>Good luck!</p>",
      "rawMarkdown": "Generally speaking, large models perform better but require more resources (time, computation). So during initial prototyping, people experiment with base models, then move to large models later.\n\nIf cases are important, I think, as in this competition, use cased. Otherwise use uncased.\n\nMost of PyTorch baselines use either BERT or RoBERTa. RoBERTa models seem to perform slightly better than BERT, but at the end, you need to try them all and see which one performs best in each competition.\n\nGood luck!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1338055,
      "author_name": "jeongyoonlee",
      "author_url": "",
      "post_date": "06/06/2021 06:14:00",
      "content": "<p>I created Kaggle datasets for TF huggingface tokenizers and pretrained models as follows:</p>\n<ul>\n<li><a href=\"https://www.kaggle.com/jeongyoonlee/tfbert-base-uncased\" target=\"_blank\">TF BERT Base Uncased Pretrained Model/Tokenizer</a></li>\n<li><a href=\"https://www.kaggle.com/jeongyoonlee/tfbert-large-uncased\" target=\"_blank\">TF BERT Large Uncased Pretrained Model/Tokenizer</a></li>\n<li><a href=\"https://www.kaggle.com/jeongyoonlee/tfroberta-base\" target=\"_blank\">TF RoBERTa Base Model/Tokenizer</a></li>\n<li><a href=\"https://www.kaggle.com/jeongyoonlee/tfroberta-large\" target=\"_blank\">TF RoBERTa Large Model/Tokenizer</a></li>\n<li><a href=\"https://www.kaggle.com/jeongyoonlee/tfbart-base\" target=\"_blank\">TF BART Base Pretrained Model/Tokenizer</a></li>\n<li><a href=\"https://www.kaggle.com/jeongyoonlee/tfbart-large\" target=\"_blank\">TF BART Large Pretrained Model/Tokenizer</a></li>\n</ul>\n<p>You can add them as datasets to your notebook to use them. </p>",
      "votes": null,
      "replies": [
        {
          "id": 1338087,
          "author_name": "jkreddy",
          "author_url": "",
          "post_date": "06/06/2021 06:56:58",
          "content": "<p>Great and thanks for the datasets. Checking out your notebooks on these datasets. Shall try out the code from there 👍🙏</p>\n<p><strong>EDIT</strong></p>\n<p>I was able to successfully load from above datasets using the code from your notebook <a href=\"https://www.kaggle.com/jeongyoonlee/tf-keras-bert-baseline-training-inference\" target=\"_blank\">link</a></p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1338289,
          "author_name": "mannyjain",
          "author_url": "",
          "post_date": "06/06/2021 10:26:45",
          "content": "<p>Hey <a href=\"https://www.kaggle.com/Jeong-Yoon\" target=\"_blank\">@Jeong-Yoon</a> Lee, Thanks for the above datasets. Do you have any documentation on how to save the tf hub models? I have tried using the .pb format but was unable to load the model successfully.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1338798,
          "author_name": "jeongyoonlee",
          "author_url": "",
          "post_date": "06/06/2021 18:28:41",
          "content": "<p>You can save them as HDF5 (tf_model.h5) instead of protobuf as follows:</p>\n<pre><code>bert_model = TFBertModel.from_pretrained(\"bert-large-uncased\", config=config)\nbert_model.save_pretrained(pretrained_dir)\n</code></pre>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1339335,
          "author_name": "jkreddy",
          "author_url": "",
          "post_date": "06/07/2021 07:29:56",
          "content": "<p><a href=\"https://www.kaggle.com/mannyjain\" target=\"_blank\">@mannyjain</a> Are you asking about, how to download(and then save) from tf hub or do transfer learning on tf hub models and then save?? if it is second one, you can follow as in above comment.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1342118,
      "author_name": "jkreddy",
      "author_url": "",
      "post_date": "06/09/2021 07:39:46",
      "content": "<p><a href=\"https://www.kaggle.com/jeongyoonlee\" target=\"_blank\">@jeongyoonlee</a> which BERT do you suggest for NER task??<br>\nCased vs uncased<br>\nbase vs large<br>\nBERT vs RoBERTa vs BART etc?<br>\nThanks</p>",
      "votes": null,
      "replies": [
        {
          "id": 1342457,
          "author_name": "jeongyoonlee",
          "author_url": "",
          "post_date": "06/09/2021 13:22:09",
          "content": "<p>Generally speaking, large models perform better but require more resources (time, computation). So during initial prototyping, people experiment with base models, then move to large models later.</p>\n<p>If cases are important, I think, as in this competition, use cased. Otherwise use uncased.</p>\n<p>Most of PyTorch baselines use either BERT or RoBERTa. RoBERTa models seem to perform slightly better than BERT, but at the end, you need to try them all and see which one performs best in each competition.</p>\n<p>Good luck!</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1337918": "Thanks for your time!!\n\nI am facing an issue, when trying to use BERT from tensorflow in the notebook without internet ON for predictions. \n\nI have downloaded TF BERT preprocessing and encoder pre-trained models and created a dataset. From dataset, tried to load these pre-trained models using tensorflow hub and getting errors.\n\nFew solutions on the net were like, install tensorflow_text(and import the same), and tensorflow_io etc ... none didnt work and will not work, if internet is off.\n\nMy question is, is it possible to use the tf hub models for competitions?? OR, huggingFace BERT is the alternative solution??\n\n```\n    import tensorflow as tf\n    import tensorflow_hub as hub\n\n    model_path = \"../input/bert-en-uncased-l12-h768-a124-jun5-2021/bert_en_uncased_preprocess_3\"\n    preprocessor = tf.keras.models.load_model(model_path)#hub.KerasLayer(hub.load(model_path))\n    #\"https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3\")\n    #\"https://tfhub.dev/tensorflow/albert_en_preprocess/3\")\n\n    encoder = hub.KerasLayer(\n    \"../input/bert-en-uncased-l12-h768-a124-jun5-2021/bert_en_uncased_L-12_H-768_A-12_4\",\n    #\"https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/3\",\n    #    \"https://tfhub.dev/tensorflow/albert_en_base/3\",\n    trainable=True)\n```\n\nExperts, please throw some light on using BERT models on Kaggle!\nThanks.",
    "1338055": "I created Kaggle datasets for TF huggingface tokenizers and pretrained models as follows:\n* [TF BERT Base Uncased Pretrained Model/Tokenizer](https://www.kaggle.com/jeongyoonlee/tfbert-base-uncased)\n* [TF BERT Large Uncased Pretrained Model/Tokenizer](https://www.kaggle.com/jeongyoonlee/tfbert-large-uncased)\n* [TF RoBERTa Base Model/Tokenizer](https://www.kaggle.com/jeongyoonlee/tfroberta-base)\n* [TF RoBERTa Large Model/Tokenizer](https://www.kaggle.com/jeongyoonlee/tfroberta-large)\n* [TF BART Base Pretrained Model/Tokenizer](https://www.kaggle.com/jeongyoonlee/tfbart-base)\n* [TF BART Large Pretrained Model/Tokenizer](https://www.kaggle.com/jeongyoonlee/tfbart-large)\n\nYou can add them as datasets to your notebook to use them.",
    "1338087": "Great and thanks for the datasets. Checking out your notebooks on these datasets. Shall try out the code from there 👍🙏\n\n**EDIT**\n\nI was able to successfully load from above datasets using the code from your notebook [link](https://www.kaggle.com/jeongyoonlee/tf-keras-bert-baseline-training-inference)",
    "1338289": "Hey @Jeong-Yoon Lee, Thanks for the above datasets. Do you have any documentation on how to save the tf hub models? I have tried using the .pb format but was unable to load the model successfully.",
    "1338798": "You can save them as HDF5 (tf_model.h5) instead of protobuf as follows:\n```python\nbert_model = TFBertModel.from_pretrained(\"bert-large-uncased\", config=config)\nbert_model.save_pretrained(pretrained_dir)\n```",
    "1339335": "mannyjain Are you asking about, how to download(and then save) from tf hub or do transfer learning on tf hub models and then save?? if it is second one, you can follow as in above comment.",
    "1342118": "jeongyoonlee which BERT do you suggest for NER task??\nCased vs uncased\nbase vs large\nBERT vs RoBERTa vs BART etc?\nThanks",
    "1342457": "Generally speaking, large models perform better but require more resources (time, computation). So during initial prototyping, people experiment with base models, then move to large models later.\n\nIf cases are important, I think, as in this competition, use cased. Otherwise use uncased.\n\nMost of PyTorch baselines use either BERT or RoBERTa. RoBERTa models seem to perform slightly better than BERT, but at the end, you need to try them all and see which one performs best in each competition.\n\nGood luck!"
  },
  "source": "meta"
}