File size: 1,323 Bytes
730ca57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
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:

```python
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!"))