ktsn-ud commited on
Commit
bd36d3a
·
1 Parent(s): 5544c96

インポートに関するエラー修正と、vecのダウンロードを追加

Browse files
Files changed (1) hide show
  1. scripts/0_download_data.py +33 -15
scripts/0_download_data.py CHANGED
@@ -1,10 +1,16 @@
1
  import os
 
 
 
2
 
3
  from utils.logger import setup_logger
4
  from utils.json import get_file_path_from_config
5
 
6
  log = setup_logger(__name__)
7
 
 
 
 
8
 
9
  def download_embeddings() -> None:
10
  """Hugging Face Datasets から Embeddings をダウンロードする"""
@@ -17,22 +23,34 @@ def download_embeddings() -> None:
17
  log.info("Downloading embeddings from Hugging Face Datasets...")
18
 
19
  # ダウンロード
20
- path = hf_hub_download(
21
- repo_id=os.getenv("HF_EMBEDDINGS_REPO_ID"),
22
- repo_type="dataset",
23
- filename="cc.ja.300.bin",
24
- local_dir=target_dir,
25
- local_dir_use_symlinks=False,
26
- token=os.getenv("HF_TOKEN"),
27
- )
28
-
29
- log.info(f"Embeddings downloaded: {path}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  return
31
 
32
 
33
  if __name__ == "__main__":
34
- fast_text_bin_path = get_file_path_from_config("embeddings.fasttext_bin")
35
- if os.path.exists(fast_text_bin_path):
36
- log.info("Embeddings already exist. Skipping download.")
37
- else:
38
- download_embeddings()
 
1
  import os
2
+ import sys
3
+
4
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
5
 
6
  from utils.logger import setup_logger
7
  from utils.json import get_file_path_from_config
8
 
9
  log = setup_logger(__name__)
10
 
11
+ fast_text_bin_path = get_file_path_from_config("embeddings.fasttext_bin")
12
+ fast_text_vec_path = get_file_path_from_config("embeddings.fasttext_vec")
13
+
14
 
15
  def download_embeddings() -> None:
16
  """Hugging Face Datasets から Embeddings をダウンロードする"""
 
23
  log.info("Downloading embeddings from Hugging Face Datasets...")
24
 
25
  # ダウンロード
26
+ if os.path.exists(fast_text_bin_path):
27
+ log.info("Embeddings binary already exists. Skipping download.")
28
+ else:
29
+ path = hf_hub_download(
30
+ repo_id=os.getenv("HF_EMBEDDINGS_REPO_ID"),
31
+ repo_type="dataset",
32
+ filename="cc.ja.300.bin",
33
+ local_dir=target_dir,
34
+ local_dir_use_symlinks=False,
35
+ token=os.getenv("HF_TOKEN"),
36
+ )
37
+ log.info(f"Embeddings downloaded: {path}")
38
+
39
+ if os.path.exists(fast_text_vec_path):
40
+ log.info("Embeddings vector already exists. Skipping download.")
41
+ else:
42
+ path = hf_hub_download(
43
+ repo_id=os.getenv("HF_EMBEDDINGS_REPO_ID"),
44
+ repo_type="dataset",
45
+ filename="cc.ja.300.vec",
46
+ local_dir=target_dir,
47
+ local_dir_use_symlinks=False,
48
+ token=os.getenv("HF_TOKEN"),
49
+ )
50
+ log.info(f"Embeddings downloaded: {path}")
51
+
52
  return
53
 
54
 
55
  if __name__ == "__main__":
56
+ download_embeddings()