toxic-comment-classifier 0.1.0__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.
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: toxic_comment_classifier
3
+ Version: 0.1.0
4
+ Summary: A Python library for classifying toxic comments using deep learning.
5
+ Author-email: Md Irfan Ali <irfanali29@hotmail.com>
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: numpy
13
+ Requires-Dist: tensorflow
14
+ Requires-Dist: pandas
15
+ Requires-Dist: scikit-learn
16
+
17
+ # toxic_comment_classifier
18
+
19
+ # Toxic Comment Classifier
20
+
21
+ A Python library for classifying toxic comments using deep learning.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install toxic_comment_classifier
27
+ ```
@@ -0,0 +1,11 @@
1
+ # toxic_comment_classifier
2
+
3
+ # Toxic Comment Classifier
4
+
5
+ A Python library for classifying toxic comments using deep learning.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install toxic_comment_classifier
11
+ ```
@@ -0,0 +1,28 @@
1
+ [project]
2
+ name = "toxic_comment_classifier"
3
+ version = "0.1.0"
4
+ description = "A Python library for classifying toxic comments using deep learning."
5
+ authors = [
6
+ { name = "Md Irfan Ali", email = "irfanali29@hotmail.com" }
7
+ ]
8
+ license = { text = "MIT" } # ← Use table again to avoid license-expression injection
9
+ readme = "README.md"
10
+ requires-python = ">=3.6"
11
+ dependencies = [
12
+ "numpy",
13
+ "tensorflow",
14
+ "pandas",
15
+ "scikit-learn"
16
+ ]
17
+ classifiers = [
18
+ "Programming Language :: Python :: 3",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Operating System :: OS Independent"
21
+ ]
22
+
23
+ [build-system]
24
+ requires = ["setuptools>=61.0", "wheel"]
25
+ build-backend = "setuptools.build_meta"
26
+
27
+ [tool.setuptools]
28
+ license-files = [] # ← Prevent LICENSE.txt from being injected
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ from .model import ToxicCommentClassifier
@@ -0,0 +1,45 @@
1
+ import os
2
+ import pickle
3
+ import numpy as np
4
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
5
+ from tensorflow.keras.models import load_model
6
+
7
+ # === Constants ===
8
+ MAXLEN = 100
9
+ LIST_CLASSES = ["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"]
10
+
11
+
12
+ # === Model Class ===
13
+ class ToxicCommentClassifier:
14
+ def __init__(self):
15
+ """
16
+ Initializes the classifier by loading the model and tokenizer.
17
+ The model files are stored inside the 'models/' directory.
18
+ """
19
+ base_path = os.path.dirname(os.path.abspath(__file__)) # Get package directory
20
+ model_path = os.path.join(base_path, "models", "model.h5")
21
+ tokenizer_path = os.path.join(base_path, "models", "tokenizer.pickle")
22
+
23
+ # Load Tokenizer
24
+ with open(tokenizer_path, "rb") as handle:
25
+ self.tokenizer = pickle.load(handle)
26
+
27
+ # Load Model
28
+ self.model = load_model(model_path)
29
+
30
+ def classify(self, text: str) -> dict:
31
+ """
32
+ Classifies a given text and returns toxicity scores.
33
+
34
+ :param text: Input text to classify
35
+ :return: Dictionary with toxicity scores
36
+ """
37
+ # Preprocess text
38
+ seq = self.tokenizer.texts_to_sequences([text])
39
+ padded = pad_sequences(seq, maxlen=MAXLEN)
40
+
41
+ # Predict toxicity scores
42
+ preds = self.model.predict(padded)[0]
43
+
44
+ # Return results as a dictionary
45
+ return {LIST_CLASSES[i]: float(preds[i]) for i in range(len(LIST_CLASSES))}
@@ -0,0 +1,13 @@
1
+ import re
2
+
3
+
4
+ def clean_text(text: str) -> str:
5
+ """
6
+ Cleans text by removing special characters and multiple spaces.
7
+
8
+ :param text: Raw text
9
+ :return: Cleaned text
10
+ """
11
+ text = re.sub(r"\s+", " ", text) # Remove extra spaces
12
+ text = re.sub(r"[^a-zA-Z0-9!?.,]", " ", text) # Remove special chars
13
+ return text.strip()
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: toxic_comment_classifier
3
+ Version: 0.1.0
4
+ Summary: A Python library for classifying toxic comments using deep learning.
5
+ Author-email: Md Irfan Ali <irfanali29@hotmail.com>
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: numpy
13
+ Requires-Dist: tensorflow
14
+ Requires-Dist: pandas
15
+ Requires-Dist: scikit-learn
16
+
17
+ # toxic_comment_classifier
18
+
19
+ # Toxic Comment Classifier
20
+
21
+ A Python library for classifying toxic comments using deep learning.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install toxic_comment_classifier
27
+ ```
@@ -0,0 +1,10 @@
1
+ README.md
2
+ pyproject.toml
3
+ toxic_classifier/__init__.py
4
+ toxic_classifier/model.py
5
+ toxic_classifier/utils.py
6
+ toxic_comment_classifier.egg-info/PKG-INFO
7
+ toxic_comment_classifier.egg-info/SOURCES.txt
8
+ toxic_comment_classifier.egg-info/dependency_links.txt
9
+ toxic_comment_classifier.egg-info/requires.txt
10
+ toxic_comment_classifier.egg-info/top_level.txt
@@ -0,0 +1,4 @@
1
+ numpy
2
+ tensorflow
3
+ pandas
4
+ scikit-learn