Spaces:
Sleeping
Sleeping
| """Global configuration for the ACSA-Clothing project (v2: with metadata fusion).""" | |
| from pathlib import Path | |
| # --- Paths --- | |
| ROOT = Path(__file__).resolve().parent.parent | |
| DATA_DIR = ROOT / "data" | |
| CHECKPOINT_DIR = ROOT / "checkpoints" | |
| OUTPUT_DIR = ROOT / "outputs" | |
| REPORT_DIR = ROOT / "reports" | |
| for d in (DATA_DIR, CHECKPOINT_DIR, OUTPUT_DIR, REPORT_DIR): | |
| d.mkdir(parents=True, exist_ok=True) | |
| # Raw data files | |
| RAW_REVIEWS_PATH = DATA_DIR / "raw_reviews.parquet" | |
| RAW_META_PATH = DATA_DIR / "raw_meta.parquet" | |
| # Processed | |
| PROCESSED_PATH = DATA_DIR / "processed_reviews.parquet" | |
| LABELED_PATH = DATA_DIR / "labeled_reviews.parquet" | |
| ASPECT_DICT_PATH = DATA_DIR / "aspect_dict.json" | |
| # Splits | |
| TRAIN_PATH = DATA_DIR / "train.parquet" | |
| VAL_PATH = DATA_DIR / "val.parquet" | |
| TEST_PATH = DATA_DIR / "test.parquet" | |
| # Meta encoder artifacts (vectorizer, scaler, etc.) | |
| META_ENCODER_PATH = DATA_DIR / "meta_encoder.pkl" | |
| # --- HuggingFace Dataset --- | |
| HF_DATASET = "McAuley-Lab/Amazon-Reviews-2023" | |
| CATEGORY = "Clothing_Shoes_and_Jewelry" | |
| HF_REVIEW_CONFIG = f"raw_review_{CATEGORY}" | |
| HF_META_CONFIG = f"raw_meta_{CATEGORY}" | |
| # --- Aspects --- | |
| # 6 high-level aspects relevant to clothing reviews. | |
| ASPECTS = ["SIZE", "MATERIAL", "QUALITY", "APPEARANCE", "STYLE", "VALUE"] | |
| NUM_ASPECTS = len(ASPECTS) | |
| # Per-aspect classes: 0 = Not_Mentioned, 1 = Positive, 2 = Negative | |
| LABEL_MAP = {"Not_Mentioned": 0, "Positive": 1, "Negative": 2} | |
| LABEL_NAMES = ["Not_Mentioned", "Positive", "Negative"] | |
| NUM_CLASSES = 3 | |
| # --- Overall (3-class) label codes (used by baselines + overall_label column) --- | |
| # 0 = Negative, 1 = Neutral, 2 = Positive | |
| OVERALL_LABEL_NAMES = ["Negative", "Neutral", "Positive"] | |
| OVERALL_NUM_CLASSES = 3 | |
| # --- Model --- | |
| BERT_MODEL_NAME = "bert-base-uncased" # 12-layer BERT backbone for the 10W experiment | |
| MAX_LENGTH = 256 | |
| # --- Metadata encoder dims --- | |
| META_FEATURE_TFIDF_DIM = 64 # TF-IDF dim for product features_text | |
| META_CATEGORY_TFIDF_DIM = 36 # TF-IDF dim for categories_text | |
| META_TFIDF_DIM = META_FEATURE_TFIDF_DIM + META_CATEGORY_TFIDF_DIM | |
| META_NUM_DIM = 4 # price, average_rating, log(rating_number), price_missing_flag | |
| META_HIDDEN_DIM = 128 # MLP output dim | |
| META_CROSSATTN_HEADS = 4 # multi-head cross-attention heads | |
| META_NUMERIC_TOKEN_SCALE = 0.10 # keep numeric metadata as a supporting signal; avoid noisy VALUE over-reliance | |
| CROSS_ATTN_RESIDUAL_SCALE = 0.25 # fallback scalar residual if per-aspect scales are not used | |
| # Aspect order: SIZE, MATERIAL, QUALITY, APPEARANCE, STYLE, VALUE. | |
| # Lower values keep cross-attention more dominant; higher values retain more concat stability. | |
| CROSS_ATTN_RESIDUAL_SCALES = [0.25, 0.30, 0.45, 0.45, 0.45, 0.25] | |
| OVERALL_AUX_WEIGHT = 0.35 # keep overall auxiliary learning, but reduce pressure on aspect optimization | |
| # --- Training --- | |
| DEFAULT_BATCH_SIZE = 16 | |
| DEFAULT_EPOCHS = 3 | |
| DEFAULT_LR_BERT = 2e-5 | |
| DEFAULT_LR_HEADS = 1e-3 | |
| DEFAULT_WEIGHT_DECAY = 0.01 | |
| WARMUP_RATIO = 0.1 | |
| # --- Split ratios --- | |
| TRAIN_RATIO = 0.7 | |
| VAL_RATIO = 0.15 | |
| TEST_RATIO = 0.15 | |
| RANDOM_SEED = 42 | |
| # --- Weak labeling --- | |
| VADER_POSITIVE_THRESHOLD = 0.05 | |
| VADER_NEGATIVE_THRESHOLD = -0.05 | |
| RATING_POSITIVE_THRESHOLD = 4 | |
| RATING_NEGATIVE_THRESHOLD = 2 | |
| MIN_REVIEW_LENGTH = 20 | |
| AUDIT_SAMPLE_SIZE = 200 | |
| # When the product's `features` field explicitly lists an aspect-related | |
| # attribute (e.g. "100% cotton" -> MATERIAL aspect is salient), | |
| # bump the prior probability that the corresponding aspect is mentioned/relevant. | |
| META_PRIOR_BOOST = True | |