ValueError: You need to specify either `text` or `text_target` when using evaluator
Hello, I am loading a fine-tuned model I trained to test on a new dataset. The dataset is straight off Huggingface to simplify the process. However, I get this error ValueError: You need to specify eithertextortext_targetHere is my code:from transformers import AutoTokenizer, AutoModelForSequenceClassificationfrom datasets import load_datasetfrom transformers import pipelineimport evaluateimport re#------------------------------------------------------------------------------##---------------------Loading Fine-tuned Model and Tokenizer -----------------##------------------------------------------------------------------------------##--Load your modelmodel_path = “/content/drive/MyDrive/NLP!!/Sentiment Analysis/Airline_reviews/Model 1 - 80_20 Split”#— Load tokenizer and modelloaded_tokenizer = AutoTokenizer.from_pretrained(model_path)loaded_model = AutoModelForSequenceClassification.from_pretrained(model_path)#------------------------------------------------------------------------------##------------------------Dealing with the new dataset ------------------------##------------------------------------------------------------------------------##— Load the new datasetnew_dataset = load_dataset(“Sp1786/multiclass-sentiment-analysis-dataset”, split=“test”)#onlyload the test datasetnew_dataset#— Pre-process new data in the same way you did as the data you used to train your modeldef preprocess_text(text):if not isinstance(text, str):  # Check if text is not a stringtext = “”  # Convert to empty string if not a string# Remove URLs
text = re.sub(r'http\S+', '', text)

# Remove "@" mentions and usernames
text = re.sub(r'@\w+\s*', '', text)

return text#— Get the text data from the ‘test’ splittexts = new_dataset[‘text’]texts#— Make it a list and Apply your preprocessing funcitonpreprocessed_texts = [preprocess_text(text) for text in texts]preprocessed_texts#------------------------------------------------------------------------------##-----------------------------------Inference --------------------------------##------------------------------------------------------------------------------##— Setting up pipeline for inferencesentiment_pipeline = pipeline(task=“text-classification”,model=loaded_model,tokenizer=loaded_tokenizer,device=0) # will tokenize entries for youA quick testsentiment_pipeline(preprocessed_texts) # the pipeline worksground_truth_labels = new_dataset[‘label’]#------------------------------------------------------------------------------##-----------------------------------Evaluation -------------------------------##------------------------------------------------------------------------------#Initialize the task evaluatortask_evaluator = evaluator(“text-classification”)Define label mapping for your dataseteval_results = task_evaluator.compute(model_or_pipeline=loaded_model,tokenizer=loaded_tokenizer,metric=“accuracy”,data=new_dataset,input_column= ‘text’,label_column= ‘label’,label_mapping={“positive”: 2, “neutral”: 1, “negative”: 0})Thank you in advance! Any help would be great
2024-08-27T01:50:35Z
Just checking if the “text is not None” worked for me honestly.