Commit
•
1a772ee
1
Parent(s):
9797d26
Upload model card
Browse files
README.md
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
metrics:
|
6 |
+
- glue
|
7 |
+
pipeline_tag: text-classification
|
8 |
+
---
|
9 |
+
Evaluate on MNLI:
|
10 |
+
```python
|
11 |
+
from transformers import (
|
12 |
+
default_data_collator,
|
13 |
+
AutoTokenizer,
|
14 |
+
AutoModelForSequenceClassification,
|
15 |
+
Trainer,
|
16 |
+
)
|
17 |
+
from datasets import load_dataset
|
18 |
+
|
19 |
+
import functools
|
20 |
+
|
21 |
+
from utils import compute_metrics, preprocess_function
|
22 |
+
|
23 |
+
model_name = "George-Ogden/gpt2-medium-finetuned-mnli"
|
24 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
25 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
26 |
+
trainer = Trainer(
|
27 |
+
model=model,
|
28 |
+
eval_dataset="mnli",
|
29 |
+
tokenizer=tokenizer,
|
30 |
+
compute_metrics=compute_metrics,
|
31 |
+
data_collator=default_data_collator,
|
32 |
+
)
|
33 |
+
|
34 |
+
raw_datasets = load_dataset(
|
35 |
+
"glue",
|
36 |
+
"mnli",
|
37 |
+
).map(functools.partial(preprocess_function, tokenizer), batched=True)
|
38 |
+
|
39 |
+
tasks = ["mnli", "mnli-mm"]
|
40 |
+
eval_datasets = [
|
41 |
+
raw_datasets["validation_matched"],
|
42 |
+
raw_datasets["validation_mismatched"],
|
43 |
+
]
|
44 |
+
|
45 |
+
for layers in reversed(range(model.num_layers + 1)):
|
46 |
+
for eval_dataset, task in zip(eval_datasets, tasks):
|
47 |
+
metrics = trainer.evaluate(eval_dataset=eval_dataset)
|
48 |
+
metrics["eval_samples"] = len(eval_dataset)
|
49 |
+
|
50 |
+
if task == "mnli-mm":
|
51 |
+
metrics = {k + "_mm": v for k, v in metrics.items()}
|
52 |
+
|
53 |
+
trainer.log_metrics(metrics)
|
54 |
+
```
|