Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# T5-Small for News Headline Generation
|
2 |
+
This is a T5-Small model fine-tuned for generating concise and informative news topics from content summaries. It is useful for news agencies, content creators, and media professionals to generate headlines efficiently.
|
3 |
+
|
4 |
+
# Model Details
|
5 |
+
**Model Type:** Sequence-to-Sequence Transformer
|
6 |
+
**Base Model:** t5-small
|
7 |
+
**Maximum Sequence Length:** 128 tokens (input and output)
|
8 |
+
**Output:** News headlines based on input summaries
|
9 |
+
**Task:** Text Summarization (Headline Generation)
|
10 |
+
|
11 |
+
# Model Sources
|
12 |
+
**Documentation:** T5 Model Documentation
|
13 |
+
**Repository:** Hugging Face Model Hub
|
14 |
+
**Hugging Face Model:** Available on Hugging Face
|
15 |
+
|
16 |
+
# Full Model Architecture
|
17 |
+
```
|
18 |
+
T5ForConditionalGeneration(
|
19 |
+
(shared): Embedding(32128, 512)
|
20 |
+
(encoder): T5Stack(
|
21 |
+
(embed_tokens): Embedding(32128, 512)
|
22 |
+
(block): ModuleList(...)
|
23 |
+
(final_layer_norm): LayerNorm((512,), eps=1e-12)
|
24 |
+
(dropout): Dropout(p=0.1)
|
25 |
+
)
|
26 |
+
(decoder): T5Stack(
|
27 |
+
(embed_tokens): Embedding(32128, 512)
|
28 |
+
(block): ModuleList(...)
|
29 |
+
(final_layer_norm): LayerNorm((512,), eps=1e-12)
|
30 |
+
(dropout): Dropout(p=0.1)
|
31 |
+
)
|
32 |
+
(lm_head): Linear(in_features=512, out_features=32128, bias=False)
|
33 |
+
)
|
34 |
+
```
|
35 |
+
|
36 |
+
# Installation and Setup
|
37 |
+
```bash
|
38 |
+
pip install -U transformers torch datasets
|
39 |
+
```
|
40 |
+
|
41 |
+
# Load the Model and Run Inference
|
42 |
+
```python
|
43 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
44 |
+
import torch
|
45 |
+
|
46 |
+
# Model Name
|
47 |
+
model_name = "your_fine_tuned_model_id"
|
48 |
+
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
49 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
50 |
+
|
51 |
+
# Move model to GPU if available
|
52 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
53 |
+
model.to(device)
|
54 |
+
|
55 |
+
# Inference
|
56 |
+
news_summary = "Ministry of Education has announced a major reform in the national curriculum to enhance digital literacy among students."
|
57 |
+
inputs = tokenizer(news_summary, max_length=128, truncation=True, padding="max_length", return_tensors="pt").to(device)
|
58 |
+
outputs = model.generate(
|
59 |
+
input_ids=inputs["input_ids"],
|
60 |
+
attention_mask=inputs["attention_mask"],
|
61 |
+
max_length=20,
|
62 |
+
num_beams=5,
|
63 |
+
early_stopping=True
|
64 |
+
)
|
65 |
+
headline = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
66 |
+
print(f"Generated Headline: {headline}")
|
67 |
+
```
|
68 |
+
|
69 |
+
# Training Details
|
70 |
+
### Training Dataset
|
71 |
+
**Dataset Name:** News Headlines Dataset
|
72 |
+
**Size:** 30,000 rows
|
73 |
+
**Columns:** article_summary (input), headline (output)
|
74 |
+
|
75 |
+
# Approximate Statistics
|
76 |
+
```
|
77 |
+
article_summary:
|
78 |
+
Type: string
|
79 |
+
Min length: ~20 tokens
|
80 |
+
Mean length: ~50-60 tokens (estimated)
|
81 |
+
Max length: ~128 tokens
|
82 |
+
headline:
|
83 |
+
Type: string
|
84 |
+
Min length: ~5 tokens
|
85 |
+
Mean length: ~10-15 tokens
|
86 |
+
Max length: ~20 tokens
|
87 |
+
```
|
88 |
+
|
89 |
+
# Training Hyperparameters
|
90 |
+
- **per_device_train_batch_size:** 8
|
91 |
+
- **per_device_eval_batch_size:** 8
|
92 |
+
- **gradient_accumulation_steps:** 2
|
93 |
+
- **num_train_epochs:** 4
|
94 |
+
- **learning_rate:** 5e-5
|
95 |
+
- **fp16:** True
|
96 |
+
|
97 |
+
This model is optimized for **content topic generation**, ensuring concise, accurate, and informative outputs. 🚀
|
98 |
+
|