π§ LSTM Spam Detector
This repository contains a simple LSTM-based binary text classification model to detect spam messages, built using Keras and trained on a small dataset of English spam and non-spam messages.
π How to Use
You can use the model and tokenizer in your own code like this:
from tensorflow.keras.models import load_model
from huggingface_hub import hf_hub_download
import pickle
# Download files from Hugging Face Hub
model_path = hf_hub_download("lokas/lstm-spam-detector", "model.h5")
tokenizer_path = hf_hub_download("lokas/lstm-spam-detector", "tokenizer.pkl")
# Load model and tokenizer
model = load_model(model_path)
with open(tokenizer_path, "rb") as f:
tokenizer = pickle.load(f)
# Predict a sample message
from tensorflow.keras.preprocessing.sequence import pad_sequences
def predict_spam(text):
seq = tokenizer.texts_to_sequences([text])
padded = pad_sequences(seq, maxlen=10)
pred = model.predict(padded)[0][0]
return "π« Spam" if pred > 0.5 else "β
Not Spam"
print(predict_spam("Win a free iPhone now!"))
- Downloads last month
- -
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
π
Ask for provider support