Create drift_env.py
Browse files- drift_env.py +17 -0
drift_env.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
def evaluate_instruction_drift(response: str):
|
| 4 |
+
violations = {
|
| 5 |
+
"conciseness_violation": len(response.split()) > 120,
|
| 6 |
+
"speculation_violation": bool(
|
| 7 |
+
re.search(r"\b(might|could|possibly|likely)\b", response.lower())
|
| 8 |
+
),
|
| 9 |
+
"uncertainty_missing": "uncertain" not in response.lower()
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
drift_score = round(
|
| 13 |
+
sum(violations.values()) / len(violations),
|
| 14 |
+
2
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
return violations, drift_score
|