SetFit/enron_spam
Viewer β’ Updated β’ 33.7k β’ 2.79k β’ 21
How to use lokas/spam-emails-classifier with Keras:
# Available backend options are: "jax", "torch", "tensorflow".
import os
os.environ["KERAS_BACKEND"] = "jax"
import keras
model = keras.saving.load_model("hf://lokas/spam-emails-classifier")
This model uses a Bidirectional LSTM (BiLSTM) architecture built with Keras to classify email messages as Spam or Ham. It was trained on the Enron Spam Dataset using GloVe word embeddings.
Tokenizer trained on the Enron dataset Embedding β BiLSTM β Dropout β Dense(sigmoid)0 = Ham, 1 = Spamfrom tensorflow.keras.models import load_model
from huggingface_hub import hf_hub_download
import pickle
from tensorflow.keras.preprocessing.sequence import pad_sequences
# Load files from HF Hub
model_path = hf_hub_download("lokas/spam-emails-classifier", "model.h5")
tokenizer_path = hf_hub_download("lokas/spam-emails-classifier", "tokenizer.pkl")
# Load model and tokenizer
model = load_model(model_path)
with open(tokenizer_path, "rb") as f:
tokenizer = pickle.load(f)
# Prediction function
def predict_spam(text):
seq = tokenizer.texts_to_sequences([text])
padded = pad_sequences(seq, maxlen=50) # must match training maxlen
pred = model.predict(padded)[0][0]
return "π« Spam" if pred > 0.5 else "β
Not Spam"
# Example
print(predict_spam("Win a free iPhone now!"))