File size: 7,018 Bytes
e7e1778
 
 
 
 
 
 
 
 
 
6619824
e7e1778
 
6619824
e7e1778
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6619824
e7e1778
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
"""
emotion_engine.py — HuggingFace Datasets loading script

Registered as the dataset builder for the emotion-engine HF repo.
Supports loading by condition name or "all" for the full dataset.

Usage:
    from datasets import load_dataset

    # Single condition
    ds = load_dataset("PremC1F/emotion-engine", "condition_d")

    # All conditions concatenated
    ds = load_dataset("PremC1F/emotion-engine", "all")
"""

import datasets

_CITATION = """
@article{kanaparthi2026emotion,
  author  = {Kanaparthi, Prem Babu},
  title   = {Emergent Emotional Appraisal in Generative Agents
             via Predictive World Modeling},
  year    = {2026},
}
"""

_DESCRIPTION = """
204,520 agent-step records from a five-condition controlled experiment comparing
emotion-engine architectures in a 12-agent ghost-survival simulation (Ghost Town).

Five conditions:
  baseline_0  — no emotion system
  condition_a — hand-coded OCC appraisal rules
  condition_b — behavioral cloning from condition_a
  condition_c — emotion dynamics model
  condition_d — predictive world modeling (proposed)

Six scenarios per condition:
  standard_night, high_ghost_pressure, storm_scarcity,
  ally_death, betrayal_refusal, crowded_shelter

8 random seeds per scenario.

Each record contains: full 14-dim observation, 6-dim emotion vector,
8-dim latent representation, 12 future-event predictions (Condition D),
action taken, and outcome metadata.
"""

_HOMEPAGE = "https://github.com/PremC1F/emotion-engine"
_LICENSE  = "MIT"

_CONDITIONS = [
    "baseline_0",
    "condition_a",
    "condition_b",
    "condition_c",
    "condition_d",
]

_FEATURES = datasets.Features({
    # Identity
    "run_id":    datasets.Value("string"),
    "step":      datasets.Value("int32"),
    "agent_id":  datasets.Value("string"),
    "condition": datasets.Value("string"),
    "seed":      datasets.Value("int32"),
    "scenario":  datasets.Value("string"),

    # Observation (14 dims)
    "obs_visible_ghosts":          datasets.Value("int32"),
    "obs_visible_deaths":          datasets.Value("int32"),
    "obs_nearby_allies":           datasets.Value("int32"),
    "obs_trusted_allies":          datasets.Value("int32"),
    "obs_supplies_seen":           datasets.Value("int32"),
    "obs_in_shelter":              datasets.Value("bool"),
    "obs_nearest_refuge_distance": datasets.Value("float32"),
    "obs_steps_since_ghost_seen":  datasets.Value("int32"),
    "obs_steps_since_ally_died":   datasets.Value("int32"),
    "obs_steps_since_betrayal":    datasets.Value("int32"),
    "obs_ally_deaths_witnessed":   datasets.Value("int32"),
    "obs_betrayals_received":      datasets.Value("int32"),
    "obs_average_trust":           datasets.Value("float32"),
    "obs_graph_tension":           datasets.Value("float32"),

    # Affect / emotion
    "affect_fear":      datasets.Value("float32"),
    "affect_grief":     datasets.Value("float32"),
    "affect_trust":     datasets.Value("float32"),
    "affect_stress":    datasets.Value("float32"),
    "affect_relief":    datasets.Value("float32"),
    "affect_suspicion": datasets.Value("float32"),

    # Latent representation (8 dims)
    "latent_0": datasets.Value("float32"),
    "latent_1": datasets.Value("float32"),
    "latent_2": datasets.Value("float32"),
    "latent_3": datasets.Value("float32"),
    "latent_4": datasets.Value("float32"),
    "latent_5": datasets.Value("float32"),
    "latent_6": datasets.Value("float32"),
    "latent_7": datasets.Value("float32"),

    # Future-event predictions (Condition D; zero for others)
    "pred_ghost_nearby_t3":     datasets.Value("float32"),
    "pred_my_death_t5":         datasets.Value("float32"),
    "pred_health_drop_t3":      datasets.Value("float32"),
    "pred_nearby_death_t5":     datasets.Value("float32"),
    "pred_help_success_t5":     datasets.Value("float32"),
    "pred_refusal_received_t5": datasets.Value("float32"),
    "pred_tie_increase_t5":     datasets.Value("float32"),
    "pred_shelter_achieved_t2": datasets.Value("float32"),
    "pred_storm_onset_t3":      datasets.Value("float32"),
    "pred_scarcity_t5":         datasets.Value("float32"),
    "pred_graph_tension_t3":    datasets.Value("float32"),
    "pred_valence_t5":          datasets.Value("float32"),

    # Action & outcome
    "action":          datasets.Value("string"),
    "goal":            datasets.Value("string"),
    "reward_survival": datasets.Value("float32"),
    "reward_shelter":  datasets.Value("float32"),
    "reward_health":   datasets.Value("float32"),
    "reward_social":   datasets.Value("float32"),
    "total_reward":    datasets.Value("float32"),
    "alive":           datasets.Value("bool"),
    "health":          datasets.Value("float32"),
    "sheltered":       datasets.Value("bool"),
    "time_of_day":     datasets.Value("string"),
})


class EmotionEngineConfig(datasets.BuilderConfig):
    def __init__(self, condition="all", **kwargs):
        super().__init__(**kwargs)
        self.condition = condition


class EmotionEngine(datasets.GeneratorBasedBuilder):
    """Ghost Town emotion engine dataset — 204,520 agent-step records."""

    VERSION = datasets.Version("1.0.0")

    BUILDER_CONFIG_CLASS = EmotionEngineConfig

    BUILDER_CONFIGS = [
        EmotionEngineConfig(
            name="all",
            version=VERSION,
            description="All five conditions concatenated (204,520 records)",
            condition="all",
        ),
    ] + [
        EmotionEngineConfig(
            name=c,
            version=VERSION,
            description=f"Condition {c} only (~40k records, 6 scenarios, 8 seeds)",
            condition=c,
        )
        for c in _CONDITIONS
    ]

    DEFAULT_CONFIG_NAME = "condition_d"

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=_FEATURES,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        if self.config.condition == "all":
            files = {
                c: dl_manager.download(f"data/{c}.parquet")
                for c in _CONDITIONS
            }
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={"filepaths": list(files.values())},
                )
            ]
        else:
            filepath = dl_manager.download(
                f"data/{self.config.condition}.parquet"
            )
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={"filepaths": [filepath]},
                )
            ]

    def _generate_examples(self, filepaths):
        import pandas as pd
        idx = 0
        for path in filepaths:
            df = pd.read_parquet(path)
            for _, row in df.iterrows():
                yield idx, row.to_dict()
                idx += 1