Skip to content

Commit

Permalink
added static file folder
Browse files Browse the repository at this point in the history
  • Loading branch information
menamerai committed Feb 19, 2024
1 parent bd4a88b commit a3d7adc
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions scripts/label_all_tokens.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
import pickle
from pathlib import Path
from importlib.resources import files

from tqdm.auto import tqdm
from transformers import AutoTokenizer, PreTrainedTokenizer, PreTrainedTokenizerFast
Expand Down Expand Up @@ -36,7 +36,7 @@ def main():

# Access command-line arguments
# Directory to save the results
SAVE_DIR = Path("src/delphi/eval/")
SAVE_DIR = files("delphi").joinpath("static")
model_name = args.model_name

print("\n", " LABEL ALL TOKENS ".center(50, "="), "\n")
Expand All @@ -60,8 +60,8 @@ def main():

# Save the list of all tokens to a file
filename = "all_tokens_list.txt"
filepath = SAVE_DIR / filename
with open(filepath, "w", encoding="utf-8") as f:
filepath = SAVE_DIR.joinpath(filename)
with open(f"{filepath}", "w", encoding="utf-8") as f:
f.write(tokens_str)

print(f"Saved the list of all tokens to:\n\t{filepath}\n")
Expand Down Expand Up @@ -89,15 +89,15 @@ def main():
# Save the labelled tokens to a file
filename = "labelled_token_ids_dict.pkl"
filepath = SAVE_DIR / filename
with open(filepath, "wb") as f:
with open(f"{filepath}", "wb") as f:
pickle.dump(labelled_token_ids_dict, f)

print(f"Saved the labelled tokens to:\n\t{filepath}\n")

# sanity check that The pickled and the original dict are the same
print("Sanity check ...", end="")
# load pickle
with open(filepath, "rb") as f:
with open(f"{filepath}", "rb") as f:
pickled = pickle.load(f)
# compare
assert labelled_token_ids_dict == pickled
Expand Down
3 changes: 2 additions & 1 deletion scripts/map_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import argparse
import pickle
from importlib.resources import files

from delphi.eval.token_map import token_map
from delphi.eval.utils import load_validation_dataset
Expand All @@ -18,5 +19,5 @@

mapping = token_map(dataset)

with open(f"data/{args.output}", "wb") as f:
with open(f"{files('delphi').joinpath('static')}/{args.output}", "wb") as f:
pickle.dump(mapping, file=f)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
version="0.1",
packages=find_packages(where="src"),
package_dir={"": "src"},
package_data={"delphi.static": ["*"]},
)
Binary file removed src/delphi/eval/labelled_token_ids_dict.pkl
Binary file not shown.
File renamed without changes.
Binary file added src/delphi/static/labelled_token_ids_dict.pkl
Binary file not shown.
Binary file added src/delphi/static/token_map.pkl
Binary file not shown.

0 comments on commit a3d7adc

Please sign in to comment.