From db8c6a0b8a0606516a0cbdb61b633a28f1d3aa29 Mon Sep 17 00:00:00 2001 From: yh Date: Fri, 26 Jul 2019 19:44:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=AF=BB=E5=8F=96bert?= =?UTF-8?q?=E6=9D=83=E9=87=8D=E6=BD=9C=E5=9C=A8=E7=9A=84bug=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastNLP/embeddings/bert_embedding.py | 2 +- fastNLP/modules/utils.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fastNLP/embeddings/bert_embedding.py b/fastNLP/embeddings/bert_embedding.py index 21944570..adc205c2 100644 --- a/fastNLP/embeddings/bert_embedding.py +++ b/fastNLP/embeddings/bert_embedding.py @@ -63,7 +63,7 @@ class BertEmbedding(ContextualEmbedding): model_dir = cached_path(model_url) # 检查是否存在 elif os.path.isdir(os.path.expanduser(os.path.abspath(model_dir_or_name))): - model_dir = model_dir_or_name + model_dir = os.path.expanduser(os.path.abspath(model_dir_or_name)) else: raise ValueError(f"Cannot recognize {model_dir_or_name}.") diff --git a/fastNLP/modules/utils.py b/fastNLP/modules/utils.py index 700e9620..21608c5d 100644 --- a/fastNLP/modules/utils.py +++ b/fastNLP/modules/utils.py @@ -128,9 +128,9 @@ def _get_file_name_base_on_postfix(dir_path, postfix): :param postfix: 形如".bin", ".json"等 :return: str,文件的路径 """ - files = glob.glob(os.path.join(dir_path, '*' + postfix)) + files = list(filter(lambda filename:filename.endswith(postfix), os.listdir(os.path.join(dir_path)))) if len(files) == 0: - raise FileNotFoundError(f"There is no file endswith *.{postfix} file in {dir_path}") + raise FileNotFoundError(f"There is no file endswith *{postfix} file in {dir_path}") elif len(files) > 1: - raise FileExistsError(f"There are multiple *.{postfix} files in {dir_path}") + raise FileExistsError(f"There are multiple *{postfix} files in {dir_path}") return os.path.join(dir_path, files[0]) \ No newline at end of file