devxyasir commited on
Commit
d8d50b7
Β·
verified Β·
1 Parent(s): 9d87752

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +134 -3
README.md CHANGED
@@ -1,3 +1,134 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ tags:
6
+ - email
7
+ - spam
8
+ - spamdetection
9
+ ---
10
+
11
+ # πŸ“© Spam Detection Neural Network (PyTorch)
12
+
13
+ [![Python](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/)
14
+ [![PyTorch](https://img.shields.io/badge/pytorch-2.1-red.svg)](https://pytorch.org/)
15
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
16
+
17
+ A **simple, real-world spam detection neural network** built from scratch in **PyTorch**.
18
+ This model classifies SMS / short text messages as **Spam** or **Ham (Not Spam)**.
19
+
20
+ The project is **small, easy to understand, and perfect for learning**.
21
+ You can fork it, fine-tune it, and use it as a **starting point for your own projects**.
22
+
23
+ ---
24
+
25
+ ## 🧠 Model Overview
26
+
27
+ - **Framework:** PyTorch
28
+ - **Architecture:** Fully Connected Neural Network (MLP)
29
+ - **Input:** Bag-of-Words text vectors
30
+ - **Output:** Binary classification (Spam / Ham)
31
+ - **Training:** From scratch, small dataset (~5,500 messages)
32
+
33
+ > ⚠️ Note: The dataset is intentionally small to keep things simple.
34
+ > You are encouraged to **fork the repo, add more data, and fine-tune the model**.
35
+
36
+ ---
37
+
38
+ ## πŸ“‚ Repository Structure
39
+
40
+ ```
41
+
42
+ .
43
+ β”œβ”€β”€ spam_nn.pth # Trained PyTorch model weights
44
+ β”œβ”€β”€ vectorizer.pkl # CountVectorizer for text preprocessing
45
+ β”œβ”€β”€ model.py # Neural network architecture
46
+ β”œβ”€β”€ config.json # Model configuration
47
+ β”œβ”€β”€ inference.py # Inference / prediction script
48
+ β”œβ”€β”€ README.md # Documentation
49
+
50
+ ````
51
+
52
+ ---
53
+
54
+ ## πŸš€ Usage
55
+
56
+ ### Load Model
57
+
58
+ ```python
59
+ import torch
60
+ from model import SpamNN
61
+ import pickle
62
+
63
+ # Load model architecture + weights
64
+ model = SpamNN()
65
+ model.load_state_dict(torch.load("spam_nn.pth"))
66
+ model.eval()
67
+
68
+ # Load vectorizer
69
+ with open("vectorizer.pkl", "rb") as f:
70
+ vectorizer = pickle.load(f)
71
+ ````
72
+
73
+ ### Predict Messages
74
+
75
+ ```python
76
+ def predict(text):
77
+ vec = vectorizer.transform([text]).toarray()
78
+ vec = torch.tensor(vec, dtype=torch.float32)
79
+
80
+ with torch.no_grad():
81
+ output = model(vec)
82
+
83
+ return "Spam" if output.item() > 0.35 else "Ham"
84
+
85
+ # Example
86
+ print(predict("Congratulations! You won $1000. Click now!"))
87
+ ```
88
+
89
+ ---
90
+
91
+ ## πŸ”§ Training & Fine-Tuning
92
+
93
+ The model can be **improved and fine-tuned** by:
94
+
95
+ * Adding more data (larger SMS datasets)
96
+ * Increasing n-grams (`ngram_range=(1,2)`)
97
+ * Adjusting class weights in `BCEWithLogitsLoss`
98
+ * Training with more epochs
99
+ * Using embeddings or LSTM for contextual understanding
100
+
101
+ πŸ’‘ **Fork this repo and experiment freely**. Make it your own!
102
+
103
+ ---
104
+
105
+ ## 🌟 Support the Project
106
+
107
+ If this project is helpful:
108
+
109
+ ⭐ **Give this repository a star**
110
+ 🍴 **Fork it and improve it**
111
+ πŸ“’ **Share it with others learning PyTorch**
112
+
113
+ > Following and starring helps me keep releasing open-source projects!
114
+
115
+ ---
116
+
117
+ ## πŸ“Œ Source Code & Updates
118
+
119
+ For the **full source code, training scripts, and future updates**,
120
+ please visit the **GitHub repository** linked to this project.
121
+
122
+ ---
123
+
124
+ ## πŸ“œ License
125
+
126
+ This project is **open-source** and intended for **educational purposes**.
127
+ MIT License applies.
128
+
129
+ ---
130
+
131
+ ## πŸ€— Hugging Face Friendly
132
+
133
+ You can also **upload this model to Hugging Face Model Hub**.
134
+ Include `spam_nn.pth`, `vectorizer.pkl`, `config.json`, and `inference.py` to make it **ready for inference online**.