-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_extended_pararel.py
49 lines (34 loc) · 1.46 KB
/
generate_extended_pararel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import argparse
import os
from src.pararel.data import extract_data, process_raw_data
from src.utils.general import set_seed_everywhere
from src.utils.io import save_json
from transformers import AutoModelForCausalLM, AutoTokenizer
from src.utils.logger import freeze_args, get_logger, get_output_dir
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("--pararel_dir", type=str)
parser.add_argument("--model_name_path", type=str)
parser.add_argument("--num_false_objects", default=4, type=int)
parser.add_argument("--seed", default=100, type=int)
return parser.parse_args()
def generate_extended_pararel(args):
logger = get_logger()
logger.info("Loading model...")
model = AutoModelForCausalLM.from_pretrained(args.model_name_path, device_map="auto")
tokenizer = AutoTokenizer.from_pretrained(args.model_name_path)
logger.info("Extracting data from ParaRel...")
raw_data = extract_data(args.pararel_dir)
logger.info("Processing raw data...")
extended_pararel = process_raw_data(raw_data, model, tokenizer, args.num_false_objects)
logger.info("Saving extended pararel...")
output_dir = get_output_dir()
extended_pararel_path = os.path.join(output_dir, "extended_pararel.json")
save_json(extended_pararel, extended_pararel_path)
def main():
args = get_args()
freeze_args(args)
set_seed_everywhere(args.seed)
generate_extended_pararel(args)
if __name__ == "__main__":
main()