toxic-comment-classifier 0.2.1__tar.gz → 0.2.3__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.
Files changed (17) hide show
  1. {toxic_comment_classifier-0.2.1/toxic_comment_classifier.egg-info → toxic_comment_classifier-0.2.3}/PKG-INFO +10 -2
  2. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3}/README.md +8 -0
  3. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3}/pyproject.toml +2 -2
  4. toxic_comment_classifier-0.2.1/toxic_classifier/model/model.h5 → toxic_comment_classifier-0.2.3/toxic_classifier/model/model.weights.h5 +0 -0
  5. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3}/toxic_classifier/model.py +18 -14
  6. toxic_comment_classifier-0.2.3/toxic_classifier/utils.py +11 -0
  7. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3/toxic_comment_classifier.egg-info}/PKG-INFO +10 -2
  8. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3}/toxic_comment_classifier.egg-info/SOURCES.txt +1 -1
  9. toxic_comment_classifier-0.2.1/toxic_classifier/utils.py +0 -10
  10. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3}/LICENSE.txt +0 -0
  11. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3}/MANIFEST.in +0 -0
  12. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3}/setup.cfg +0 -0
  13. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3}/toxic_classifier/__init__.py +0 -0
  14. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3}/toxic_classifier/model/tokenizer.pickle +0 -0
  15. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3}/toxic_comment_classifier.egg-info/dependency_links.txt +0 -0
  16. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3}/toxic_comment_classifier.egg-info/requires.txt +0 -0
  17. {toxic_comment_classifier-0.2.1 → toxic_comment_classifier-0.2.3}/toxic_comment_classifier.egg-info/top_level.txt +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toxic_comment_classifier
3
- Version: 0.2.1
4
- Summary: A Python library for classifying toxic comments using deep learning.
3
+ Version: 0.2.3
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
7
7
  Project-URL: Homepage, https://github.com/irfanalidv/toxic_comment_classifier
@@ -17,6 +17,14 @@ Requires-Dist: tensorflow
17
17
  Requires-Dist: pandas
18
18
  Requires-Dist: scikit-learn
19
19
 
20
+ # Toxic Comment Classifier
21
+
22
+ [![GitHub license](https://img.shields.io/github/license/irfanalidv/toxic_comment_classifier)](https://github.com/irfanalidv/toxic_comment_classifier/blob/main/LICENSE)
23
+ [![Python version](https://img.shields.io/badge/python-3.6%2B-blue.svg)](https://pypi.org/project/toxic-comment-classifier/)
24
+ [![PyPI version](https://badge.fury.io/py/toxic-comment-classifier.svg)](https://pypi.org/project/toxic-comment-classifier/)
25
+ [![Downloads](https://static.pepy.tech/badge/toxic-comment-classifier)](https://pepy.tech/project/toxic-comment-classifier)
26
+
27
+
20
28
  ````markdown
21
29
  # Toxic Comment Classifier
22
30
 
@@ -1,3 +1,11 @@
1
+ # Toxic Comment Classifier
2
+
3
+ [![GitHub license](https://img.shields.io/github/license/irfanalidv/toxic_comment_classifier)](https://github.com/irfanalidv/toxic_comment_classifier/blob/main/LICENSE)
4
+ [![Python version](https://img.shields.io/badge/python-3.6%2B-blue.svg)](https://pypi.org/project/toxic-comment-classifier/)
5
+ [![PyPI version](https://badge.fury.io/py/toxic-comment-classifier.svg)](https://pypi.org/project/toxic-comment-classifier/)
6
+ [![Downloads](https://static.pepy.tech/badge/toxic-comment-classifier)](https://pepy.tech/project/toxic-comment-classifier)
7
+
8
+
1
9
  ````markdown
2
10
  # Toxic Comment Classifier
3
11
 
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "toxic_comment_classifier"
3
- version = "0.2.1"
4
- description = "A Python library for classifying toxic comments using deep learning."
3
+ version = "0.2.3"
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" }
7
7
  ]
@@ -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 Sequential
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 the tokenizer and model weights.
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
- self.model = Sequential([
31
- Embedding(input_dim=VOCAB_SIZE, output_dim=EMBEDDING_DIM, input_length=MAXLEN),
32
- LSTM(64, return_sequences=False),
33
- Dense(len(LIST_CLASSES), activation="sigmoid")
34
- ])
35
-
36
- # Load weights only
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,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toxic_comment_classifier
3
- Version: 0.2.1
4
- Summary: A Python library for classifying toxic comments using deep learning.
3
+ Version: 0.2.3
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
7
7
  Project-URL: Homepage, https://github.com/irfanalidv/toxic_comment_classifier
@@ -17,6 +17,14 @@ Requires-Dist: tensorflow
17
17
  Requires-Dist: pandas
18
18
  Requires-Dist: scikit-learn
19
19
 
20
+ # Toxic Comment Classifier
21
+
22
+ [![GitHub license](https://img.shields.io/github/license/irfanalidv/toxic_comment_classifier)](https://github.com/irfanalidv/toxic_comment_classifier/blob/main/LICENSE)
23
+ [![Python version](https://img.shields.io/badge/python-3.6%2B-blue.svg)](https://pypi.org/project/toxic-comment-classifier/)
24
+ [![PyPI version](https://badge.fury.io/py/toxic-comment-classifier.svg)](https://pypi.org/project/toxic-comment-classifier/)
25
+ [![Downloads](https://static.pepy.tech/badge/toxic-comment-classifier)](https://pepy.tech/project/toxic-comment-classifier)
26
+
27
+
20
28
  ````markdown
21
29
  # Toxic Comment Classifier
22
30
 
@@ -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()