Download code/dataset/schema.py from Jommarn/Qwen3.5-0.8B-NestedMemory-v5: direct link, hf CLI and curl.
- Browser
- Download file 5.81 kB
-
https://huggingface.co/Jommarn/Qwen3.5-0.8B-NestedMemory-v5/resolve/main/code/dataset/schema.py
- Command line
-
hf download hf://Jommarn/Qwen3.5-0.8B-NestedMemory-v5/code/dataset/schema.py
-
curl -L -o schema.py https://huggingface.co/Jommarn/Qwen3.5-0.8B-NestedMemory-v5/resolve/main/code/dataset/schema.py
5.81 kB
| from __future__ import annotations | |
| from dataclasses import asdict, dataclass, field | |
| import json | |
| from pathlib import Path | |
| from typing import Any, Literal, Optional | |
| SplitType = Literal["train", "val", "test"] | |
| EventKind = Literal["episode", "fact", "preference", "relationship"] | |
| RehearsalType = Literal["mentioned", "recalled", "retold"] | |
| QueryType = Literal[ | |
| "single_fact", | |
| "episode_detail", | |
| "temporal", | |
| "update", | |
| "multi_hop", | |
| "person", | |
| "absent", | |
| ] | |
| RecallLabel = Literal["full", "partial", "forgotten"] | |
| class ForgettingParams: | |
| model: str = "exp_stability_v1" | |
| S0_days: float = 3.0 | |
| a_importance: float = 4.0 | |
| b_arousal: float = 2.0 | |
| c_rehearsal: float = 0.8 | |
| partial_band: float = 0.2 | |
| class Meta: | |
| life_id: str | |
| schema_version: str = "1.0" | |
| language: str = "th" | |
| split: SplitType = "train" | |
| seed: int = 1234 | |
| generator: str = "synthetic_v1" | |
| start_date: str = "2026-01-01" | |
| n_days: int = 90 | |
| forgetting_params: ForgettingParams = field(default_factory=ForgettingParams) | |
| class Person: | |
| person_id: str | |
| name: str | |
| relation: str | |
| closeness: float | |
| first_met_day: int | |
| is_interlocutor: bool = True | |
| class Persona: | |
| name: str | |
| age: int | |
| occupation: str | |
| location: str | |
| traits: list[str] | |
| speaking_style: str | |
| backstory: list[str] = field(default_factory=list) | |
| memory_tendency: float = 0.9 | |
| people: list[Person] = field(default_factory=list) | |
| class Emotion: | |
| label: str = "neutral" | |
| valence: float = 0.0 | |
| arousal: float = 0.1 | |
| class EventDetails: | |
| who: list[str] = field(default_factory=list) | |
| where: Optional[str] = None | |
| what: str = "" | |
| objects: list[str] = field(default_factory=list) | |
| class Triple: | |
| subject: str | |
| relation: str | |
| object: str | |
| class Rehearsal: | |
| session_id: str | |
| day: int | |
| type: RehearsalType = "mentioned" | |
| class TimelineEvent: | |
| event_id: str | |
| day: int | |
| kind: EventKind | |
| summary: str | |
| time: Optional[str] = None | |
| details: EventDetails = field(default_factory=EventDetails) | |
| triple: Optional[Triple] = None | |
| participants: list[str] = field(default_factory=list) | |
| topic: list[str] = field(default_factory=list) | |
| importance: float = 0.5 | |
| emotion: Emotion = field(default_factory=Emotion) | |
| supersedes: Optional[str] = None | |
| related: list[str] = field(default_factory=list) | |
| rehearsals: list[Rehearsal] = field(default_factory=list) | |
| class Turn: | |
| turn_id: int | |
| speaker: str # "self" or person_id | |
| text: str | |
| refs: list[str] = field(default_factory=list) | |
| is_probe: bool = False | |
| class Session: | |
| session_id: str | |
| day: int | |
| start_time: str | |
| end_time: str | |
| gap_hours: float | |
| interlocutor: str | |
| new_events: list[str] = field(default_factory=list) | |
| rehearsed_events: list[str] = field(default_factory=list) | |
| turns: list[Turn] = field(default_factory=list) | |
| sleep_after: bool = True | |
| class Probe: | |
| probe_id: str | |
| session_id: str | |
| day: int | |
| target_events: list[str] | |
| q_type: QueryType | |
| question: str | |
| paraphrase_group: str | |
| gap_days: float | |
| n_rehearsals: int | |
| days_since_last_rehearsal: float | |
| stability: float | |
| p_recall: float | |
| recall_label: RecallLabel | |
| ground_truth: str | |
| target_answer: str | |
| kept_details: list[str] = field(default_factory=list) | |
| acceptable_answers: list[str] = field(default_factory=list) | |
| class LifeDataset: | |
| meta: Meta | |
| persona: Persona | |
| timeline: list[TimelineEvent] = field(default_factory=list) | |
| sessions: list[Session] = field(default_factory=list) | |
| probes: list[Probe] = field(default_factory=list) | |
| def to_dict(self) -> dict[str, Any]: | |
| return asdict(self) | |
| def save_json(self, path: str | Path) -> None: | |
| p = Path(path) | |
| p.parent.mkdir(parents=True, exist_ok=True) | |
| with p.open("w", encoding="utf-8") as f: | |
| json.dump(self.to_dict(), f, ensure_ascii=False, indent=2) | |
| def from_dict(cls, data: dict[str, Any]) -> "LifeDataset": | |
| meta_raw = data["meta"] | |
| fp = ForgettingParams(**meta_raw["forgetting_params"]) | |
| meta = Meta(**{**meta_raw, "forgetting_params": fp}) | |
| persona_raw = data["persona"] | |
| people = [Person(**p) for p in persona_raw.get("people", [])] | |
| persona = Persona(**{**persona_raw, "people": people}) | |
| timeline = [] | |
| for ev in data.get("timeline", []): | |
| details = EventDetails(**ev.get("details", {})) | |
| triple = Triple(**ev["triple"]) if ev.get("triple") else None | |
| emotion = Emotion(**ev.get("emotion", {})) | |
| rehearsals = [Rehearsal(**r) for r in ev.get("rehearsals", [])] | |
| timeline.append( | |
| TimelineEvent( | |
| **{ | |
| **ev, | |
| "details": details, | |
| "triple": triple, | |
| "emotion": emotion, | |
| "rehearsals": rehearsals, | |
| } | |
| ) | |
| ) | |
| sessions = [] | |
| for s in data.get("sessions", []): | |
| turns = [Turn(**t) for t in s.get("turns", [])] | |
| sessions.append(Session(**{**s, "turns": turns})) | |
| probes = [Probe(**pr) for pr in data.get("probes", [])] | |
| return cls( | |
| meta=meta, | |
| persona=persona, | |
| timeline=timeline, | |
| sessions=sessions, | |
| probes=probes, | |
| ) | |
| def load_json(cls, path: str | Path) -> "LifeDataset": | |
| with Path(path).open("r", encoding="utf-8") as f: | |
| return cls.from_dict(json.load(f)) | |