Views
No views yet
| Path | Description |
|---|---|
demographic_vectors/ | Demographic identity vectors in .pt and .safetensors formats |
vector_metadata.jsonl | One metadata row per vector file |
wvs_questions/questions.jsonl | WVS question metadata in JSONL format |
wvs_questions/question_mapping.json | Question-id keyed WVS metadata mapping |
.pt file loads as a torch.Tensor with dtype float16. Each .safetensors file contains the same tensor under the key vector.| Model directory | Tensor shape | Files |
|---|---|---|
llama3.1-8b | (33, 4096) | 75 .pt + 75 .safetensors |
mistral-24b | (41, 5120) | 75 .pt + 75 .safetensors |
qwen2.5-7b | (29, 3584) | 75 .pt + 75 .safetensors |
qwen2.5-14b | (49, 5120) | 75 .pt + 75 .safetensors |
1demographic_vectors/<model>/<WVS question id>_<option code>.pt
2demographic_vectors/<model>/<WVS question id>_<option code>.safetensorsdemographic_vectors/llama3.1-8b/Q260_1.pt corresponds to Respondent's Sex / Male for llama3.1-8b.steering_strength * vector to the hidden states.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4
5model_name = "meta-llama/Llama-3.1-8B-Instruct"
6vector_path = "demographic_vectors/llama3.1-8b/Q260_1.pt"
7
8tokenizer = AutoTokenizer.from_pretrained(model_name)
9model = AutoModelForCausalLM.from_pretrained(
10 model_name,
11 torch_dtype=torch.float16,
12 device_map="auto",
13)
14
15psii_vector = torch.load(vector_path, map_location="cpu")
16
17target_layer_idx = 16
18steering_strength = 1.0
19steering_vector = psii_vector[target_layer_idx]
20
21
22def add_psii_vector(module, inputs, output):
23 if isinstance(output, tuple):
24 hidden_states = output[0]
25 vector = steering_vector.to(device=hidden_states.device, dtype=hidden_states.dtype)
26 hidden_states = hidden_states + steering_strength * vector
27 return (hidden_states,) + output[1:]
28
29 vector = steering_vector.to(device=output.device, dtype=output.dtype)
30 return output + steering_strength * vector
31
32
33handle = model.model.layers[target_layer_idx].register_forward_hook(add_psii_vector)
34
35inputs = tokenizer("What is your view on social equality?", return_tensors="pt").to(model.device)
36with torch.no_grad():
37 generated = model.generate(**inputs, max_new_tokens=128)
38
39handle.remove()
40print(tokenizer.decode(generated[0], skip_special_tokens=True))1from safetensors.torch import load_file
2
3
4tensors = load_file("demographic_vectors/llama3.1-8b/Q260_1.safetensors")
5vector = tensors["vector"]
6print(vector.shape, vector.dtype)wvs_questions/questions.jsonl contains 290 WVS question metadata records. Each row contains:question_idquestion_textoptions1@article{wang2026parametric,
2 title={Parametric Social Identity Injection and Diversification in Public Opinion Simulation},
3 author={Wang, Hexi and Zhou, Yujia and Du, Bangde and Ai, Qingyao and Liu, Yiqun},
4 journal={arXiv preprint arXiv:2603.16142},
5 year={2026}
6}