Create truthfield.py
Browse files- truthfield.py +17 -0
truthfield.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# truthfield.py
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
def truth_charge(emb_vec, self_vec, temp=0.35):
|
| 5 |
+
# cosine alignment scaled to 0–100 with mild temperature smoothing
|
| 6 |
+
denom = (np.linalg.norm(emb_vec) * np.linalg.norm(self_vec) + 1e-9)
|
| 7 |
+
cos = float(np.dot(emb_vec, self_vec) / denom)
|
| 8 |
+
z = np.tanh(cos / max(temp, 1e-5))
|
| 9 |
+
return round((z * 50) + 50, 2) # map [-1,1] -> [0,100]
|
| 10 |
+
|
| 11 |
+
def mirror_integrity(out_text, in_text):
|
| 12 |
+
# simple overlap & semantic coherence proxy
|
| 13 |
+
a = set(w.lower() for w in out_text.split())
|
| 14 |
+
b = set(w.lower() for w in in_text.split())
|
| 15 |
+
if not a or not b: return 50.0
|
| 16 |
+
j = len(a & b) / len(a | b)
|
| 17 |
+
return round((0.4 + 0.6 * j) * 100, 2) # bias toward baseline coherence
|