Downloads · 30 days
0
ash001/imdb-sentiment-simple-rnn
imdb-sentiment-simple-rnn is a text classification model from ash001. Use it when you need a label for a piece of text. It is set up for tf-keras. The card lists the license as apache-2.0.
A lightweight SimpleRNN model trained on the Keras IMDB dataset to predict movie review sentiment.
Downloads · 30 days
0
Access
Public
Updated Mar 2, 2026
Repo size
15.8 MB
Likes
0
Public
Click a slice to open those files.
.h515.8 MB · 100%
From the Hugging Face model README
A lightweight SimpleRNN model trained on the Keras IMDB dataset to predict movie review sentiment.
This Hugging Face repo hosts the trained model artifact used by a Streamlit inference app.
pages/03_IMDB_Sentiment_SimpleRNN.py)artifacts/simple_rnn_imdb.h5 — trained Keras modelartifacts/config.json — key inference settings:
max_features (vocab size cap)max_len (sequence length)threshold_default (classification threshold)[a-z']+tensorflow.keras.datasets.imdb.get_word_index())12+3max_features; anything outside becomes 2 (unknown)max_len using pad_sequences (padding="pre", truncating="post")[0, 1].Positive if P(positive) >= thresholdNegative otherwiseartifacts/config.json (typically 0.5).import re
import numpy as np
import tensorflow as tf
from huggingface_hub import hf_hub_download
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.datasets import imdb
import json
REPO_ID = "ash001/imdb-sentiment-simple-rnn"
# Load model + config
model_path = hf_hub_download(REPO_ID, "artifacts/simple_rnn_imdb.h5")
cfg_path = hf_hub_download(REPO_ID, "artifacts/config.json")
cfg = json.load(open(cfg_path, "r"))
model = tf.keras.models.load_model(model_path, compile=False)
word_index = imdb.get_word_index()
max_features = int(cfg["max_features"])
max_len = int(cfg["max_len"])
threshold = float(cfg.get("threshold_default", 0.5))
def text_to_sequence(text: str):
text = text.lower()
tokens = re.findall(r"[a-z']+", text)
seq = [1] # start token
for w in tokens:
idx = word_index.get(w, 2) + 3
if idx >= max_features:
idx = 2
seq.append(idx)
return pad_sequences([seq], maxlen=max_len, truncating="post", padding="pre")
text = "This movie was surprisingly good, with great acting and a strong ending."
X = text_to_sequence(text)
prob_pos = float(model.predict(X, verbose=0).reshape(-1)[0])
label = "Positive" if prob_pos >= threshold else "Negative"
print("P(positive) =", prob_pos, "|", label)