Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Here's your model card based on the example you provided:
|
2 |
+
|
3 |
+
---
|
4 |
+
|
5 |
+
# RoBERTa-Base for News Classification (FP16 Quantized)
|
6 |
+
This is a RoBERTa-Base model fine-tuned on the **AG News dataset** for text classification. It categorizes news articles into one of four classes: **World, Sports, Business, and Science/Technology**. The model has been further **quantized to FP16** for improved inference speed and reduced memory usage, making it efficient for deployment on resource-constrained environments.
|
7 |
+
|
8 |
+
---
|
9 |
+
|
10 |
+
## **Model Details**
|
11 |
+
|
12 |
+
### **Model Description**
|
13 |
+
- **Model Type:** Transformer-based text classifier
|
14 |
+
- **Base Model:** `roberta-base`
|
15 |
+
- **Fine-Tuned Dataset:** AG News
|
16 |
+
- **Maximum Sequence Length:** 512 tokens
|
17 |
+
- **Output:** One of four news categories
|
18 |
+
- **Task:** Text classification
|
19 |
+
---
|
20 |
+
|
21 |
+
## **Full Model Architecture**
|
22 |
+
```python
|
23 |
+
RobertaForSequenceClassification(
|
24 |
+
(roberta): RobertaModel(
|
25 |
+
(embeddings): RobertaEmbeddings(...)
|
26 |
+
(encoder): RobertaEncoder(...)
|
27 |
+
)
|
28 |
+
(classifier): RobertaClassificationHead(
|
29 |
+
(dense): Linear(in_features=768, out_features=768, bias=True)
|
30 |
+
(dropout): Dropout(p=0.1)
|
31 |
+
(out_proj): Linear(in_features=768, out_features=4, bias=True)
|
32 |
+
)
|
33 |
+
)
|
34 |
+
```
|
35 |
+
|
36 |
+
---
|
37 |
+
|
38 |
+
## **Usage Instructions**
|
39 |
+
|
40 |
+
### **Installation**
|
41 |
+
```bash
|
42 |
+
pip install -U transformers torch
|
43 |
+
```
|
44 |
+
|
45 |
+
### **Loading the Model for Inference**
|
46 |
+
```python
|
47 |
+
from transformers import RobertaForSequenceClassification, RobertaTokenizer
|
48 |
+
import torch
|
49 |
+
|
50 |
+
# Load the model and tokenizer
|
51 |
+
model_name = "AventIQ-AI/Roberta-Base-News-Classification" # Update with your model ID
|
52 |
+
tokenizer = RobertaTokenizer.from_pretrained(model_name)
|
53 |
+
model = RobertaForSequenceClassification.from_pretrained(model_name)
|
54 |
+
|
55 |
+
# Move to GPU if available
|
56 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
57 |
+
model.to(device)
|
58 |
+
|
59 |
+
# Function to predict category
|
60 |
+
def predict(text):
|
61 |
+
inputs = tokenizer(text, return_tensors="pt", padding="max_length", truncation=True, max_length=512).to(device)
|
62 |
+
with torch.no_grad():
|
63 |
+
outputs = model(**inputs)
|
64 |
+
logits = outputs.logits
|
65 |
+
predicted_class = torch.argmax(logits, dim=1).item()
|
66 |
+
class_labels = {0: "World", 1: "Sports", 2: "Business", 3: "Science/Technology"}
|
67 |
+
return class_labels[predicted_class]
|
68 |
+
|
69 |
+
# Example usage
|
70 |
+
custom_text = "Stock prices are rising due to global economic recovery."
|
71 |
+
predicted_label = predict(custom_text)
|
72 |
+
print(f"Predicted Category: {predicted_label}")
|
73 |
+
```
|
74 |
+
|
75 |
+
---
|
76 |
+
|
77 |
+
## **Training Details**
|
78 |
+
|
79 |
+
### **Training Dataset**
|
80 |
+
- **Name:** AG News
|
81 |
+
- **Size:** 50,000 training samples, 7,600 test samples
|
82 |
+
- **Labels:**
|
83 |
+
- **0:** World
|
84 |
+
- **1:** Sports
|
85 |
+
- **2:** Business
|
86 |
+
- **3:** Science/Technology
|
87 |
+
|
88 |
+
---
|
89 |
+
|
90 |
+
## **Training Hyperparameters**
|
91 |
+
### **Non-Default Hyperparameters:**
|
92 |
+
- **per_device_train_batch_size:** 8
|
93 |
+
- **per_device_eval_batch_size:** 8
|
94 |
+
- **gradient_accumulation_steps:** 2 (effective batch size = 16)
|
95 |
+
- **num_train_epochs:** 3
|
96 |
+
- **learning_rate:** 2e-5
|
97 |
+
- **fp16:** True (for reduced memory footprint and faster inference)
|
98 |
+
- **weight_decay:** 0.01
|
99 |
+
- **optimizer:** AdamW
|
100 |
+
|
101 |
+
---
|
102 |
+
|
103 |
+
## **Model Performance**
|
104 |
+
| Metric | Score |
|
105 |
+
|---------|-------|
|
106 |
+
| Accuracy | **94.3%** |
|
107 |
+
| F1 Score | **94.1%** |
|
108 |
+
| Precision | **94.5%** |
|
109 |
+
| Recall | **94.2%** |
|
110 |
+
|
111 |
+
*(Update these values based on your actual evaluation results.)*
|
112 |
+
|
113 |
+
---
|
114 |
+
|
115 |
+
## **Quantization Details**
|
116 |
+
- The model has been quantized to **FP16** to reduce its size and improve inference speed.
|
117 |
+
- FP16 quantization provides a **2x reduction in memory** while maintaining similar accuracy.
|
118 |
+
|
119 |
+
---
|
120 |
+
|
121 |
+
## **Limitations & Considerations**
|
122 |
+
- The model is **trained on AG News** and may not generalize well to **other domains** such as medical, legal, or entertainment news.
|
123 |
+
- Due to **FP16 quantization**, there might be a minor loss in precision, but inference speed is significantly improved.
|
124 |
+
- The model is **not intended for real-time misinformation detection**—it only classifies text based on its most probable category.
|
125 |
+
|
126 |
+
---
|