File size: 4,000 Bytes
a0cca4a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Here's your model card based on the example you provided:  

---

# RoBERTa-Base for News Classification (FP16 Quantized)  
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.  

---

## **Model Details**  

### **Model Description**  
- **Model Type:** Transformer-based text classifier  
- **Base Model:** `roberta-base`  
- **Fine-Tuned Dataset:** AG News  
- **Maximum Sequence Length:** 512 tokens  
- **Output:** One of four news categories  
- **Task:** Text classification  
---

## **Full Model Architecture**  
```python
RobertaForSequenceClassification(
  (roberta): RobertaModel(
    (embeddings): RobertaEmbeddings(...)
    (encoder): RobertaEncoder(...)
  )
  (classifier): RobertaClassificationHead(
    (dense): Linear(in_features=768, out_features=768, bias=True)
    (dropout): Dropout(p=0.1)
    (out_proj): Linear(in_features=768, out_features=4, bias=True)
  )
)
```

---

## **Usage Instructions**  

### **Installation**  
```bash
pip install -U transformers torch
```

### **Loading the Model for Inference**  
```python
from transformers import RobertaForSequenceClassification, RobertaTokenizer
import torch

# Load the model and tokenizer
model_name = "AventIQ-AI/Roberta-Base-News-Classification"  # Update with your model ID
tokenizer = RobertaTokenizer.from_pretrained(model_name)
model = RobertaForSequenceClassification.from_pretrained(model_name)

# Move to GPU if available
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)

# Function to predict category
def predict(text):
    inputs = tokenizer(text, return_tensors="pt", padding="max_length", truncation=True, max_length=512).to(device)
    with torch.no_grad():
        outputs = model(**inputs)
    logits = outputs.logits
    predicted_class = torch.argmax(logits, dim=1).item()
    class_labels = {0: "World", 1: "Sports", 2: "Business", 3: "Science/Technology"}
    return class_labels[predicted_class]

# Example usage
custom_text = "Stock prices are rising due to global economic recovery."
predicted_label = predict(custom_text)
print(f"Predicted Category: {predicted_label}")
```

---

## **Training Details**  

### **Training Dataset**  
- **Name:** AG News  
- **Size:** 50,000 training samples, 7,600 test samples  
- **Labels:**  
  - **0:** World  
  - **1:** Sports  
  - **2:** Business  
  - **3:** Science/Technology  

---

## **Training Hyperparameters**  
### **Non-Default Hyperparameters:**  
- **per_device_train_batch_size:** 8  
- **per_device_eval_batch_size:** 8  
- **gradient_accumulation_steps:** 2 (effective batch size = 16)  
- **num_train_epochs:** 3  
- **learning_rate:** 2e-5  
- **fp16:** True (for reduced memory footprint and faster inference)  
- **weight_decay:** 0.01  
- **optimizer:** AdamW  

---

## **Model Performance**  
| Metric  | Score |  
|---------|-------|  
| Accuracy | **94.3%** |  
| F1 Score | **94.1%** |  
| Precision | **94.5%** |  
| Recall | **94.2%** |  

*(Update these values based on your actual evaluation results.)*  

---

## **Quantization Details**  
- The model has been quantized to **FP16** to reduce its size and improve inference speed.
- FP16 quantization provides a **2x reduction in memory** while maintaining similar accuracy.

---

## **Limitations & Considerations**  
- The model is **trained on AG News** and may not generalize well to **other domains** such as medical, legal, or entertainment news.
- Due to **FP16 quantization**, there might be a minor loss in precision, but inference speed is significantly improved.
- The model is **not intended for real-time misinformation detection**—it only classifies text based on its most probable category.

---