Spaces:
Running
Running
Download preprocessing/config.py from anikethans06/capstone: direct link, hf CLI and curl.
- Browser
- Download file 3.56 kB
-
https://huggingface.co/spaces/anikethans06/capstone/resolve/main/preprocessing/config.py
- Command line
-
hf download hf://spaces/anikethans06/capstone/preprocessing/config.py
-
curl -L -o config.py https://huggingface.co/spaces/anikethans06/capstone/resolve/main/preprocessing/config.py
3.56 kB
| """ | |
| 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" | |