add cache dir
"outputs": [],
"source": [
"import sys\n",
+ "from tempfile import TemporaryDirectory\n",
"\n",
"sys.path.append(\"../../\")\n",
"import json\n",
"text = \"rare bird has more than enough charm to make it memorable.\"\n",
"\n",
"# get the tokenized words.\n",
- "tokenizer = BertTokenizer.from_pretrained(\"bert-base-uncased\")\n",
+ "cache_dir = TemporaryDirectory().name\n",
+ "tokenizer = BertTokenizer.from_pretrained(\"bert-base-uncased\", cache_dir=cache_dir)\n",
"words = [\"[CLS]\"] + tokenizer.tokenize(text) + [\"[SEP]\"]\n",
"\n",
"# load BERT base model\n",
- "model = BertModel.from_pretrained(\"bert-base-uncased\").to(device)\n",
+ "model = BertModel.from_pretrained(\"bert-base-uncased\", cache_dir=cache_dir).to(device)\n",
"for param in model.parameters():\n",
" param.requires_grad = False\n",
"model.eval()\n",
