Mismatch in the number of predictions (128000) and references (1000)

#2
by vinnitu - opened

import cramming

model_name = "pbelcak/UltraFastBERT-1x11-long"

from datasets import load_dataset
dataset = load_dataset("yelp_review_full")

from transformers import AutoTokenizer as Tokenizer
tokenizer = Tokenizer.from_pretrained(model_name)

def tokenize_function(examples):
return tokenizer(examples["text"], padding="max_length", truncation=True)

tokenized_datasets = dataset.map(tokenize_function, batched=True)

small_train_dataset = tokenized_datasets["train"].shuffle(seed=42).select(range(1000))
small_eval_dataset = tokenized_datasets["test"].shuffle(seed=42).select(range(1000))

from transformers import AutoModelForMaskedLM as Model

model = Model.from_pretrained(model_name, num_labels=5)
from transformers import TrainingArguments

training_args = TrainingArguments(output_dir="test_trainer")

import numpy as np
import evaluate

metric = evaluate.load("accuracy")

def compute_metrics(eval_pred):
logits, labels = eval_pred
predictions = np.argmax(logits, axis=-1)
return metric.compute(predictions=predictions, references=labels) # here error

from transformers import TrainingArguments, Trainer

training_args = TrainingArguments(output_dir="test_trainer", evaluation_strategy="epoch")

trainer = Trainer(
model=model,
args=training_args,
train_dataset=small_train_dataset,
eval_dataset=small_eval_dataset,
compute_metrics=compute_metrics,
)

trainer.train()

Sign up or log in to comment