Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit e964051

Browse files
authored
Modify get_local_asset_path to take overwrite option and use it in BERTTokenizer (#1839)
1 parent 5ce9c42 commit e964051

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

torchtext/transforms.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ def __init__(
572572
self, vocab_path: str, do_lower_case: bool = True, strip_accents: Optional[bool] = None, return_tokens=False
573573
) -> None:
574574
super().__init__()
575-
self.bert_model = BERTEncoderPyBind(get_asset_local_path(vocab_path), do_lower_case, strip_accents)
575+
self.bert_model = BERTEncoderPyBind(
576+
get_asset_local_path(vocab_path, overwite=True), do_lower_case, strip_accents
577+
)
576578
self._return_tokens = return_tokens
577579
self._vocab_path = vocab_path
578580
self._do_lower_case = do_lower_case

torchtext/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,11 @@ def _log_class_usage(klass):
209209
torch._C._log_api_usage_once(identifier)
210210

211211

212-
def get_asset_local_path(asset_path: str) -> str:
212+
def get_asset_local_path(asset_path: str, overwite=False) -> str:
213213
"""Get local path for assets. Download if path does not exost locally
214214
Args:
215215
asset_path: Local path to asset or remote URL
216+
overwrite: Indicate whether to overwrite the file when downloading from URL (default: False)
216217
Returns:
217218
bool: local path of the asset after downloading or reading from cache
218219
Examples:
@@ -225,5 +226,5 @@ def get_asset_local_path(asset_path: str) -> str:
225226
if os.path.exists(asset_path):
226227
local_path = asset_path
227228
else:
228-
local_path = download_from_url(url=asset_path, root=_CACHE_DIR)
229+
local_path = download_from_url(url=asset_path, root=_CACHE_DIR, overwrite=overwite)
229230
return local_path

0 commit comments

Comments
 (0)