Skip to content

Commit

Permalink
♻️ set default cache directory as .cache
Browse files Browse the repository at this point in the history
  • Loading branch information
bage79 committed Dec 6, 2021
1 parent 05aa627 commit 5b78dac
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
ratings_test.txt
ratings_train.txt
*.egg-info
.cache
2 changes: 1 addition & 1 deletion kobert/mxnet_kobert.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_mxnet_kobert_model(
use_decoder=True,
use_classifier=True,
ctx=mx.cpu(0),
cachedir="~/kobert/",
cachedir=".cache",
):
# download model
model_info = mxnet_kobert
Expand Down
2 changes: 1 addition & 1 deletion kobert/pytorch_kobert.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}


def get_pytorch_kobert_model(ctx="cpu", cachedir="~/kobert/"):
def get_pytorch_kobert_model(ctx="cpu", cachedir=".cache"):
# download model
model_info = pytorch_kobert
model_down = _download(
Expand Down
8 changes: 4 additions & 4 deletions kobert/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}


def download(url, filename, chksum, cachedir="~/kobert/"):
def download(url, filename, chksum, cachedir=".cache"):
f_cachedir = os.path.expanduser(cachedir)
os.makedirs(f_cachedir, exist_ok=True)
file_path = os.path.join(f_cachedir, filename)
Expand All @@ -54,7 +54,7 @@ def download(url, filename, chksum, cachedir="~/kobert/"):
downloaded += len(data)
f.write(data)
done = int(50 * downloaded / total)
sys.stdout.write("\r[{}{}]".format("█" * done, "." * (50 - done)))
sys.stdout.write("\r{}[{}{}]".format(file_path, "█" * done, "." * (50 - done)))
sys.stdout.flush()
sys.stdout.write("\n")
assert (
Expand All @@ -63,15 +63,15 @@ def download(url, filename, chksum, cachedir="~/kobert/"):
return file_path


def get_onnx(cachedir="~/kobert/"):
def get_onnx(cachedir=".cache"):
"""Get KoBERT ONNX file path after downloading"""
model_info = onnx_kobert
return download(
model_info["url"], model_info["fname"], model_info["chksum"], cachedir=cachedir
)


def get_tokenizer(cachedir="~/kobert/"):
def get_tokenizer(cachedir=".cache"):
"""Get KoBERT Tokenizer file path after downloading"""
model_info = tokenizer
return download(
Expand Down
12 changes: 6 additions & 6 deletions scripts/NSMC/naver_review_classifications_gluon_kobert.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
},
"outputs": [],
"source": [
"bert_base, vocab = get_mxnet_kobert_model(use_decoder=False, use_classifier=False, ctx=ctx)"
"bert_base, vocab = get_mxnet_kobert_model(use_decoder=False, use_classifier=False, ctx=ctx, cachedir=\".cache\")"
]
},
{
Expand Down Expand Up @@ -146,8 +146,8 @@
},
"outputs": [],
"source": [
"!wget -O ratings_train.txt https://www.dropbox.com/s/374ftkec978br3d/ratings_train.txt?dl=1\n",
"!wget -O ratings_test.txt https://www.dropbox.com/s/977gbwh542gdy94/ratings_test.txt?dl=1"
"!wget -O .cache/ratings_train.txt https://www.dropbox.com/s/374ftkec978br3d/ratings_train.txt?dl=1\n",
"!wget -O .cache/ratings_test.txt https://www.dropbox.com/s/977gbwh542gdy94/ratings_test.txt?dl=1"
]
},
{
Expand All @@ -160,8 +160,8 @@
},
"outputs": [],
"source": [
"dataset_train = nlp.data.TSVDataset(\"ratings_train.txt\", field_indices=[1,2], num_discard_samples=1)\n",
"dataset_test = nlp.data.TSVDataset(\"ratings_test.txt\", field_indices=[1,2], num_discard_samples=1)"
"dataset_train = nlp.data.TSVDataset(\".cache/ratings_train.txt\", field_indices=[1,2], num_discard_samples=1)\n",
"dataset_test = nlp.data.TSVDataset(\".cache/ratings_test.txt\", field_indices=[1,2], num_discard_samples=1)"
]
},
{
Expand Down Expand Up @@ -469,7 +469,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.7.0"
},
"toc": {
"nav_menu": {},
Expand Down
10 changes: 5 additions & 5 deletions scripts/NSMC/naver_review_classifications_pytorch_kobert.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"metadata": {},
"outputs": [],
"source": [
"bertmodel, vocab = get_pytorch_kobert_model()"
"bertmodel, vocab = get_pytorch_kobert_model(cachedir=\".cache\")"
]
},
{
Expand All @@ -81,8 +81,8 @@
"metadata": {},
"outputs": [],
"source": [
"!wget -O ratings_train.txt https://www.dropbox.com/s/374ftkec978br3d/ratings_train.txt?dl=1\n",
"!wget -O ratings_test.txt https://www.dropbox.com/s/977gbwh542gdy94/ratings_test.txt?dl=1"
"!wget -O .cache/ratings_train.txt https://www.dropbox.com/s/374ftkec978br3d/ratings_train.txt?dl=1\n",
"!wget -O .cache/ratings_test.txt https://www.dropbox.com/s/977gbwh542gdy94/ratings_test.txt?dl=1"
]
},
{
Expand All @@ -91,8 +91,8 @@
"metadata": {},
"outputs": [],
"source": [
"dataset_train = nlp.data.TSVDataset(\"ratings_train.txt\", field_indices=[1,2], num_discard_samples=1)\n",
"dataset_test = nlp.data.TSVDataset(\"ratings_test.txt\", field_indices=[1,2], num_discard_samples=1)"
"dataset_train = nlp.data.TSVDataset(\".cache/ratings_train.txt\", field_indices=[1,2], num_discard_samples=1)\n",
"dataset_test = nlp.data.TSVDataset(\".cache/ratings_test.txt\", field_indices=[1,2], num_discard_samples=1)"
]
},
{
Expand Down

0 comments on commit 5b78dac

Please sign in to comment.