Migrate metric to Evaluate in Pytorch examples (#18369)

* Migrate metric to Evaluate in pytorch examples

* Remove unused imports
This commit is contained in:
atturaioe
2022-08-01 14:40:25 +03:00
committed by GitHub
parent 25ec12eaf7
commit 1f84399171
25 changed files with 72 additions and 49 deletions

View File

@@ -25,8 +25,9 @@ from typing import Optional
import datasets
import numpy as np
from datasets import load_dataset, load_metric
from datasets import load_dataset
import evaluate
import transformers
from transformers import (
AutoConfig,
@@ -480,9 +481,9 @@ def main():
# Get the metric function
if data_args.task_name is not None:
metric = load_metric("glue", data_args.task_name)
metric = evaluate.load("glue", data_args.task_name)
else:
metric = load_metric("accuracy")
metric = evaluate.load("accuracy")
# You can define your custom compute_metrics function. It takes an `EvalPrediction` object (a namedtuple with a
# predictions and label_ids field) and has to return a dictionary string to float.

View File

@@ -23,10 +23,11 @@ from pathlib import Path
import datasets
import torch
from datasets import load_dataset, load_metric
from datasets import load_dataset
from torch.utils.data import DataLoader
from tqdm.auto import tqdm
import evaluate
import transformers
from accelerate import Accelerator
from accelerate.logging import get_logger
@@ -466,9 +467,9 @@ def main():
# Get the metric function
if args.task_name is not None:
metric = load_metric("glue", args.task_name)
metric = evaluate.load("glue", args.task_name)
else:
metric = load_metric("accuracy")
metric = evaluate.load("accuracy")
# Train!
total_batch_size = args.per_device_train_batch_size * accelerator.num_processes * args.gradient_accumulation_steps

View File

@@ -26,8 +26,9 @@ from typing import Optional
import datasets
import numpy as np
from datasets import load_dataset, load_metric
from datasets import load_dataset
import evaluate
import transformers
from transformers import (
AutoConfig,
@@ -349,7 +350,7 @@ def main():
)
# Get the metric function
metric = load_metric("xnli")
metric = evaluate.load("xnli")
# You can define your custom compute_metrics function. It takes an `EvalPrediction` object (a namedtuple with a
# predictions and label_ids field) and has to return a dictionary string to float.