Skip to content

Instantly share code, notes, and snippets.

@shravankumar147
Created December 27, 2021 17:58
Show Gist options
  • Save shravankumar147/5695aa57abdc14726fe8ce911ac615ea to your computer and use it in GitHub Desktop.
Save shravankumar147/5695aa57abdc14726fe8ce911ac615ea to your computer and use it in GitHub Desktop.
Bert Model Download to Local.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Bert Model Download to Local.ipynb",
"provenance": [],
"authorship_tag": "ABX9TyOBETmAYZzF4IEkbv4ywx+I",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/shravankumar147/5695aa57abdc14726fe8ce911ac615ea/bert-model-download-to-local.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"!pip install transformers -q"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "bL4R84__VKxK",
"outputId": "7a709673-db66-4768-f91b-a484e3301a4d"
},
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\u001b[K |████████████████████████████████| 3.4 MB 4.2 MB/s \n",
"\u001b[K |████████████████████████████████| 596 kB 48.8 MB/s \n",
"\u001b[K |████████████████████████████████| 895 kB 47.1 MB/s \n",
"\u001b[K |████████████████████████████████| 61 kB 330 kB/s \n",
"\u001b[K |████████████████████████████████| 3.3 MB 44.8 MB/s \n",
"\u001b[?25h"
]
}
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"id": "NEt06ZTFU3iB"
},
"outputs": [],
"source": [
"# Import generic wrappers\n",
"from transformers import AutoModel, AutoTokenizer \n"
]
},
{
"cell_type": "code",
"source": [
"# Define the model repo\n",
"model_name = \"bert-base-uncased\""
],
"metadata": {
"id": "ZBmuWt0OVAiI"
},
"execution_count": 4,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Download pytorch model\n",
"model = AutoModel.from_pretrained(model_name)\n",
"tokenizer = AutoTokenizer.from_pretrained(model_name)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "tSPeLTNeVC13",
"outputId": "dd4bde37-0672-4692-b443-96c99669c46f"
},
"execution_count": 16,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"Some weights of the model checkpoint at bert-base-uncased were not used when initializing BertModel: ['cls.predictions.transform.dense.weight', 'cls.seq_relationship.weight', 'cls.predictions.bias', 'cls.predictions.transform.dense.bias', 'cls.predictions.transform.LayerNorm.weight', 'cls.predictions.transform.LayerNorm.bias', 'cls.seq_relationship.bias', 'cls.predictions.decoder.weight']\n",
"- This IS expected if you are initializing BertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n",
"- This IS NOT expected if you are initializing BertModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"model.save_pretrained('./') # saving inside content folder"
],
"metadata": {
"id": "BRXeSqwLVvwF"
},
"execution_count": 6,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!wget https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased-vocab.txt"
],
"metadata": {
"id": "EV7wnbtpekGA"
},
"execution_count": 7,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!mv vocab.txt bert_local_model/"
],
"metadata": {
"id": "EiPYURq0g2Xv"
},
"execution_count": 13,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Download pytorch model\n",
"model_local = AutoModel.from_pretrained(\"./bert_local_model/\")\n"
],
"metadata": {
"id": "XYyn_Hq5fNRf"
},
"execution_count": 17,
"outputs": []
},
{
"cell_type": "code",
"source": [
"\n",
"tokenizer_local = AutoTokenizer.from_pretrained(\"./bert_local_model/\")"
],
"metadata": {
"id": "LsBETjfLgsJo"
},
"execution_count": 18,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Transform input tokens \n",
"inputs = tokenizer(\"Hello world!\", return_tensors=\"pt\")\n",
"\n",
"# Model apply\n",
"outputs = model(**inputs)\n",
"print(outputs)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "jRpXk2jihiMw",
"outputId": "2ee7cf65-0a20-427a-a7bd-07f83ef1f886"
},
"execution_count": 19,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"BaseModelOutputWithPoolingAndCrossAttentions(last_hidden_state=tensor([[[-0.1424, 0.1335, -0.1291, ..., -0.3597, -0.0562, 0.3605],\n",
" [-0.3506, 0.1042, 0.6244, ..., -0.1761, 0.4834, 0.0644],\n",
" [-0.2451, -0.1573, 0.6945, ..., -0.5654, -0.0894, -0.1856],\n",
" [-0.8248, -0.9119, -0.6561, ..., 0.5074, -0.1939, -0.1659],\n",
" [ 0.8767, 0.0352, -0.1233, ..., 0.2720, -0.6369, -0.1585]]],\n",
" grad_fn=<NativeLayerNormBackward0>), pooler_output=tensor([[-8.9756e-01, -3.3040e-01, -7.6942e-01, 7.5799e-01, 4.6678e-01,\n",
" -1.2035e-01, 9.1835e-01, 1.8087e-01, -7.2716e-01, -9.9991e-01,\n",
" -4.4723e-01, 8.9104e-01, 9.6621e-01, 5.4915e-01, 9.4344e-01,\n",
" -7.6605e-01, -6.0469e-01, -6.1654e-01, 4.0572e-01, -7.4644e-01,\n",
" 6.1739e-01, 9.9974e-01, 3.2990e-02, 2.5414e-01, 4.3106e-01,\n",
" 9.7732e-01, -8.4328e-01, 9.2297e-01, 9.4871e-01, 6.3994e-01,\n",
" -7.3620e-01, 9.0956e-02, -9.7607e-01, -1.9114e-01, -8.1717e-01,\n",
" -9.7907e-01, 3.1635e-01, -7.2013e-01, 1.6124e-01, 5.1998e-02,\n",
" -8.9102e-01, 2.3002e-01, 9.9967e-01, 1.1504e-02, 1.1176e-01,\n",
" -3.5556e-01, -1.0000e+00, 2.8487e-01, -8.3339e-01, 8.0987e-01,\n",
" 7.4664e-01, 6.2762e-01, 1.9847e-01, 4.5185e-01, 4.7242e-01,\n",
" -3.9167e-03, -1.0570e-01, 9.3340e-02, -1.8906e-01, -5.1946e-01,\n",
" -5.7823e-01, 2.8046e-01, -8.2281e-01, -8.9764e-01, 9.1890e-01,\n",
" 7.4117e-01, -5.9993e-02, -3.1655e-01, 2.8227e-03, -1.4652e-01,\n",
" 9.0953e-01, 2.5587e-01, 5.4493e-02, -8.4187e-01, 5.7772e-01,\n",
" 2.4804e-01, -6.1732e-01, 1.0000e+00, -6.4891e-01, -9.5425e-01,\n",
" 5.5482e-01, 6.8866e-01, 5.5711e-01, -3.3463e-01, 4.7904e-01,\n",
" -1.0000e+00, 3.4198e-01, -1.1332e-01, -9.7818e-01, 2.2887e-01,\n",
" 4.5161e-01, -1.5720e-01, 1.6196e-01, 5.1240e-01, -5.7139e-01,\n",
" -3.7296e-01, -2.8502e-01, -8.0263e-01, -2.1937e-01, -2.2406e-01,\n",
" -5.1871e-03, -2.6417e-01, -2.2839e-01, -3.7414e-01, 2.6933e-01,\n",
" -4.5077e-01, -5.5173e-01, 4.8430e-01, 4.7179e-02, 6.6727e-01,\n",
" 3.3201e-01, -2.9447e-01, 5.0653e-01, -9.4933e-01, 6.1857e-01,\n",
" -2.4586e-01, -9.7565e-01, -5.3396e-01, -9.7924e-01, 5.8934e-01,\n",
" -2.3402e-01, -2.7536e-01, 9.4687e-01, 1.5282e-01, 3.0224e-01,\n",
" 1.1186e-02, -7.3235e-01, -1.0000e+00, -6.9951e-01, -5.0531e-01,\n",
" -2.7527e-01, -2.0676e-01, -9.5607e-01, -9.1109e-01, 5.1232e-01,\n",
" 9.3519e-01, 1.3547e-01, 9.9877e-01, -2.0620e-01, 9.2237e-01,\n",
" -4.9195e-01, -7.0814e-01, 6.5991e-01, -4.0702e-01, 7.4080e-01,\n",
" 4.4237e-01, -6.9697e-01, 1.7959e-01, -2.0311e-01, 2.8031e-01,\n",
" -6.5004e-01, -2.2036e-01, -6.8982e-01, -9.2266e-01, -3.2942e-01,\n",
" 9.3754e-01, -4.7618e-01, -8.9325e-01, -1.4759e-01, -1.4892e-01,\n",
" -5.3520e-01, 8.4738e-01, 7.0655e-01, 3.8488e-01, -4.0430e-01,\n",
" 3.9195e-01, 2.2351e-01, 5.5196e-01, -8.1159e-01, -1.8874e-01,\n",
" 3.3696e-01, -3.6883e-01, -6.5580e-01, -9.7058e-01, -3.4790e-01,\n",
" 4.8675e-01, 9.8414e-01, 7.1667e-01, 2.3032e-01, 7.0561e-01,\n",
" -8.2327e-02, 7.3910e-01, -9.2162e-01, 9.5893e-01, -3.3638e-01,\n",
" 2.3401e-01, 6.1110e-02, 4.1919e-01, -8.5576e-01, 1.5276e-01,\n",
" 8.8090e-01, -6.3311e-01, -8.3712e-01, 6.5171e-02, -4.3054e-01,\n",
" -3.4557e-01, -5.9076e-01, 5.1503e-01, -2.6207e-01, -2.4693e-01,\n",
" 6.1307e-02, 8.7691e-01, 9.8752e-01, 8.0232e-01, 1.4752e-01,\n",
" 6.8812e-01, -8.9320e-01, -5.4703e-01, 4.8356e-02, 2.1540e-01,\n",
" 2.3904e-01, 9.9014e-01, -4.9880e-01, -1.3789e-01, -9.2269e-01,\n",
" -9.7721e-01, -9.4687e-02, -9.0299e-01, -1.3468e-01, -7.0078e-01,\n",
" 5.1664e-01, 2.4403e-01, 6.1268e-01, 3.6200e-01, -9.9236e-01,\n",
" -7.4132e-01, 3.4922e-01, -2.3057e-01, 3.8191e-01, -1.6780e-01,\n",
" 3.9557e-02, 8.9809e-01, -5.3350e-01, 8.3722e-01, 8.8839e-01,\n",
" -7.2514e-01, -7.3965e-01, 8.9407e-01, -2.3408e-01, 8.7030e-01,\n",
" -5.6373e-01, 9.7425e-01, 8.4706e-01, 8.3271e-01, -8.9631e-01,\n",
" -5.6269e-01, -9.0159e-01, -6.9973e-01, 6.1689e-02, 9.8560e-02,\n",
" 8.7749e-01, 5.6404e-01, 3.4049e-01, 3.7582e-01, -6.7834e-01,\n",
" 9.9827e-01, -3.3602e-02, -9.2002e-01, 2.7571e-01, -3.0865e-01,\n",
" -9.6896e-01, 7.2166e-01, 3.3953e-01, -4.0726e-03, -4.1497e-01,\n",
" -6.4642e-01, -9.2770e-01, 9.3160e-01, 6.0920e-02, 9.9071e-01,\n",
" 4.6195e-02, -9.3994e-01, -6.6822e-01, -8.9785e-01, -3.0716e-01,\n",
" -2.0500e-01, -3.8714e-01, -8.1208e-02, -9.4563e-01, 4.3475e-01,\n",
" 4.1566e-01, 4.9148e-01, -6.9445e-01, 9.9830e-01, 1.0000e+00,\n",
" 9.3747e-01, 8.9366e-01, 9.2651e-01, -9.9799e-01, -2.9389e-01,\n",
" 9.9995e-01, -9.7730e-01, -1.0000e+00, -9.1234e-01, -6.9568e-01,\n",
" 3.7277e-01, -1.0000e+00, -2.0609e-01, 1.7125e-01, -8.7448e-01,\n",
" 5.9412e-01, 9.6720e-01, 9.9095e-01, -1.0000e+00, 6.5990e-01,\n",
" 9.2647e-01, -6.0201e-01, 9.5347e-01, -3.2178e-01, 9.5794e-01,\n",
" 6.5932e-01, 1.1768e-01, -2.4565e-01, 3.2490e-01, -8.8230e-01,\n",
" -8.7855e-01, -4.5894e-01, -6.2306e-01, 9.8882e-01, 1.1127e-01,\n",
" -8.1504e-01, -8.9768e-01, -2.5663e-02, -2.0069e-01, -3.3576e-01,\n",
" -9.4615e-01, -1.0597e-01, 5.6197e-01, 7.7034e-01, 9.0875e-02,\n",
" 3.0440e-01, -6.8938e-01, 2.5243e-01, -1.7008e-01, 3.3678e-01,\n",
" 6.2607e-01, -9.2541e-01, -6.4668e-01, -4.1812e-01, -1.5776e-01,\n",
" -5.8090e-01, -9.3592e-01, 9.5067e-01, -4.7707e-01, 7.9794e-01,\n",
" 1.0000e+00, 1.2838e-01, -8.6789e-01, 6.2421e-01, 2.0468e-01,\n",
" 4.3405e-03, 1.0000e+00, 7.7308e-01, -9.5914e-01, -4.9383e-01,\n",
" 5.1447e-01, -5.0643e-01, -4.6023e-01, 9.9656e-01, -2.7889e-01,\n",
" -6.0374e-01, -3.1379e-01, 9.4870e-01, -9.7579e-01, 9.8235e-01,\n",
" -8.9237e-01, -9.4238e-01, 9.3981e-01, 9.0497e-01, -6.8348e-01,\n",
" -4.2984e-01, 1.2406e-01, -6.3880e-01, 3.0334e-01, -9.6749e-01,\n",
" 7.3108e-01, 5.1503e-01, 4.4069e-02, 8.4879e-01, -9.0855e-01,\n",
" -4.6638e-01, 2.9909e-01, -7.3568e-01, -2.1431e-01, 7.7439e-01,\n",
" 5.1014e-01, -3.0549e-01, 9.3042e-02, -3.4041e-01, 2.4432e-01,\n",
" -9.6357e-01, 3.4927e-01, 1.0000e+00, -2.4683e-01, 4.8418e-01,\n",
" -5.1474e-01, 5.1816e-02, -1.7388e-01, 4.7761e-01, 5.5868e-01,\n",
" -2.4163e-01, -8.0916e-01, 7.3723e-01, -9.7524e-01, -9.7020e-01,\n",
" 8.5261e-01, 1.8727e-01, -2.7090e-01, 9.9998e-01, 4.6983e-01,\n",
" 9.6978e-02, 3.6852e-01, 9.7414e-01, -8.3766e-04, 6.4376e-01,\n",
" 8.7053e-01, 9.6059e-01, -1.8756e-01, 5.1957e-01, 8.7386e-01,\n",
" -8.3668e-01, -2.7663e-01, -5.9559e-01, -1.2339e-02, -8.8570e-01,\n",
" 8.2444e-02, -9.3376e-01, 9.5201e-01, 8.6130e-01, 3.3720e-01,\n",
" 2.3967e-01, 5.4095e-01, 1.0000e+00, 1.3089e-01, 7.5866e-01,\n",
" -6.5313e-01, 9.1302e-01, -9.9812e-01, -8.6791e-01, -3.1752e-01,\n",
" -9.1607e-03, -7.3271e-01, -3.1350e-01, 2.6582e-01, -9.5944e-01,\n",
" 7.4126e-01, 4.9215e-01, -9.9320e-01, -9.8625e-01, -2.1465e-01,\n",
" 9.0425e-01, -4.9062e-02, -9.3739e-01, -7.3878e-01, -5.6868e-01,\n",
" 5.5593e-01, -2.0358e-01, -9.3490e-01, -1.9005e-01, -2.3025e-01,\n",
" 4.5899e-01, -7.0443e-02, 5.4063e-01, 7.6846e-01, 5.9393e-01,\n",
" -1.9536e-01, -1.4414e-01, -2.6515e-02, -8.3050e-01, 8.8996e-01,\n",
" -8.3560e-01, -8.2514e-01, -1.7632e-01, 1.0000e+00, -5.3209e-01,\n",
" 7.4747e-01, 7.9880e-01, 8.0815e-01, -1.0571e-01, 9.6487e-02,\n",
" 8.7753e-01, 2.1673e-01, -7.5100e-01, -8.1242e-01, -9.0104e-01,\n",
" -3.2831e-01, 6.3693e-01, 8.2358e-03, 5.5376e-01, 7.1281e-01,\n",
" 6.4975e-01, 1.4424e-01, 3.0208e-02, -1.5367e-01, 9.9958e-01,\n",
" -2.4823e-01, -4.5267e-02, -4.9861e-01, 8.4450e-03, -3.3764e-01,\n",
" -7.4455e-01, 1.0000e+00, 2.2909e-01, 3.0400e-01, -9.8225e-01,\n",
" -7.7581e-01, -9.3825e-01, 9.9999e-01, 8.0493e-01, -6.9461e-01,\n",
" 6.7583e-01, 7.1560e-01, -7.5956e-02, 8.8280e-01, -8.8796e-02,\n",
" -3.6776e-01, 3.0358e-01, 9.0578e-02, 9.3570e-01, -5.4713e-01,\n",
" -9.4064e-01, -5.1854e-01, 3.6407e-01, -9.4586e-01, 9.9884e-01,\n",
" -4.6634e-01, -2.2036e-01, -4.2909e-01, 1.9812e-01, 8.0296e-01,\n",
" -1.1237e-01, -9.7593e-01, 3.2545e-03, 2.2387e-01, 9.4407e-01,\n",
" 2.3152e-01, -5.3741e-01, -9.0152e-01, 7.2972e-01, 6.4679e-01,\n",
" -8.5261e-01, -9.2280e-01, 9.4217e-01, -9.8578e-01, 6.6755e-01,\n",
" 1.0000e+00, 3.4225e-01, -1.6761e-01, 7.7093e-02, -3.9836e-01,\n",
" 2.2625e-01, -2.2041e-01, 7.3612e-01, -9.2743e-01, -3.6491e-01,\n",
" -1.7540e-01, 2.9468e-01, -1.1303e-01, 2.6401e-01, 6.9200e-01,\n",
" 1.5430e-01, -4.0083e-01, -5.2640e-01, 2.4087e-02, 4.3949e-01,\n",
" 8.6077e-01, -2.6866e-01, -1.0388e-01, 7.5587e-03, -1.2241e-01,\n",
" -9.1376e-01, -2.1348e-01, -2.9673e-01, -9.9988e-01, 6.9455e-01,\n",
" -1.0000e+00, 2.8368e-01, 8.6735e-02, -1.2220e-01, 7.9206e-01,\n",
" 1.5490e-02, 4.9311e-01, -7.3105e-01, -8.1444e-01, 5.0827e-01,\n",
" 7.2358e-01, -2.9349e-01, -5.1790e-01, -6.9773e-01, 2.4637e-01,\n",
" -1.5526e-02, 2.1339e-01, -5.1806e-01, 7.8137e-01, -1.7301e-01,\n",
" 1.0000e+00, 1.9527e-01, -7.5410e-01, -9.8262e-01, 1.5416e-01,\n",
" -2.1457e-01, 1.0000e+00, -9.3285e-01, -9.1573e-01, 2.9430e-01,\n",
" -6.9617e-01, -8.3260e-01, 2.6820e-01, -3.4682e-02, -7.8862e-01,\n",
" -8.5820e-01, 9.5101e-01, 9.4690e-01, -5.5200e-01, 4.5879e-01,\n",
" -3.4441e-01, -5.6058e-01, -4.5147e-02, 7.0248e-01, 9.7133e-01,\n",
" 2.6254e-01, 8.9137e-01, 4.2302e-01, -7.3707e-02, 9.4970e-01,\n",
" 1.6445e-01, 6.1381e-01, 1.0270e-01, 1.0000e+00, 2.7983e-01,\n",
" -8.8676e-01, 1.4404e-01, -9.7244e-01, -1.6864e-01, -9.5221e-01,\n",
" 2.6231e-01, 2.7997e-01, 8.9316e-01, -2.3383e-01, 9.4295e-01,\n",
" -5.3833e-01, 4.3593e-02, -7.9243e-01, -3.1933e-01, 3.5616e-01,\n",
" -9.0270e-01, -9.7206e-01, -9.7301e-01, 6.8435e-01, -4.2106e-01,\n",
" 4.4723e-02, 1.2440e-01, 7.1743e-03, 3.5916e-01, 4.4393e-01,\n",
" -1.0000e+00, 9.2962e-01, 3.8557e-01, 8.5492e-01, 9.2992e-01,\n",
" 7.0625e-01, 4.8370e-01, 2.3270e-01, -9.7541e-01, -9.8218e-01,\n",
" -3.2932e-01, -2.1163e-01, 7.5084e-01, 6.3202e-01, 8.8856e-01,\n",
" 4.3251e-01, -5.0404e-01, -6.7029e-02, -2.9505e-01, -3.2807e-01,\n",
" -9.8568e-01, 4.3446e-01, -5.8658e-01, -9.7724e-01, 9.3651e-01,\n",
" -1.3708e-01, -1.3665e-01, -9.2905e-02, -6.6635e-01, 9.7278e-01,\n",
" 7.0707e-01, 4.3204e-01, 8.7915e-02, 4.7217e-01, 8.3990e-01,\n",
" 9.4993e-01, 9.7219e-01, -6.7202e-01, 8.3279e-01, -5.4167e-01,\n",
" 4.1125e-01, 3.4719e-01, -9.0791e-01, 9.1832e-02, 2.0506e-01,\n",
" -2.8610e-01, 1.5352e-01, -1.1304e-01, -9.8395e-01, 1.8631e-01,\n",
" -2.0863e-01, 6.1166e-01, -2.9382e-01, 5.8579e-02, -3.7076e-01,\n",
" -3.7402e-02, -6.2659e-01, -7.5935e-01, 5.6508e-01, 5.0258e-01,\n",
" 8.7703e-01, 8.0735e-01, -6.9027e-02, -6.4556e-01, -2.2308e-01,\n",
" -7.0203e-01, -8.9239e-01, 9.4453e-01, -2.7452e-02, -3.4130e-01,\n",
" 5.0977e-01, -1.5005e-01, 5.0155e-01, 9.2492e-02, -3.1371e-01,\n",
" -3.9861e-01, -6.5197e-01, 8.3609e-01, 4.2015e-02, -5.3505e-01,\n",
" -7.0400e-01, 5.6731e-01, 3.1090e-01, 9.9974e-01, -6.7131e-01,\n",
" -8.3116e-01, -1.6593e-01, -3.9197e-01, 2.8166e-01, -4.2960e-01,\n",
" -1.0000e+00, 3.9846e-01, -3.7210e-01, 6.3236e-01, -6.8413e-01,\n",
" 4.8827e-01, -7.2434e-01, -9.8220e-01, -1.6252e-01, 4.2168e-02,\n",
" 6.8659e-01, -4.7085e-01, -7.6191e-01, 4.8094e-01, -1.6689e-01,\n",
" 9.5317e-01, 8.1554e-01, -3.6865e-01, 1.1301e-01, 6.0376e-01,\n",
" -6.5595e-01, -6.1998e-01, 9.0952e-01]], grad_fn=<TanhBackward0>), hidden_states=None, past_key_values=None, attentions=None, cross_attentions=None)\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Transform input tokens \n",
"inputs = tokenizer_local(\"Hello world!\", return_tensors=\"pt\")\n",
"\n",
"# Model apply\n",
"outputs = model_local(**inputs)\n",
"print(outputs)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Bq6BDHDdhxhp",
"outputId": "90f7d2d0-e363-41d2-e945-9bd4c16ee33d"
},
"execution_count": 20,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"BaseModelOutputWithPoolingAndCrossAttentions(last_hidden_state=tensor([[[-0.1424, 0.1335, -0.1291, ..., -0.3597, -0.0562, 0.3605],\n",
" [-0.3506, 0.1042, 0.6244, ..., -0.1761, 0.4834, 0.0644],\n",
" [-0.2451, -0.1573, 0.6945, ..., -0.5654, -0.0894, -0.1856],\n",
" [-0.8248, -0.9119, -0.6561, ..., 0.5074, -0.1939, -0.1659],\n",
" [ 0.8767, 0.0352, -0.1233, ..., 0.2720, -0.6369, -0.1585]]],\n",
" grad_fn=<NativeLayerNormBackward0>), pooler_output=tensor([[-8.9756e-01, -3.3040e-01, -7.6942e-01, 7.5799e-01, 4.6678e-01,\n",
" -1.2035e-01, 9.1835e-01, 1.8087e-01, -7.2716e-01, -9.9991e-01,\n",
" -4.4723e-01, 8.9104e-01, 9.6621e-01, 5.4915e-01, 9.4344e-01,\n",
" -7.6605e-01, -6.0469e-01, -6.1654e-01, 4.0572e-01, -7.4644e-01,\n",
" 6.1739e-01, 9.9974e-01, 3.2990e-02, 2.5414e-01, 4.3106e-01,\n",
" 9.7732e-01, -8.4328e-01, 9.2297e-01, 9.4871e-01, 6.3994e-01,\n",
" -7.3620e-01, 9.0956e-02, -9.7607e-01, -1.9114e-01, -8.1717e-01,\n",
" -9.7907e-01, 3.1635e-01, -7.2013e-01, 1.6124e-01, 5.1998e-02,\n",
" -8.9102e-01, 2.3002e-01, 9.9967e-01, 1.1504e-02, 1.1176e-01,\n",
" -3.5556e-01, -1.0000e+00, 2.8487e-01, -8.3339e-01, 8.0987e-01,\n",
" 7.4664e-01, 6.2762e-01, 1.9847e-01, 4.5185e-01, 4.7242e-01,\n",
" -3.9167e-03, -1.0570e-01, 9.3340e-02, -1.8906e-01, -5.1946e-01,\n",
" -5.7823e-01, 2.8046e-01, -8.2281e-01, -8.9764e-01, 9.1890e-01,\n",
" 7.4117e-01, -5.9993e-02, -3.1655e-01, 2.8227e-03, -1.4652e-01,\n",
" 9.0953e-01, 2.5587e-01, 5.4493e-02, -8.4187e-01, 5.7772e-01,\n",
" 2.4804e-01, -6.1732e-01, 1.0000e+00, -6.4891e-01, -9.5425e-01,\n",
" 5.5482e-01, 6.8866e-01, 5.5711e-01, -3.3463e-01, 4.7904e-01,\n",
" -1.0000e+00, 3.4198e-01, -1.1332e-01, -9.7818e-01, 2.2887e-01,\n",
" 4.5161e-01, -1.5720e-01, 1.6196e-01, 5.1240e-01, -5.7139e-01,\n",
" -3.7296e-01, -2.8502e-01, -8.0263e-01, -2.1937e-01, -2.2406e-01,\n",
" -5.1871e-03, -2.6417e-01, -2.2839e-01, -3.7414e-01, 2.6933e-01,\n",
" -4.5077e-01, -5.5173e-01, 4.8430e-01, 4.7179e-02, 6.6727e-01,\n",
" 3.3201e-01, -2.9447e-01, 5.0653e-01, -9.4933e-01, 6.1857e-01,\n",
" -2.4586e-01, -9.7565e-01, -5.3396e-01, -9.7924e-01, 5.8934e-01,\n",
" -2.3402e-01, -2.7536e-01, 9.4687e-01, 1.5282e-01, 3.0224e-01,\n",
" 1.1186e-02, -7.3235e-01, -1.0000e+00, -6.9951e-01, -5.0531e-01,\n",
" -2.7527e-01, -2.0676e-01, -9.5607e-01, -9.1109e-01, 5.1232e-01,\n",
" 9.3519e-01, 1.3547e-01, 9.9877e-01, -2.0620e-01, 9.2237e-01,\n",
" -4.9195e-01, -7.0814e-01, 6.5991e-01, -4.0702e-01, 7.4080e-01,\n",
" 4.4237e-01, -6.9697e-01, 1.7959e-01, -2.0311e-01, 2.8031e-01,\n",
" -6.5004e-01, -2.2036e-01, -6.8982e-01, -9.2266e-01, -3.2942e-01,\n",
" 9.3754e-01, -4.7618e-01, -8.9325e-01, -1.4759e-01, -1.4892e-01,\n",
" -5.3520e-01, 8.4738e-01, 7.0655e-01, 3.8488e-01, -4.0430e-01,\n",
" 3.9195e-01, 2.2351e-01, 5.5196e-01, -8.1159e-01, -1.8874e-01,\n",
" 3.3696e-01, -3.6883e-01, -6.5580e-01, -9.7058e-01, -3.4790e-01,\n",
" 4.8675e-01, 9.8414e-01, 7.1667e-01, 2.3032e-01, 7.0561e-01,\n",
" -8.2327e-02, 7.3910e-01, -9.2162e-01, 9.5893e-01, -3.3638e-01,\n",
" 2.3401e-01, 6.1110e-02, 4.1919e-01, -8.5576e-01, 1.5276e-01,\n",
" 8.8090e-01, -6.3311e-01, -8.3712e-01, 6.5171e-02, -4.3054e-01,\n",
" -3.4557e-01, -5.9076e-01, 5.1503e-01, -2.6207e-01, -2.4693e-01,\n",
" 6.1307e-02, 8.7691e-01, 9.8752e-01, 8.0232e-01, 1.4752e-01,\n",
" 6.8812e-01, -8.9320e-01, -5.4703e-01, 4.8356e-02, 2.1540e-01,\n",
" 2.3904e-01, 9.9014e-01, -4.9880e-01, -1.3789e-01, -9.2269e-01,\n",
" -9.7721e-01, -9.4687e-02, -9.0299e-01, -1.3468e-01, -7.0078e-01,\n",
" 5.1664e-01, 2.4403e-01, 6.1268e-01, 3.6200e-01, -9.9236e-01,\n",
" -7.4132e-01, 3.4922e-01, -2.3057e-01, 3.8191e-01, -1.6780e-01,\n",
" 3.9557e-02, 8.9809e-01, -5.3350e-01, 8.3722e-01, 8.8839e-01,\n",
" -7.2514e-01, -7.3965e-01, 8.9407e-01, -2.3408e-01, 8.7030e-01,\n",
" -5.6373e-01, 9.7425e-01, 8.4706e-01, 8.3271e-01, -8.9631e-01,\n",
" -5.6269e-01, -9.0159e-01, -6.9973e-01, 6.1689e-02, 9.8560e-02,\n",
" 8.7749e-01, 5.6404e-01, 3.4049e-01, 3.7582e-01, -6.7834e-01,\n",
" 9.9827e-01, -3.3602e-02, -9.2002e-01, 2.7571e-01, -3.0865e-01,\n",
" -9.6896e-01, 7.2166e-01, 3.3953e-01, -4.0726e-03, -4.1497e-01,\n",
" -6.4642e-01, -9.2770e-01, 9.3160e-01, 6.0920e-02, 9.9071e-01,\n",
" 4.6195e-02, -9.3994e-01, -6.6822e-01, -8.9785e-01, -3.0716e-01,\n",
" -2.0500e-01, -3.8714e-01, -8.1208e-02, -9.4563e-01, 4.3475e-01,\n",
" 4.1566e-01, 4.9148e-01, -6.9445e-01, 9.9830e-01, 1.0000e+00,\n",
" 9.3747e-01, 8.9366e-01, 9.2651e-01, -9.9799e-01, -2.9389e-01,\n",
" 9.9995e-01, -9.7730e-01, -1.0000e+00, -9.1234e-01, -6.9568e-01,\n",
" 3.7277e-01, -1.0000e+00, -2.0609e-01, 1.7125e-01, -8.7448e-01,\n",
" 5.9412e-01, 9.6720e-01, 9.9095e-01, -1.0000e+00, 6.5990e-01,\n",
" 9.2647e-01, -6.0201e-01, 9.5347e-01, -3.2178e-01, 9.5794e-01,\n",
" 6.5932e-01, 1.1768e-01, -2.4565e-01, 3.2490e-01, -8.8230e-01,\n",
" -8.7855e-01, -4.5894e-01, -6.2306e-01, 9.8882e-01, 1.1127e-01,\n",
" -8.1504e-01, -8.9768e-01, -2.5663e-02, -2.0069e-01, -3.3576e-01,\n",
" -9.4615e-01, -1.0597e-01, 5.6197e-01, 7.7034e-01, 9.0875e-02,\n",
" 3.0440e-01, -6.8938e-01, 2.5243e-01, -1.7008e-01, 3.3678e-01,\n",
" 6.2607e-01, -9.2541e-01, -6.4668e-01, -4.1812e-01, -1.5776e-01,\n",
" -5.8090e-01, -9.3592e-01, 9.5067e-01, -4.7707e-01, 7.9794e-01,\n",
" 1.0000e+00, 1.2838e-01, -8.6789e-01, 6.2421e-01, 2.0468e-01,\n",
" 4.3405e-03, 1.0000e+00, 7.7308e-01, -9.5914e-01, -4.9383e-01,\n",
" 5.1447e-01, -5.0643e-01, -4.6023e-01, 9.9656e-01, -2.7889e-01,\n",
" -6.0374e-01, -3.1379e-01, 9.4870e-01, -9.7579e-01, 9.8235e-01,\n",
" -8.9237e-01, -9.4238e-01, 9.3981e-01, 9.0497e-01, -6.8348e-01,\n",
" -4.2984e-01, 1.2406e-01, -6.3880e-01, 3.0334e-01, -9.6749e-01,\n",
" 7.3108e-01, 5.1503e-01, 4.4069e-02, 8.4879e-01, -9.0855e-01,\n",
" -4.6638e-01, 2.9909e-01, -7.3568e-01, -2.1431e-01, 7.7439e-01,\n",
" 5.1014e-01, -3.0549e-01, 9.3042e-02, -3.4041e-01, 2.4432e-01,\n",
" -9.6357e-01, 3.4927e-01, 1.0000e+00, -2.4683e-01, 4.8418e-01,\n",
" -5.1474e-01, 5.1816e-02, -1.7388e-01, 4.7761e-01, 5.5868e-01,\n",
" -2.4163e-01, -8.0916e-01, 7.3723e-01, -9.7524e-01, -9.7020e-01,\n",
" 8.5261e-01, 1.8727e-01, -2.7090e-01, 9.9998e-01, 4.6983e-01,\n",
" 9.6978e-02, 3.6852e-01, 9.7414e-01, -8.3766e-04, 6.4376e-01,\n",
" 8.7053e-01, 9.6059e-01, -1.8756e-01, 5.1957e-01, 8.7386e-01,\n",
" -8.3668e-01, -2.7663e-01, -5.9559e-01, -1.2339e-02, -8.8570e-01,\n",
" 8.2444e-02, -9.3376e-01, 9.5201e-01, 8.6130e-01, 3.3720e-01,\n",
" 2.3967e-01, 5.4095e-01, 1.0000e+00, 1.3089e-01, 7.5866e-01,\n",
" -6.5313e-01, 9.1302e-01, -9.9812e-01, -8.6791e-01, -3.1752e-01,\n",
" -9.1607e-03, -7.3271e-01, -3.1350e-01, 2.6582e-01, -9.5944e-01,\n",
" 7.4126e-01, 4.9215e-01, -9.9320e-01, -9.8625e-01, -2.1465e-01,\n",
" 9.0425e-01, -4.9062e-02, -9.3739e-01, -7.3878e-01, -5.6868e-01,\n",
" 5.5593e-01, -2.0358e-01, -9.3490e-01, -1.9005e-01, -2.3025e-01,\n",
" 4.5899e-01, -7.0443e-02, 5.4063e-01, 7.6846e-01, 5.9393e-01,\n",
" -1.9536e-01, -1.4414e-01, -2.6515e-02, -8.3050e-01, 8.8996e-01,\n",
" -8.3560e-01, -8.2514e-01, -1.7632e-01, 1.0000e+00, -5.3209e-01,\n",
" 7.4747e-01, 7.9880e-01, 8.0815e-01, -1.0571e-01, 9.6487e-02,\n",
" 8.7753e-01, 2.1673e-01, -7.5100e-01, -8.1242e-01, -9.0104e-01,\n",
" -3.2831e-01, 6.3693e-01, 8.2358e-03, 5.5376e-01, 7.1281e-01,\n",
" 6.4975e-01, 1.4424e-01, 3.0208e-02, -1.5367e-01, 9.9958e-01,\n",
" -2.4823e-01, -4.5267e-02, -4.9861e-01, 8.4450e-03, -3.3764e-01,\n",
" -7.4455e-01, 1.0000e+00, 2.2909e-01, 3.0400e-01, -9.8225e-01,\n",
" -7.7581e-01, -9.3825e-01, 9.9999e-01, 8.0493e-01, -6.9461e-01,\n",
" 6.7583e-01, 7.1560e-01, -7.5956e-02, 8.8280e-01, -8.8796e-02,\n",
" -3.6776e-01, 3.0358e-01, 9.0578e-02, 9.3570e-01, -5.4713e-01,\n",
" -9.4064e-01, -5.1854e-01, 3.6407e-01, -9.4586e-01, 9.9884e-01,\n",
" -4.6634e-01, -2.2036e-01, -4.2909e-01, 1.9812e-01, 8.0296e-01,\n",
" -1.1237e-01, -9.7593e-01, 3.2545e-03, 2.2387e-01, 9.4407e-01,\n",
" 2.3152e-01, -5.3741e-01, -9.0152e-01, 7.2972e-01, 6.4679e-01,\n",
" -8.5261e-01, -9.2280e-01, 9.4217e-01, -9.8578e-01, 6.6755e-01,\n",
" 1.0000e+00, 3.4225e-01, -1.6761e-01, 7.7093e-02, -3.9836e-01,\n",
" 2.2625e-01, -2.2041e-01, 7.3612e-01, -9.2743e-01, -3.6491e-01,\n",
" -1.7540e-01, 2.9468e-01, -1.1303e-01, 2.6401e-01, 6.9200e-01,\n",
" 1.5430e-01, -4.0083e-01, -5.2640e-01, 2.4087e-02, 4.3949e-01,\n",
" 8.6077e-01, -2.6866e-01, -1.0388e-01, 7.5587e-03, -1.2241e-01,\n",
" -9.1376e-01, -2.1348e-01, -2.9673e-01, -9.9988e-01, 6.9455e-01,\n",
" -1.0000e+00, 2.8368e-01, 8.6735e-02, -1.2220e-01, 7.9206e-01,\n",
" 1.5490e-02, 4.9311e-01, -7.3105e-01, -8.1444e-01, 5.0827e-01,\n",
" 7.2358e-01, -2.9349e-01, -5.1790e-01, -6.9773e-01, 2.4637e-01,\n",
" -1.5526e-02, 2.1339e-01, -5.1806e-01, 7.8137e-01, -1.7301e-01,\n",
" 1.0000e+00, 1.9527e-01, -7.5410e-01, -9.8262e-01, 1.5416e-01,\n",
" -2.1457e-01, 1.0000e+00, -9.3285e-01, -9.1573e-01, 2.9430e-01,\n",
" -6.9617e-01, -8.3260e-01, 2.6820e-01, -3.4682e-02, -7.8862e-01,\n",
" -8.5820e-01, 9.5101e-01, 9.4690e-01, -5.5200e-01, 4.5879e-01,\n",
" -3.4441e-01, -5.6058e-01, -4.5147e-02, 7.0248e-01, 9.7133e-01,\n",
" 2.6254e-01, 8.9137e-01, 4.2302e-01, -7.3707e-02, 9.4970e-01,\n",
" 1.6445e-01, 6.1381e-01, 1.0270e-01, 1.0000e+00, 2.7983e-01,\n",
" -8.8676e-01, 1.4404e-01, -9.7244e-01, -1.6864e-01, -9.5221e-01,\n",
" 2.6231e-01, 2.7997e-01, 8.9316e-01, -2.3383e-01, 9.4295e-01,\n",
" -5.3833e-01, 4.3593e-02, -7.9243e-01, -3.1933e-01, 3.5616e-01,\n",
" -9.0270e-01, -9.7206e-01, -9.7301e-01, 6.8435e-01, -4.2106e-01,\n",
" 4.4723e-02, 1.2440e-01, 7.1743e-03, 3.5916e-01, 4.4393e-01,\n",
" -1.0000e+00, 9.2962e-01, 3.8557e-01, 8.5492e-01, 9.2992e-01,\n",
" 7.0625e-01, 4.8370e-01, 2.3270e-01, -9.7541e-01, -9.8218e-01,\n",
" -3.2932e-01, -2.1163e-01, 7.5084e-01, 6.3202e-01, 8.8856e-01,\n",
" 4.3251e-01, -5.0404e-01, -6.7029e-02, -2.9505e-01, -3.2807e-01,\n",
" -9.8568e-01, 4.3446e-01, -5.8658e-01, -9.7724e-01, 9.3651e-01,\n",
" -1.3708e-01, -1.3665e-01, -9.2905e-02, -6.6635e-01, 9.7278e-01,\n",
" 7.0707e-01, 4.3204e-01, 8.7915e-02, 4.7217e-01, 8.3990e-01,\n",
" 9.4993e-01, 9.7219e-01, -6.7202e-01, 8.3279e-01, -5.4167e-01,\n",
" 4.1125e-01, 3.4719e-01, -9.0791e-01, 9.1832e-02, 2.0506e-01,\n",
" -2.8610e-01, 1.5352e-01, -1.1304e-01, -9.8395e-01, 1.8631e-01,\n",
" -2.0863e-01, 6.1166e-01, -2.9382e-01, 5.8579e-02, -3.7076e-01,\n",
" -3.7402e-02, -6.2659e-01, -7.5935e-01, 5.6508e-01, 5.0258e-01,\n",
" 8.7703e-01, 8.0735e-01, -6.9027e-02, -6.4556e-01, -2.2308e-01,\n",
" -7.0203e-01, -8.9239e-01, 9.4453e-01, -2.7452e-02, -3.4130e-01,\n",
" 5.0977e-01, -1.5005e-01, 5.0155e-01, 9.2492e-02, -3.1371e-01,\n",
" -3.9861e-01, -6.5197e-01, 8.3609e-01, 4.2015e-02, -5.3505e-01,\n",
" -7.0400e-01, 5.6731e-01, 3.1090e-01, 9.9974e-01, -6.7131e-01,\n",
" -8.3116e-01, -1.6593e-01, -3.9197e-01, 2.8166e-01, -4.2960e-01,\n",
" -1.0000e+00, 3.9846e-01, -3.7210e-01, 6.3236e-01, -6.8413e-01,\n",
" 4.8827e-01, -7.2434e-01, -9.8220e-01, -1.6252e-01, 4.2168e-02,\n",
" 6.8659e-01, -4.7085e-01, -7.6191e-01, 4.8094e-01, -1.6689e-01,\n",
" 9.5317e-01, 8.1554e-01, -3.6865e-01, 1.1301e-01, 6.0376e-01,\n",
" -6.5595e-01, -6.1998e-01, 9.0952e-01]], grad_fn=<TanhBackward0>), hidden_states=None, past_key_values=None, attentions=None, cross_attentions=None)\n"
]
}
]
},
{
"cell_type": "code",
"source": [
""
],
"metadata": {
"id": "b0Y_3PoFh91P"
},
"execution_count": null,
"outputs": []
}
]
}
@shravankumar147
Copy link
Author

Make public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment