toxic-comment-classifier 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {toxic_comment_classifier-0.2.2/toxic_comment_classifier.egg-info → toxic_comment_classifier-0.2.4}/PKG-INFO +1 -1
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/pyproject.toml +1 -1
- toxic_comment_classifier-0.2.2/toxic_classifier/model/model.h5 → toxic_comment_classifier-0.2.4/toxic_classifier/model/model.weights.h5 +0 -0
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/toxic_classifier/model.py +18 -14
- toxic_comment_classifier-0.2.4/toxic_classifier/utils.py +11 -0
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4/toxic_comment_classifier.egg-info}/PKG-INFO +1 -1
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/toxic_comment_classifier.egg-info/SOURCES.txt +1 -1
- toxic_comment_classifier-0.2.2/toxic_classifier/utils.py +0 -10
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/LICENSE.txt +0 -0
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/MANIFEST.in +0 -0
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/README.md +0 -0
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/setup.cfg +0 -0
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/toxic_classifier/__init__.py +0 -0
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/toxic_classifier/model/tokenizer.pickle +0 -0
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/toxic_comment_classifier.egg-info/dependency_links.txt +0 -0
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/toxic_comment_classifier.egg-info/requires.txt +0 -0
- {toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/toxic_comment_classifier.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: toxic_comment_classifier
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: A Python library for classifying toxic comments using deep learning. It supports detecting multiple types of toxicity including obscene language, threats, and identity hate.
|
|
5
5
|
Author-email: Md Irfan Ali <irfanali29@hotmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "toxic_comment_classifier"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.4"
|
|
4
4
|
description = " A Python library for classifying toxic comments using deep learning. It supports detecting multiple types of toxicity including obscene language, threats, and identity hate."
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Md Irfan Ali", email = "irfanali29@hotmail.com" }
|
|
Binary file
|
|
@@ -2,24 +2,23 @@ import os
|
|
|
2
2
|
import pickle
|
|
3
3
|
import numpy as np
|
|
4
4
|
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
|
5
|
-
from tensorflow.keras.models import
|
|
6
|
-
from tensorflow.keras.layers import Embedding, LSTM, Dense
|
|
5
|
+
from tensorflow.keras.models import Model
|
|
6
|
+
from tensorflow.keras.layers import Input, Embedding, LSTM, Bidirectional, GlobalMaxPooling1D, Dense, Dropout
|
|
7
7
|
from typing import List
|
|
8
8
|
|
|
9
9
|
# === Constants ===
|
|
10
10
|
MAXLEN = 100
|
|
11
|
+
VOCAB_SIZE = 20000
|
|
12
|
+
EMBEDDING_DIM = 50
|
|
11
13
|
LIST_CLASSES = ["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"]
|
|
12
|
-
VOCAB_SIZE = 20000 # Update this if your training tokenizer used a different size
|
|
13
|
-
EMBEDDING_DIM = 128 # Must match the training setup
|
|
14
14
|
|
|
15
|
-
# === Model Class ===
|
|
16
15
|
class ToxicCommentClassifier:
|
|
17
16
|
def __init__(self):
|
|
18
17
|
"""
|
|
19
|
-
Initializes the classifier by loading
|
|
18
|
+
Initializes the classifier by loading tokenizer and model weights.
|
|
20
19
|
"""
|
|
21
20
|
base_path = os.path.dirname(os.path.abspath(__file__))
|
|
22
|
-
model_path = os.path.join(base_path, "model", "model.h5")
|
|
21
|
+
model_path = os.path.join(base_path, "model", "model.weights.h5")
|
|
23
22
|
tokenizer_path = os.path.join(base_path, "model", "tokenizer.pickle")
|
|
24
23
|
|
|
25
24
|
# Load Tokenizer
|
|
@@ -27,13 +26,18 @@ class ToxicCommentClassifier:
|
|
|
27
26
|
self.tokenizer = pickle.load(handle)
|
|
28
27
|
|
|
29
28
|
# Rebuild model architecture (must match training!)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
inp = Input(shape=(MAXLEN,))
|
|
30
|
+
x = Embedding(input_dim=VOCAB_SIZE, output_dim=EMBEDDING_DIM, trainable=False)(inp)
|
|
31
|
+
x = Bidirectional(LSTM(50, return_sequences=True, dropout=0.1, recurrent_dropout=0.1))(x)
|
|
32
|
+
x = GlobalMaxPooling1D()(x)
|
|
33
|
+
x = Dense(50, activation="relu")(x)
|
|
34
|
+
x = Dropout(0.1)(x)
|
|
35
|
+
output = Dense(len(LIST_CLASSES), activation="sigmoid")(x)
|
|
36
|
+
|
|
37
|
+
self.model = Model(inputs=inp, outputs=output)
|
|
38
|
+
self.model.compile(loss='binary_crossentropy', optimizer='adam')
|
|
39
|
+
|
|
40
|
+
# Load weights (trained separately)
|
|
37
41
|
self.model.load_weights(model_path)
|
|
38
42
|
|
|
39
43
|
def classify(self, text: str) -> dict:
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
def clean_text(text: str) -> str:
|
|
4
|
+
"""
|
|
5
|
+
Cleans text by lowercasing, removing special characters and extra spaces.
|
|
6
|
+
"""
|
|
7
|
+
text = text.lower()
|
|
8
|
+
text = re.sub(r"http\S+|www.\S+", "", text) # Remove URLs
|
|
9
|
+
text = re.sub(r"[^a-zA-Z0-9!?.,]", " ", text) # Keep alphanumerics and some punctuation
|
|
10
|
+
text = re.sub(r"\s+", " ", text).strip() # Remove extra spaces
|
|
11
|
+
return text
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: toxic_comment_classifier
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: A Python library for classifying toxic comments using deep learning. It supports detecting multiple types of toxicity including obscene language, threats, and identity hate.
|
|
5
5
|
Author-email: Md Irfan Ali <irfanali29@hotmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -5,7 +5,7 @@ pyproject.toml
|
|
|
5
5
|
toxic_classifier/__init__.py
|
|
6
6
|
toxic_classifier/model.py
|
|
7
7
|
toxic_classifier/utils.py
|
|
8
|
-
toxic_classifier/model/model.h5
|
|
8
|
+
toxic_classifier/model/model.weights.h5
|
|
9
9
|
toxic_classifier/model/tokenizer.pickle
|
|
10
10
|
toxic_comment_classifier.egg-info/PKG-INFO
|
|
11
11
|
toxic_comment_classifier.egg-info/SOURCES.txt
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
|
|
3
|
-
def clean_text(text: str) -> str:
|
|
4
|
-
"""
|
|
5
|
-
Cleans text by removing special characters and multiple spaces.
|
|
6
|
-
"""
|
|
7
|
-
text = text.lower()
|
|
8
|
-
text = re.sub(r"\s+", " ", text) # Remove extra spaces
|
|
9
|
-
text = re.sub(r"[^a-zA-Z0-9!?.,]", " ", text) # Remove special chars
|
|
10
|
-
return text.strip()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{toxic_comment_classifier-0.2.2 → toxic_comment_classifier-0.2.4}/toxic_classifier/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|