Commit ·
09d8291
1
Parent(s): 4962fe3
updated README.md
Browse files
README.md
CHANGED
|
@@ -44,5 +44,40 @@ The model was tested on **991** college‑email samples. Below are the per‑cla
|
|
| 44 |
|
| 45 |
## Usage
|
| 46 |
|
|
|
|
| 47 |
```bash
|
| 48 |
-
pip install tensorflow sentence-transformers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
## Usage
|
| 46 |
|
| 47 |
+
### 1. Install dependencies
|
| 48 |
```bash
|
| 49 |
+
pip install tensorflow sentence-transformers huggingface_hub
|
| 50 |
+
```
|
| 51 |
+
### 2. Load the model & embedder
|
| 52 |
+
``` python
|
| 53 |
+
from sentence_transformers import SentenceTransformer
|
| 54 |
+
import tensorflow as tf
|
| 55 |
+
from huggingface_hub import hf_hub_download
|
| 56 |
+
|
| 57 |
+
# 1) Load SBERT embedder
|
| 58 |
+
embedder = SentenceTransformer("all-MiniLM-L6-v2")
|
| 59 |
+
|
| 60 |
+
# 2) Load your fine‑tuned classifier
|
| 61 |
+
model_file = hf_hub_download(
|
| 62 |
+
repo_id="skgezhil2005/email_classifier",
|
| 63 |
+
filename="model_v2.keras" #replace with your model file
|
| 64 |
+
)
|
| 65 |
+
model = tf.keras.models.load_model(model_file)
|
| 66 |
+
|
| 67 |
+
# 3) Define label names (in the same order used during training)
|
| 68 |
+
labels = ["Academics", "Clubs", "Internships", "Others", "Talks"]
|
| 69 |
+
```
|
| 70 |
+
### 3. Inference Helper
|
| 71 |
+
|
| 72 |
+
``` python
|
| 73 |
+
def classify_email(text: str) -> str:
|
| 74 |
+
# Compute a 1×384 SBERT embedding
|
| 75 |
+
emb = embedder.encode(text, convert_to_tensor=False)
|
| 76 |
+
emb = emb.reshape(1, -1)
|
| 77 |
+
# Predict probabilities and pick the highest‐scoring class
|
| 78 |
+
prediction = model.predict(emb)
|
| 79 |
+
pred_idx = int(np.argmax(prediction[0]))
|
| 80 |
+
|
| 81 |
+
return labels[pred_idx]
|
| 82 |
+
|
| 83 |
+
```
|