Text Generation
Transformers
emotion-vectors
interpretability
mechanistic-interpretability
replication
gemma4
google
anthropic
valence-arousal
PCA
logit-lens
linear-probe
probing
emotion
functional-emotions
AI-safety
neuroscience
circumplex-model
activation-extraction
residual-stream
Eval Results (legacy)
Run this model with HF Jobs
Run rain1955/emotion-vector-replication on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/rain1955/emotion-vector-replication. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/rain1955/emotion-vector-replication on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/rain1955/emotion-vector-replication. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/rain1955/emotion-vector-replication. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use rain1955/emotion-vector-replication with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use rain1955/emotion-vector-replication with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="rain1955/emotion-vector-replication")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("rain1955/emotion-vector-replication", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use rain1955/emotion-vector-replication with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "rain1955/emotion-vector-replication" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "rain1955/emotion-vector-replication", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/rain1955/emotion-vector-replication
- SGLang
How to use rain1955/emotion-vector-replication with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "rain1955/emotion-vector-replication" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "rain1955/emotion-vector-replication", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "rain1955/emotion-vector-replication" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "rain1955/emotion-vector-replication", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use rain1955/emotion-vector-replication with Docker Model Runner:
docker model run hf.co/rain1955/emotion-vector-replication
Add analyze_vectors.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148#!/usr/bin/env python3"""Analyze extracted emotion vectors: cosine similarity, clustering, visualization."""
import jsonimport osimport numpy as np
EXP_DIR = os.path.dirname(os.path.abspath(__file__))RESULTS_DIR = os.path.join(EXP_DIR, "results")
def load_vectors(): vectors_file = os.path.join(RESULTS_DIR, "emotion_vectors.npz") data = np.load(vectors_file) return {name: data[name] for name in data.files}
def cosine_sim(a, b): return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b) + 1e-8)
def cosine_similarity_matrix(vectors): emotions = sorted(vectors.keys()) n = len(emotions) matrix = np.zeros((n, n)) for i, e1 in enumerate(emotions): for j, e2 in enumerate(emotions): matrix[i, j] = cosine_sim(vectors[e1], vectors[e2]) return emotions, matrix
def print_similarity_matrix(emotions, matrix): print("\n=== Cosine Similarity Matrix ===\n") # Header header = f"{'':12s}" + "".join(f"{e[:6]:>7s}" for e in emotions) print(header) for i, e in enumerate(emotions): row = f"{e:12s}" + "".join(f"{matrix[i,j]:7.2f}" for j in range(len(emotions))) print(row)
def find_clusters(emotions, matrix, threshold=0.5): """Find emotion pairs with high similarity.""" print(f"\n=== High Similarity Pairs (>{threshold}) ===\n") pairs = [] for i in range(len(emotions)): for j in range(i + 1, len(emotions)): if matrix[i, j] > threshold: pairs.append((emotions[i], emotions[j], matrix[i, j])) pairs.sort(key=lambda x: -x[2]) for e1, e2, sim in pairs: print(f" {e1:12s} <-> {e2:12s} sim={sim:.3f}") if not pairs: print(" (none found)") return pairs
def find_opposites(emotions, matrix, threshold=-0.3): """Find emotion pairs with negative similarity (opposites).""" print(f"\n=== Opposite Pairs (<{threshold}) ===\n") pairs = [] for i in range(len(emotions)): for j in range(i + 1, len(emotions)): if matrix[i, j] < threshold: pairs.append((emotions[i], emotions[j], matrix[i, j])) pairs.sort(key=lambda x: x[2]) for e1, e2, sim in pairs: print(f" {e1:12s} <-> {e2:12s} sim={sim:.3f}") if not pairs: print(" (none found)") return pairs
def valence_arousal_check(emotions, pca_results): """Check if PC1≈valence, PC2≈arousal based on known emotion groupings.""" print("\n=== Valence-Arousal Structure Check ===\n")
positive = {"happy", "proud", "inspired", "loving", "hopeful", "calm", "playful"} negative = {"sad", "angry", "afraid", "desperate", "guilty", "disgusted", "lonely", "spiteful"} high_arousal = {"angry", "afraid", "surprised", "desperate", "inspired", "nervous", "anxious"} low_arousal = {"calm", "sad", "brooding", "lonely", "guilty"}
for pc_name, pc_vals in [("PC1", pca_results["pc1"]), ("PC2", pca_results["pc2"])]: pos_vals = [pc_vals[i] for i, e in enumerate(pca_results["emotions"]) if e in positive] neg_vals = [pc_vals[i] for i, e in enumerate(pca_results["emotions"]) if e in negative] hi_vals = [pc_vals[i] for i, e in enumerate(pca_results["emotions"]) if e in high_arousal] lo_vals = [pc_vals[i] for i, e in enumerate(pca_results["emotions"]) if e in low_arousal]
pos_mean = np.mean(pos_vals) if pos_vals else 0 neg_mean = np.mean(neg_vals) if neg_vals else 0 hi_mean = np.mean(hi_vals) if hi_vals else 0 lo_mean = np.mean(lo_vals) if lo_vals else 0
valence_sep = abs(pos_mean - neg_mean) arousal_sep = abs(hi_mean - lo_mean)
print(f" {pc_name}:") print(f" Positive mean: {pos_mean:+.3f} Negative mean: {neg_mean:+.3f} → Valence separation: {valence_sep:.3f}") print(f" High-A mean: {hi_mean:+.3f} Low-A mean: {lo_mean:+.3f} → Arousal separation: {arousal_sep:.3f}")
if valence_sep > arousal_sep: print(f" → {pc_name} ≈ VALENCE axis") else: print(f" → {pc_name} ≈ AROUSAL axis")
def main(): print("=== Emotion Vector Analysis ===\n")
# Load vectors vectors = load_vectors() print(f"Loaded {len(vectors)} emotion vectors") print(f"Vector dimension: {next(iter(vectors.values())).shape[0]}")
# Load experiment results for PCA results_file = os.path.join(RESULTS_DIR, "experiment_results.json") with open(results_file, "r") as f: results = json.load(f)
# Similarity analysis emotions, matrix = cosine_similarity_matrix(vectors) print_similarity_matrix(emotions, matrix) find_clusters(emotions, matrix, threshold=0.4) find_opposites(emotions, matrix, threshold=-0.2)
# Valence-Arousal check if "pca" in results: valence_arousal_check(emotions, results["pca"])
# Summary print("\n=== SUMMARY ===\n") avg_sim = matrix[np.triu_indices_from(matrix, k=1)].mean() print(f" Average pairwise similarity: {avg_sim:.3f}") print(f" Variance explained by PC1+PC2: {(results['pca']['explained_variance_pc1'] + results['pca']['explained_variance_pc2'])*100:.1f}%")
# Anthropic found ~30% variance in first 2 PCs for 171 emotions # With 20 emotions, we'd expect higher concentration var_12 = results['pca']['explained_variance_pc1'] + results['pca']['explained_variance_pc2'] if var_12 > 0.3: print(" ✓ Strong 2D structure detected (>30% in PC1+PC2)") else: print(" ✗ Weak 2D structure (<30% in PC1+PC2)")
print("\n=== ANALYSIS COMPLETE ===")
if __name__ == "__main__": main()analyze_vectors.pyAdded+148