(args, tokenizer)
| 32 | |
| 33 | |
| 34 | def make_data(args, tokenizer): |
| 35 | # train_json = [json.loads(line) for line in open(args.train_data_path).readlines()] |
| 36 | # val_json = [json.loads(line) for line in open(args.val_data_path).readlines()] |
| 37 | # test_json = [json.loads(line) for line in open(args.val_data_path).readlines()] |
| 38 | train_json = json.load(open(args.train_data_path)) |
| 39 | test_json = json.load(open(args.val_data_path)) |
| 40 | val_json = json.load(open(args.val_data_path)) |
| 41 | label2id = json.load(open(args.label_path)) |
| 42 | |
| 43 | def process_data(data): |
| 44 | features = [] |
| 45 | for example in data: |
| 46 | feature = tokenizer( |
| 47 | example["text"], |
| 48 | padding="max_length", |
| 49 | max_length=args.max_seq_length, |
| 50 | return_token_type_ids=True, |
| 51 | truncation=True |
| 52 | ) |
| 53 | feature["labels"] = label2id[example["label"]] |
| 54 | features.append(feature) |
| 55 | |
| 56 | return features |
| 57 | |
| 58 | train_features = process_data(train_json) |
| 59 | val_features = process_data(val_json) |
| 60 | test_features = process_data(test_json) |
| 61 | return myDataset(train_features), myDataset(val_features), myDataset(test_features) |
| 62 | |
| 63 | |
| 64 | model_path = "./bert-base-uncased/" #https://huggingface.co/google-bert/bert-base-uncased |
no test coverage detected