"""Configuration settings for EUMORA lyrical analysis.""" import os from dataclasses import dataclass, field from pathlib import Path from typing import Dict, List, Optional @dataclass class Config: """Training and model configuration.""" # Paths # EUMORA_ROOT can be set to the repo root when running from outside backend/ project_root: Path = field( default_factory=lambda: Path( os.environ.get("EUMORA_ROOT", str(Path(__file__).parent.parent)) ) ) @property def data_dir(self) -> Path: path = self.project_root / "data" path.mkdir(exist_ok=True) return path @property def model_dir(self) -> Path: path = self.project_root / "models" path.mkdir(exist_ok=True) return path # Model settings - using DeBERTa-v3-Base for superior emotion understanding model_name: str = "microsoft/deberta-v3-base" max_length: int = 256 # Increased for longer lyrics/text # Training settings batch_size: int = 16 learning_rate: float = 2e-5 num_epochs: int = 4 warmup_ratio: float = 0.1 weight_decay: float = 0.01 # Emotion labels (8 emotions including neutral and sarcasm) label_names: tuple = ("sadness", "joy", "love", "anger", "fear", "surprise", "neutral", "sarcasm") num_labels: int = 8 # Sarcasm calibration defaults for lyric-domain inference target_sarcasm_prior: float = 0.15 assumed_train_sarcasm_prior: float = 0.5 sarcasm_threshold: Optional[float] = None # Dataset options hf_dataset_name: str = "dair-ai/emotion" goemotions_name: str = "google-research-datasets/go_emotions" # Emotion to music context mapping @property def emotion_to_music_mood(self) -> Dict: return { "sadness": {"mood": "melancholic", "energy": "low", "valence": "negative"}, "joy": {"mood": "happy", "energy": "high", "valence": "positive"}, "love": {"mood": "romantic", "energy": "medium", "valence": "positive"}, "anger": {"mood": "intense", "energy": "high", "valence": "negative"}, "fear": {"mood": "anxious", "energy": "medium", "valence": "negative"}, "surprise": {"mood": "excited", "energy": "high", "valence": "mixed"}, "neutral": {"mood": "calm", "energy": "low", "valence": "neutral"}, "sarcasm": {"mood": "ironic", "energy": "medium", "valence": "mixed"}, } # Global config instance config = Config()