CoolFace
Apppublic

Benjamin-GitHub/Fake-News-Detector

sourceHugging Faceupdated 1y agoView on Hugging Face
4likes
vectorizer_utils.py23 linesDownload Raw Back to root
1import re2import string3from sklearn.feature_extraction.text import TfidfVectorizer4from sklearn.pipeline import Pipeline5 6def clean_text(text):7    """Lowercase, remove punctuation and digits."""8    text = text.lower()9    text = re.sub(f"[{string.punctuation}]", "", text)10    text = re.sub(r"\d+", "", text)11    return text12 13def create_vectorizer():14    """Return a configured TF-IDF vectorizer."""15    return TfidfVectorizer(stop_words='english', max_df=0.7, max_features=5000)16 17def create_pipeline(model):18    """Return a Pipeline of vectorizer + model."""19    return Pipeline([20        ('tfidf', create_vectorizer()),21        ('model', model)22    ])23