Spaces:
Sleeping
Sleeping
Update tasks/text.py
Browse files- tasks/text.py +7 -21
tasks/text.py
CHANGED
@@ -97,23 +97,8 @@ async def evaluate_text(request: TextEvaluationRequest):
|
|
97 |
# 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.
|
98 |
#--------------------------------------------------------------------------------------------
|
99 |
|
100 |
-
# Make random predictions (placeholder for actual model inference)
|
101 |
true_labels = test_dataset["label"]
|
102 |
-
|
103 |
-
label2id = config.label2id
|
104 |
-
# classifier = pipeline(
|
105 |
-
# "text-classification",
|
106 |
-
# "camillebrl/ModernBERT-envclaims-overfit",
|
107 |
-
# device="cpu"
|
108 |
-
# )
|
109 |
-
# print("len dataset : ", len(test_dataset["quote"]))
|
110 |
-
# predictions = []
|
111 |
-
# for batch in range(0, len(test_dataset["quote"]), 32): # Ajustez la taille des batchs
|
112 |
-
# batch_quotes = test_dataset["quote"][batch:batch + 32]
|
113 |
-
# batch_predictions = classifier(batch_quotes)
|
114 |
-
# predictions.extend([label2id[pred["label"]] for pred in batch_predictions])
|
115 |
-
# print(predictions)
|
116 |
-
# print("final predictions : ", predictions)
|
117 |
# Initialize the model once
|
118 |
classifier = TextClassifier()
|
119 |
|
@@ -126,6 +111,9 @@ async def evaluate_text(request: TextEvaluationRequest):
|
|
126 |
for i in range(num_batches)
|
127 |
]
|
128 |
|
|
|
|
|
|
|
129 |
# Process batches in parallel
|
130 |
max_workers = min(os.cpu_count(), 4) # Limit to 4 workers or CPU count
|
131 |
print(f"Processing with {max_workers} workers")
|
@@ -152,14 +140,12 @@ async def evaluate_text(request: TextEvaluationRequest):
|
|
152 |
batch_results[batch_idx] = []
|
153 |
|
154 |
# Flatten predictions while maintaining order
|
155 |
-
|
156 |
-
print(f"Total predictions collected: {len(
|
157 |
-
|
158 |
|
159 |
#--------------------------------------------------------------------------------------------
|
160 |
# YOUR MODEL INFERENCE STOPS HERE
|
161 |
#--------------------------------------------------------------------------------------------
|
162 |
-
|
163 |
|
164 |
# Stop tracking emissions
|
165 |
emissions_data = tracker.stop_task()
|
@@ -188,4 +174,4 @@ async def evaluate_text(request: TextEvaluationRequest):
|
|
188 |
|
189 |
print("results : ", results)
|
190 |
|
191 |
-
return results
|
|
|
97 |
# 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.
|
98 |
#--------------------------------------------------------------------------------------------
|
99 |
|
|
|
100 |
true_labels = test_dataset["label"]
|
101 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
# Initialize the model once
|
103 |
classifier = TextClassifier()
|
104 |
|
|
|
111 |
for i in range(num_batches)
|
112 |
]
|
113 |
|
114 |
+
# Initialize batch_results before parallel processing
|
115 |
+
batch_results = [[] for _ in range(num_batches)]
|
116 |
+
|
117 |
# Process batches in parallel
|
118 |
max_workers = min(os.cpu_count(), 4) # Limit to 4 workers or CPU count
|
119 |
print(f"Processing with {max_workers} workers")
|
|
|
140 |
batch_results[batch_idx] = []
|
141 |
|
142 |
# Flatten predictions while maintaining order
|
143 |
+
predictions = [pred for batch_preds in batch_results for pred in batch_preds]
|
144 |
+
print(f"Total predictions collected: {len(predictions)}")
|
|
|
145 |
|
146 |
#--------------------------------------------------------------------------------------------
|
147 |
# YOUR MODEL INFERENCE STOPS HERE
|
148 |
#--------------------------------------------------------------------------------------------
|
|
|
149 |
|
150 |
# Stop tracking emissions
|
151 |
emissions_data = tracker.stop_task()
|
|
|
174 |
|
175 |
print("results : ", results)
|
176 |
|
177 |
+
return results
|