Views
No views yet
0: Not Cyberbullying1: Gender (Sexist)2: Religion3: Age4: Ethnicity (Racist)tweet-preprocessor library and custom functions:WordNetLemmatizer.LogisticRegression (C=100, penalty='l2')RandomForestClassifier (n_estimators=100)VotingClassifier (Hard Voting) combining the above two.joblib.1import joblib
2import preprocessor as p # pip install tweet-preprocessor
3import string
4
5# 1. Load the saved files
6model = joblib.load('model.pickle')
7vectorizer = joblib.load('tfidf.pickle')
8
9# 2. Define the cleaning function (Must match training!)
10def clean_text(text):
11 text = p.clean(text)
12 text = text.lower()
13 text = "".join([char for char in text if char not in string.punctuation])
14 return text
15
16# 3. Make a prediction
17text = "You are dumb and you should go back to school."
18clean_input = clean_text(text)
19
20# Vectorize the text
21vectorized_input = vectorizer.transform([clean_input])
22
23# Predict
24prediction = model.predict(vectorized_input)
25classes = {0: 'Not Cyberbullying', 1: 'Gender', 2: 'Religion', 3: 'Age', 4: 'Ethnicity'}
26
27print(f"Prediction: {classes[prediction[0]]}")