sae_token_programs / activation_value_program /prog_L06F08045_value.py
AmiriHayes's picture
Upload folder using huggingface_hub
cfd4eec verified
Raw History Blame Contribute Delete
4.3 kB
"""L6 F8045 -- the George feature -- as a program that returns the ACTIVATION VALUE.
The binary gate is unchanged from the original program (test F1 0.972). What is
new is that the constant 1 is replaced by a predicted magnitude, because the
magnitude turns out to encode WHICH George the sentence means:
"...under President [George] W. Bush..." ~51 the US president
"...Chancellor [George] Osborne..." ~41 a notable public figure
"...and [George] told reporters..." ~35 an unmarked George
"...[King George] III..." ~26 royalty
"...Russell Westbrook, Paul [George]..." ~19 the NBA player
"...the [St George] flag..." ~15 a place name
HOW IT WORKS. Start from a number for the spelling that fired. Then look at the
five tokens before it: each one that appears in a sense list adds or subtracts
points, counted at full strength immediately before the trigger and fading as
you step back. Finally, later mentions of George in the same passage fade.
Every constant was measured on TRAIN only (5,011 firings); the test split is
disjoint by document. Scored by eval_program.py.
"""
FIRE = {' George', 'George', ' Osama', 'ORGE'}
BASE = {' George': 33.6, 'George': 31.1, 'ORGE': 14.3, ' Osama': 4.7}
# How much a context word shifts the activation, by what it says George IS.
# Matching ignores capitals and the leading space.
SENSE_POINTS = {
# this George is a place or a surname, not a first name
-15: ('st', 'paul', 'prince', 'pacers', 'indiana', 'forward'),
# royalty, a label, or a sports/entertainment frame
-2: ('.', ':', 'king', 'police', 'star', 'old', 'george', 'all', 'boy',
'cardinal', 'dr', 'photo', 'city', 'game', 'author', 'thrones',
'year', 'coach', 'her', 'we'),
# neutral: a name is coming but nothing has committed yet
+3: ('the', 'by', 'to', 'was', 'man', '(', 'named', 'son', 'my', 'you',
'over', 'had', 'professor', 'according', 'if', 'caption', 'not',
'news', 'will', 'manager', 'last', 'first'),
# connectives that lean toward a real person being discussed
+4: ('of', 'that', 'for', 'from', 'his', 'general', 'as', 'about',
'attorney', 'writer', 'after', 'this', 'minister', 'or', 'such',
'were', 'he', 'have', 'investor', 'like', 'years'),
# a notable public figure, but not the president
+8: ('billionaire', 'than', 'when', 'chancellor', 'bill', 'washington',
'who', 'house', 'state', 'week', 'host', 'both', 'war', 'office',
'then', 'since', 'abc', 'brother', 'political', 'told',
'conservative', 'more'),
# the US president
+13: ('president', 'former', 'under', 'presidents', 'secretary', 'obama',
'during', 'republican', 'clinton', 'reagan', 'us', 'administration',
'predecessor', 'bush', 'speech', 'trump', 'policy', 'election',
'campaign'),
}
POINTS = {w: p for p, words in SENSE_POINTS.items() for w in words}
# how much each of the five preceding slots counts, nearest first
DECAY = (1.0, 0.70, 0.50, 0.35, 0.25)
REPEAT_DROP = 3.4 # per earlier George in the same passage
REPEAT_CAP = 3
def prog_L06F08045(input_tokens):
"""Return (sense, predicted activation). 0.0 means the feature does not fire."""
token = input_tokens[-1]
if token not in FIRE:
return 'no match', 0.0
if token in (' Osama', 'ORGE'):
return token.strip().lower(), BASE[token]
value = BASE[token]
# --- what do the five tokens before say this George is? ---------------
best, score = 0, 0.0
for slot, tok in enumerate(reversed(input_tokens[-6:-1])):
p = POINTS.get(tok.strip().lower())
if p:
score += p * DECAY[slot]
if abs(p) > abs(best):
best = p
value += score
# --- later mentions in the same passage fade --------------------------
seen = sum(1 for t in input_tokens[:-1] if t in (' George', 'George'))
value -= REPEAT_DROP * min(seen, REPEAT_CAP)
sense = ({-15: 'place/surname', -2: 'royal/label', 3: 'block start',
0: 'george', 4: 'george (referential)', 8: 'notable figure',
13: 'us president'}[best])
return sense, max(0.1, min(60.0, value))