lstm-spam-detector / README.md
lokas's picture
Update README.md
730ca57 verified
metadata
language: en
license: mit
tags:
  - keras
  - lstm
  - spam-detection
  - binary-classification
  - text-classification
  - email
library_name: keras
model_name: LSTM Spam Detector
pipeline_tag: text-classification

🧠 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!"))