Spaces:
Runtime error
Runtime error
Download utils/preprocessing.py from arifa-batool/spam-filter-app: direct link, hf CLI and curl.
- Browser
- Download file 674 Bytes
-
https://huggingface.co/spaces/arifa-batool/spam-filter-app/resolve/main/utils/preprocessing.py
- Command line
-
hf download hf://spaces/arifa-batool/spam-filter-app/utils/preprocessing.py
-
curl -L -o preprocessing.py https://huggingface.co/spaces/arifa-batool/spam-filter-app/resolve/main/utils/preprocessing.py
674 Bytes
| import re | |
| import string | |
| import nltk | |
| from nltk.corpus import stopwords | |
| from nltk.stem import WordNetLemmatizer | |
| nltk.download('punkt') | |
| nltk.download('punkt_tab') | |
| nltk.download('stopwords') | |
| nltk.download('wordnet') | |
| stop_words = set(stopwords.words('english')) | |
| lemmatizer = WordNetLemmatizer() | |
| def preprocess_text(text: str) -> str: | |
| """Clean and preprocess input text.""" | |
| text = text.lower() | |
| text = re.sub(r'[^a-zA-Z0-9\s]', ' ', text) | |
| tokens = nltk.word_tokenize(text) | |
| tokens = [word for word in tokens if word not in stop_words and word not in string.punctuation] | |
| tokens = [lemmatizer.lemmatize(word) for word in tokens] | |
| return " ".join(tokens) | |