-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* map_tokens from risky pickle to safe hf * mapping sorted and uploaded correctly * using a list, not a dict * (unimportant) cleaning up some lines * change token_map to return list * added split_slice arg to load_validation_dataset()
- Loading branch information
1 parent
6dd4ac8
commit 6177d73
Showing
4 changed files
with
62 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import os | ||
import pickle | ||
|
||
import pandas as pd | ||
from datasets import Dataset | ||
|
||
from delphi.constants import STATIC_ASSETS_DIR | ||
from delphi.eval.token_map import token_map | ||
from delphi.eval.utils import load_validation_dataset | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="") | ||
|
||
parser.add_argument( | ||
"dataset_name", | ||
type=str, | ||
help="Dataset from huggingface to run token_map on", | ||
) | ||
parser.add_argument( | ||
"--username", | ||
type=str, | ||
help="Hugging Face API username", | ||
) | ||
parser.add_argument( | ||
"dataset_name", help="Dataset from huggingface to run token_map on" | ||
"--token", | ||
type=str, | ||
help="Hugging Face API token", | ||
) | ||
parser.add_argument( | ||
"--tokenizer-size", | ||
type=int, | ||
default=4096, | ||
help="Size of the tokenizer", | ||
) | ||
parser.add_argument("--output", help="Output file name", default="token_map.pkl") | ||
args = parser.parse_args() | ||
|
||
dataset = load_validation_dataset(args.dataset_name) | ||
|
||
mapping = token_map(dataset) | ||
hf_dataset = Dataset.from_dict( | ||
{"prompt_pos_idx": token_map(dataset, args.tokenizer_size)} | ||
) | ||
|
||
with open(f"{STATIC_ASSETS_DIR}/{args.output}", "wb") as f: | ||
pickle.dump(mapping, file=f) | ||
repo_id = f"{args.username}/v0-token-map" # location in to hf | ||
|
||
hf_dataset.push_to_hub( | ||
repo_id=repo_id, | ||
split="validation", | ||
private=False, | ||
token=args.token, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters