Zen0 commited on
Commit
97e876f
·
verified ·
1 Parent(s): 731e8c7

Update tasks/text.py

Browse files
Files changed (1) hide show
  1. tasks/text.py +29 -9
tasks/text.py CHANGED
@@ -53,29 +53,49 @@ async def evaluate_text(request: TextEvaluationRequest):
53
  # YOUR MODEL INFERENCE CODE HERE
54
  # Update the code below to replace the random baseline by your model inference within the inference pass where the energy consumption and emissions are tracked.
55
  #--------------------------------------------------------------------------------------------
 
 
 
 
 
 
56
 
57
- model_name = "Zen0/FrugalDisinfoHunter" # Model identifier from Hugging Face
 
58
  tokenizer = AutoTokenizer.from_pretrained(model_name)
59
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  test_texts = test_dataset["text"] # The field 'text' contains the climate quotes
 
62
  inputs = tokenizer(test_texts, padding=True, truncation=True, return_tensors="pt", max_length=512)
63
-
64
- dataset = load_dataset("quotaclimat/frugalaichallenge-text-train")
65
 
66
- # Access the test dataset
67
- test_dataset = dataset['test']
 
68
 
 
69
  with torch.no_grad(): # Disable gradient calculations
70
  outputs = model(**inputs)
71
  logits = outputs.logits
72
 
73
- # Get predictions from the logits
74
  predictions = torch.argmax(logits, dim=-1).cpu().numpy() # Convert to numpy array for use
75
 
76
- # Get true labels for accuracy calculation
77
- true_labels = test_dataset["label"] # Extract true labels from the dataset
78
-
79
  #--------------------------------------------------------------------------------------------
80
  # YOUR MODEL INFERENCE STOPS HERE
81
  #--------------------------------------------------------------------------------------------
 
53
  # YOUR MODEL INFERENCE CODE HERE
54
  # Update the code below to replace the random baseline by your model inference within the inference pass where the energy consumption and emissions are tracked.
55
  #--------------------------------------------------------------------------------------------
56
+ #--------------------------------------------------------------------------------------------
57
+ # Load your model and tokenizer from Hugging Face or local path
58
+ #--------------------------------------------------------------------------------------------
59
+
60
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
61
+ import torch
62
 
63
+ # Load model from Hugging Face (adjust if you uploaded it there)
64
+ model_name = "Zen0/FrugalDisinfoHunter" # Replace with your model identifier if different
65
  tokenizer = AutoTokenizer.from_pretrained(model_name)
66
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
67
 
68
+ #--------------------------------------------------------------------------------------------
69
+ # Load the dataset
70
+ #--------------------------------------------------------------------------------------------
71
+
72
+ # Assuming 'quotaclimat/frugalaichallenge-text-train' is the dataset you're working with
73
+ dataset = load_dataset(request.dataset_name)
74
+
75
+ # Access the test dataset (you can change this if you want to use a different split)
76
+ test_dataset = dataset['test'] # Assuming you have a 'test' split available
77
+
78
+ #--------------------------------------------------------------------------------------------
79
+ # Tokenize the text data
80
+ #--------------------------------------------------------------------------------------------
81
+
82
+ # Tokenize the test data (the text field contains the quotes)
83
  test_texts = test_dataset["text"] # The field 'text' contains the climate quotes
84
+
85
  inputs = tokenizer(test_texts, padding=True, truncation=True, return_tensors="pt", max_length=512)
 
 
86
 
87
+ #--------------------------------------------------------------------------------------------
88
+ # Inference
89
+ #--------------------------------------------------------------------------------------------
90
 
91
+ # Run inference on the dataset using the model
92
  with torch.no_grad(): # Disable gradient calculations
93
  outputs = model(**inputs)
94
  logits = outputs.logits
95
 
96
+ # Get predictions from the logits (choose the class with the highest logit)
97
  predictions = torch.argmax(logits, dim=-1).cpu().numpy() # Convert to numpy array for use
98
 
 
 
 
99
  #--------------------------------------------------------------------------------------------
100
  # YOUR MODEL INFERENCE STOPS HERE
101
  #--------------------------------------------------------------------------------------------