dudulu66666's picture
Add files using upload-large-folder tool
4968ea3 verified
Raw
History Blame Contribute Delete
2.36 kB
"""Unified data format definitions for MetaMem."""
from dataclasses import dataclass, field, asdict
from typing import Optional
@dataclass
class UserSession:
"""A single conversation session."""
session_id: str
timestamp: str
turns: list # list of {"role": str, "content": str, optional "has_answer": bool}
@dataclass
class MemoryBankRecord:
"""A session-level memory record for retrieval."""
id: str
source_session_id: str
content: str
timestamp: str
@dataclass
class Query:
"""A user memory query with annotations."""
id: str
query: str
answer: str
evidence_session_ids: list
query_type: str
ms_label: Optional[str] = None
rewrite_query: Optional[str] = None
@dataclass
class UserData:
"""Complete data package for one user."""
user_id: str
user_sessions: list # list of UserSession (serialized as dicts)
memory_bank: list # list of MemoryBankRecord (serialized as dicts)
queries: list # list of Query (serialized as dicts)
def to_dict(self) -> dict:
return asdict(self)
@classmethod
def from_dict(cls, d: dict) -> "UserData":
return cls(
user_id=d["user_id"],
user_sessions=d["user_sessions"],
memory_bank=d["memory_bank"],
queries=d["queries"],
)
@dataclass
class FIRPrediction:
"""FIR probing result for one query."""
user_id: str
query_id: str
query: str
gold_answer: str
predictions: list # list of str
model_name: str
lora_path: str
temperature: float
num_samples: int
@dataclass
class MSLabel:
"""Memory state label from multi-teacher judgment."""
query_id: str
ms_label: str # SM/PM/VM/NM
agreement: float # teacher agreement ratio
final_confidence: float
sample_weight: float
status: str # UNANIMOUS/MAJORITY/AMBIGUOUS
teacher_results: list # raw results from each teacher
@dataclass
class RewriteQuery:
"""Rewrite query result from multi-teacher generation."""
query_id: str
rewrite_query: str
ms_label: str
best_rank: Optional[int] = None
original_rank: Optional[int] = None
source_teacher: Optional[str] = None
all_teacher_rewrites: list = field(default_factory=list)
validation_result: Optional[dict] = None