Spaces:
Running
Running
File size: 3,555 Bytes
edf3081 11e6e78 edf3081 | 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 | """
preprocessing/config.py
ββββββββββββββββββββββββ
Central configuration for all preprocessing pipelines.
All hyperparameters live here β never hardcoded in individual modules.
"""
import pathlib
# ββ Project paths ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ROOT = pathlib.Path(__file__).parents[1]
DATA_DIR = ROOT / "data"
SPLITS_DIR = DATA_DIR / "splits"
ARTIFACTS_DIR = ROOT / "preprocessing" / "artifacts"
# Created on import so all modules can write immediately
ARTIFACTS_DIR.mkdir(parents=True, exist_ok=True)
(ARTIFACTS_DIR / "tokenizers").mkdir(exist_ok=True)
# ββ Reproducibility ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SEED = 42
# ββ Dataset ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
DATASET_NAME = "amazon_polarity"
LABEL_MAP = {0: "negative", 1: "positive"}
# ββ Global cleaning ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
MIN_TEXT_LENGTH = 10 # characters; texts shorter than this are dropped
# ββ Classical ML (TF-IDF) βββββββββββββββββββββββββββββββββββββββββββββββββββββ
TFIDF_CONFIG = {
"ngram_range": (1, 2), # unigrams + bigrams β captures "not good", "very bad"
"max_features": 100_000, # top-N features by corpus TF-IDF score
"sublinear_tf": True, # log(1+tf) β dampens high-frequency dominance
"min_df": 2, # drop hapax legomena
"max_df": 0.95, # soft stop-word filter (data-driven)
"strip_accents": "unicode",
"analyzer": "word",
}
# ββ Deep Learning (LSTM / CNN-LSTM) βββββββββββββββββββββββββββββββββββββββββββ
DL_MAX_LEN = 200 # token sequence length (covers ~95th percentile of reviews)
DL_EMBED_DIM = 100 # must match GloVe file (glove.6B.100d)
DL_MIN_FREQ = 2 # minimum token frequency for vocabulary inclusion
PAD_TOKEN = "<PAD>" # index 0 β zero-padded, no gradient
UNK_TOKEN = "<UNK>" # index 1 β out-of-vocabulary at test time
# ββ Transformers (BERT / DistilBERT) ββββββββββββββββββββββββββββββββββββββββββ
TRANSFORMER_MODELS = {
"bert": "bert-base-uncased",
"distilbert": "distilbert-base-uncased",
"roberta": "roberta-base",
}
TRANSFORMER_MAX_LEN = 128 # subword tokens; covers ~90th percentile of reviews
# ββ Artifact filenames βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ARTIFACT_TFIDF = "tfidf_vectorizer.joblib"
ARTIFACT_VOCABULARY = "vocabulary.pkl"
ARTIFACT_VOCAB_CFG = "vocab_config.json"
ARTIFACT_SPLITS_META = "splits_metadata.json"
ARTIFACT_PREP_LOG = "preprocessing_log.json"
|