Views
No views yet
preprocess.py):data_cleaning function from preprocess.py before passing text to the model.1import tensorflow as tf
2from preprocess import prepare_input
3
4# 1. Load the Hybrid CNN-BiGRU Model
5# Ensure 'tokenizer.json' and 'preprocess.py' are in the same directory
6model = tf.keras.models.load_model("arabic_misogyny_hybrid_model.keras")
7
8def predict_misogyny(tweets):
9 """
10 Cleans, tokenizes, and predicts for a list of raw Arabic strings.
11 """
12 # Unified pipeline: Clean -> Tokenize -> Pad
13 # Returns a shape of (len(tweets), 48)
14 processed_data = [prepare_input(tweet) for tweet in tweets]
15
16 # Reshape for bulk prediction if necessary, or predict individually
17 for i, tweet in enumerate(tweets):
18 input_row = prepare_input(tweet)
19 prediction = model.predict(input_row, verbose=0)[0][0]
20
21 label = "MISOGYNY" if prediction > 0.5 else "NEUTRAL"
22 confidence = prediction if prediction > 0.5 else 1 - prediction
23
24 print(f"Tweet: {tweet}")
25 print(f"Result: {label} | Confidence: {confidence*100:.2f}%\n")
26
27# --- Example Run ---
28examples = [
29 "أنتِ رائعة حقاً", # Neutral
30 "أنتِ رائعة حقاً؟ 🤮", # Misogynistic (Sarcasm/Emoji)
31 "سوف تندمين #يا_واطية" # Misogynistic (Hashtag)
32]
33
34predict_misogyny(examples)