Spaces:
Sleeping
Sleeping
Update tasks/text.py
Browse files- tasks/text.py +18 -18
tasks/text.py
CHANGED
|
@@ -62,28 +62,28 @@ async def evaluate_text(request: TextEvaluationRequest):
|
|
| 62 |
|
| 63 |
#--------------------------------------------------------------------------------------------
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
#predictions = xgb.predict(embeddings)
|
| 82 |
|
| 83 |
|
| 84 |
# Make random predictions (placeholder for actual model inference)
|
| 85 |
true_labels = test_dataset["label"]
|
| 86 |
-
predictions = xgb.predict(embeddings)
|
| 87 |
|
| 88 |
#--------------------------------------------------------------------------------------------
|
| 89 |
# YOUR MODEL INFERENCE STOPS HERE
|
|
@@ -94,7 +94,7 @@ async def evaluate_text(request: TextEvaluationRequest):
|
|
| 94 |
emissions_data = tracker.stop_task()
|
| 95 |
|
| 96 |
# Calculate accuracy
|
| 97 |
-
accuracy = accuracy_score(true_labels,
|
| 98 |
|
| 99 |
# Prepare results dictionary
|
| 100 |
results = {
|
|
|
|
| 62 |
|
| 63 |
#--------------------------------------------------------------------------------------------
|
| 64 |
|
| 65 |
+
"""""#load
|
| 66 |
+
# Step 1: Use Sentence-BERT to convert text to embeddings
|
| 67 |
+
model = SentenceTransformer("dunzhang/stella_en_400M_v5",trust_remote_code=True,
|
| 68 |
+
device="cpu",
|
| 69 |
+
config_kwargs={"use_memory_efficient_attention": False, "unpad_inputs": False})
|
| 70 |
+
|
| 71 |
+
# Convert each sentence into a vector representation (embedding)
|
| 72 |
+
embeddings = model.encode(test_dataset['quote'])
|
| 73 |
+
# YOUR MODEL INFERENCE CODE HERE
|
| 74 |
+
# 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.
|
| 75 |
+
#--------------------------------------------------------------------------------------------
|
| 76 |
+
|
| 77 |
+
#load model
|
| 78 |
+
with open("stella_400_xgb_500.pkl","rb") as f:
|
| 79 |
+
xgb = pickle.load(f)
|
| 80 |
+
"""""
|
| 81 |
#predictions = xgb.predict(embeddings)
|
| 82 |
|
| 83 |
|
| 84 |
# Make random predictions (placeholder for actual model inference)
|
| 85 |
true_labels = test_dataset["label"]
|
| 86 |
+
#predictions = xgb.predict(embeddings)
|
| 87 |
|
| 88 |
#--------------------------------------------------------------------------------------------
|
| 89 |
# YOUR MODEL INFERENCE STOPS HERE
|
|
|
|
| 94 |
emissions_data = tracker.stop_task()
|
| 95 |
|
| 96 |
# Calculate accuracy
|
| 97 |
+
accuracy = accuracy_score(true_labels, np.array([1]*len(true_labels))
|
| 98 |
|
| 99 |
# Prepare results dictionary
|
| 100 |
results = {
|