emotweetid-ekman7 / sweep_config.py
mahalisyarifuddin's picture
EmoTweetID unified under Ekman's 7 universal emotions: human labels kept, anger pool split into anger/contempt by laya
f5a2109 verified
Raw History Blame Contribute Delete
1.42 kB
"""Tune laya's token budget + per-pass token cap: speed vs. label stability on a 48-tweet sample."""
import sys
import numpy as np, pandas as pd, torch
import laya_opt
from ekman_questions import EKMAN_QUESTIONS
agent = laya_opt.load_agent()
tok = agent.tok
f1 = pd.read_csv("data/file1.csv", index_col=0); f2 = pd.read_csv("data/file2.csv", index_col=0)
ang = f1.join(f2)[f1["label"] == "anger"].copy()
rng = np.random.default_rng(0)
texts = ang.iloc[rng.choice(len(ang), 48, replace=False)]["tweet_en"].astype(str).str.replace(r"\s+", " ", regex=True).tolist()
ref = refp = None
for max_len, head, budget in [(1024,256,3072),(384,256,3072),(384,160,3072),(256,160,3072),(256,128,3072),(192,128,3072),(192,96,3072),(256,160,1536),(256,160,6144),(384,256,6144)]:
res, st = laya_opt.score_texts(agent, EKMAN_QUESTIONS, texts, max_len=max_len, head_max_len=head,
token_budget=budget, log=lambda *a: None)
lab = np.array([r["ekman"]["choice"] for r in res])
p = np.array([max(r["ekman"]["probabilities"].values()) for r in res])
if ref is None: ref, refp = lab, p
print(f"max_len={max_len:4d} head={head:3d} budget={budget:4d} L={st['max_seq_len']:4d} "
f"passes={st['forward_passes']:3d} {st['seconds']:6.1f}s {st['ms_per_doc']:6.0f} ms/doc "
f"labels_stable={(lab==ref).mean():.3f} mean|dp|={np.abs(p-refp).mean():.4f}")
sys.stdout.flush()