Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -133,17 +133,15 @@ def label_single_response_with_model(model_id, story, question, criteria, respon
|
|
| 133 |
predicted_class = torch.argmax(logits, dim=1).item()
|
| 134 |
return str(predicted_class)
|
| 135 |
else:
|
|
|
|
| 136 |
model = get_outlines_model(model_id, DEVICE_MAP, QUANTIZATION_BITS)
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
return result.score
|
| 141 |
|
| 142 |
-
|
| 143 |
@spaces.GPU
|
| 144 |
-
def label_multi_responses_with_model(
|
| 145 |
-
model_id, story, question, criteria, response_file
|
| 146 |
-
):
|
| 147 |
df = pd.read_csv(response_file.name)
|
| 148 |
assert "response" in df.columns, "CSV must contain a 'response' column."
|
| 149 |
prompts = [
|
|
@@ -158,10 +156,11 @@ def label_multi_responses_with_model(
|
|
| 158 |
predicted_classes = torch.argmax(logits, dim=1).tolist()
|
| 159 |
scores = [str(cls) for cls in predicted_classes]
|
| 160 |
else:
|
|
|
|
| 161 |
model = get_outlines_model(model_id, DEVICE_MAP, QUANTIZATION_BITS)
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
scores = [r.score for r in results]
|
| 166 |
|
| 167 |
df["score"] = scores
|
|
|
|
| 133 |
predicted_class = torch.argmax(logits, dim=1).item()
|
| 134 |
return str(predicted_class)
|
| 135 |
else:
|
| 136 |
+
# Use structured JSON generation like in the original script
|
| 137 |
model = get_outlines_model(model_id, DEVICE_MAP, QUANTIZATION_BITS)
|
| 138 |
+
sampler = outlines.samplers.greedy() # Match original temperature=0 behavior
|
| 139 |
+
generator = outlines.generate.json(model, ResponseModel, sampler=sampler)
|
| 140 |
+
result = generator(prompt)
|
| 141 |
return result.score
|
| 142 |
|
|
|
|
| 143 |
@spaces.GPU
|
| 144 |
+
def label_multi_responses_with_model(model_id, story, question, criteria, response_file):
|
|
|
|
|
|
|
| 145 |
df = pd.read_csv(response_file.name)
|
| 146 |
assert "response" in df.columns, "CSV must contain a 'response' column."
|
| 147 |
prompts = [
|
|
|
|
| 156 |
predicted_classes = torch.argmax(logits, dim=1).tolist()
|
| 157 |
scores = [str(cls) for cls in predicted_classes]
|
| 158 |
else:
|
| 159 |
+
# Use structured JSON generation for batch processing
|
| 160 |
model = get_outlines_model(model_id, DEVICE_MAP, QUANTIZATION_BITS)
|
| 161 |
+
sampler = outlines.samplers.greedy()
|
| 162 |
+
generator = outlines.generate.json(model, ResponseModel, sampler=sampler)
|
| 163 |
+
results = generator(prompts)
|
| 164 |
scores = [r.score for r in results]
|
| 165 |
|
| 166 |
df["score"] = scores
|