File size: 710 Bytes
e3cfcfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# truthfield.py
import numpy as np

def truth_charge(emb_vec, self_vec, temp=0.35):
    # cosine alignment scaled to 0–100 with mild temperature smoothing
    denom = (np.linalg.norm(emb_vec) * np.linalg.norm(self_vec) + 1e-9)
    cos = float(np.dot(emb_vec, self_vec) / denom)
    z = np.tanh(cos / max(temp, 1e-5))
    return round((z * 50) + 50, 2)  # map [-1,1] -> [0,100]

def mirror_integrity(out_text, in_text):
    # simple overlap & semantic coherence proxy
    a = set(w.lower() for w in out_text.split())
    b = set(w.lower() for w in in_text.split())
    if not a or not b: return 50.0
    j = len(a & b) / len(a | b)
    return round((0.4 + 0.6 * j) * 100, 2)  # bias toward baseline coherence