-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval_pretrain.py
More file actions
33 lines (27 loc) · 852 Bytes
/
eval_pretrain.py
File metadata and controls
33 lines (27 loc) · 852 Bytes
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
from transformers import (
Trainer,
TrainingArguments,
AutoTokenizer,
LineByLineTextDataset,
DataCollatorForLanguageModeling,
)
from transformers import BertForMaskedLM
our_tokenizer = AutoTokenizer.from_pretrained("Skratch99/bert-pretrained")
validation_dataset = LineByLineTextDataset(
tokenizer=our_tokenizer, file_path="wikitext_2_raw_v1_test.txt", block_size=128
)
data_collator = DataCollatorForLanguageModeling(
tokenizer=our_tokenizer, mlm=True, mlm_probability=0.15
)
model_id = "Skratch99/bert-pretrained"
model = BertForMaskedLM.from_pretrained(model_id)
trainer = Trainer(
model=model,
args=TrainingArguments(
output_dir="./results",
per_device_eval_batch_size=16,
),
data_collator=data_collator,
)
results = trainer.evaluate(eval_dataset=validation_dataset)
print(results)