Spaces:
Sleeping
Sleeping
Rename model_change.txt to model_change.md
Browse files
model_change.txt β model_change.md
RENAMED
|
@@ -1,50 +1,52 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
-
|
| 4 |
-
1. Faster Model
|
| 5 |
|
| 6 |
-
|
| 7 |
-
6x smaller model size = Much faster loading and inference
|
| 8 |
-
|
| 9 |
-
2. Processing Optimizations
|
| 10 |
-
|
| 11 |
-
Smaller chunks: 512 words vs 900 (faster processing)
|
| 12 |
-
Limited chunks: Max 5 chunks processed (prevents hanging on huge docs)
|
| 13 |
-
Faster tokenization: Word count instead of full tokenization for chunking
|
| 14 |
-
Reduced beam search: 2 beams instead of 4 (2x faster)
|
| 15 |
-
|
| 16 |
-
3. Smart Summarization
|
| 17 |
|
| 18 |
-
|
| 19 |
-
Skip final summary: For documents with β€2 chunks (saves time)
|
| 20 |
-
Early stopping: Enabled for faster convergence
|
| 21 |
-
Progress tracking: Shows which chunk is being processed
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
-
Try it now - it should be significantly faster! πββοΈπ¨
|
| 38 |
|
|
|
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
---
|
| 43 |
|
| 44 |
## 𧬠What is DistilBART?
|
| 45 |
|
|
|
|
|
|
|
| 46 |
| Attribute | Description |
|
| 47 |
-
|
|
| 48 |
| **Full Name** | Distilled BART |
|
| 49 |
| **Base Model** | `facebook/bart-large` |
|
| 50 |
| **Distilled By** | Hugging Face π€ |
|
|
@@ -56,43 +58,51 @@ Try it now - it should be significantly faster! πββοΈπ¨
|
|
| 56 |
## βοΈ Key Differences: BART vs DistilBART
|
| 57 |
|
| 58 |
| Feature | BART (Large) | DistilBART |
|
| 59 |
-
|
|
| 60 |
-
| Encoder Layers | 12 | 6
|
| 61 |
-
| Decoder Layers | 12 | 6
|
| 62 |
-
| Parameters |
|
| 63 |
-
| Size
|
| 64 |
-
| Speed | Slower |
|
| 65 |
-
| Performance | Very high | Slight drop (
|
| 66 |
|
| 67 |
---
|
| 68 |
|
| 69 |
## π― Use Cases
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
|
| 75 |
---
|
| 76 |
|
| 77 |
## π§ͺ Example: Summarization with DistilBART
|
| 78 |
|
| 79 |
-
You can easily use DistilBART with Hugging Face Transformers
|
| 80 |
|
| 81 |
```python
|
| 82 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 83 |
|
| 84 |
-
# Load pretrained DistilBART model
|
| 85 |
tokenizer = AutoTokenizer.from_pretrained("sshleifer/distilbart-cnn-12-6")
|
| 86 |
model = AutoModelForSeq2SeqLM.from_pretrained("sshleifer/distilbart-cnn-12-6")
|
| 87 |
|
| 88 |
-
#
|
| 89 |
ARTICLE = "The Indian Space Research Organisation (ISRO) launched a new satellite today from the Satish Dhawan Space Centre..."
|
| 90 |
|
| 91 |
# Tokenize and summarize
|
| 92 |
inputs = tokenizer([ARTICLE], max_length=1024, return_tensors="pt", truncation=True)
|
| 93 |
-
summary_ids = model.generate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
print(tokenizer.decode(summary_ids[0], skip_special_tokens=True))
|
| 95 |
-
```
|
| 96 |
|
| 97 |
---
|
| 98 |
|
|
@@ -103,13 +113,22 @@ print(tokenizer.decode(summary_ids[0], skip_special_tokens=True))
|
|
| 103 |
| `sshleifer/distilbart-cnn-12-6` | Summarization | Distilled from `facebook/bart-large-cnn` |
|
| 104 |
| `philschmid/distilbart-xsum-12-6` | Summarization (XSUM dataset) | Short, abstractive summaries |
|
| 105 |
|
| 106 |
-
|
| 107 |
|
| 108 |
---
|
| 109 |
|
| 110 |
## π Summary
|
| 111 |
|
| 112 |
-
* **DistilBART** is a
|
| 113 |
-
*
|
| 114 |
-
* Trained
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π Speed Optimized Summarization with DistilBART
|
| 2 |
|
| 3 |
+
The BART model is quite large (~1.6GB) and slow. I optimized it with a much faster, lighter model and better performance settings.
|
|
|
|
| 4 |
|
| 5 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
## π Major Speed Optimizations Applied
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
### 1. Faster Model
|
| 10 |
+
- **Switched from** `facebook/bart-large-cnn` (**~1.6GB**)
|
| 11 |
+
- **To** `sshleifer/distilbart-cnn-12-6` (**~400MB**)
|
| 12 |
+
- π₯ **6x smaller model size** = Much faster loading and inference
|
| 13 |
|
| 14 |
+
### 2. Processing Optimizations
|
| 15 |
+
- **Smaller chunks:** 512 words vs 900 (faster processing)
|
| 16 |
+
- **Limited chunks:** Max 5 chunks processed (prevents hanging on huge docs)
|
| 17 |
+
- **Faster tokenization:** Word count instead of full tokenization for chunking
|
| 18 |
+
- **Reduced beam search:** 2 beams instead of 4 (2x faster)
|
| 19 |
|
| 20 |
+
### 3. Smart Summarization
|
| 21 |
+
- **Shorter summaries:** Reduced max lengths across all modes
|
| 22 |
+
- **Skip final summary:** For documents with β€2 chunks (saves time)
|
| 23 |
+
- **Early stopping:** Enabled for faster convergence
|
| 24 |
+
- **Progress tracking:** Shows which chunk is being processed
|
| 25 |
|
| 26 |
+
### 4. Memory & Performance
|
| 27 |
+
- **Float16 precision:** Used when GPU is available (faster inference)
|
| 28 |
+
- **Optimized pipeline:** Better model loading with fallback
|
| 29 |
+
- **`optimum` library added:** For additional speed improvements
|
| 30 |
|
| 31 |
+
---
|
|
|
|
| 32 |
|
| 33 |
+
## β‘ Expected Speed Improvements
|
| 34 |
|
| 35 |
+
| Task | Before | After |
|
| 36 |
+
|-------------------|----------------------|------------------------------|
|
| 37 |
+
| Model loading | ~30+ seconds | ~10 seconds |
|
| 38 |
+
| PDF processing | Minutes | ~5β15 seconds |
|
| 39 |
+
| Memory usage | ~1.6GB | ~400MB |
|
| 40 |
+
| Overall speed | Slow | π 5β10x faster |
|
| 41 |
|
| 42 |
---
|
| 43 |
|
| 44 |
## 𧬠What is DistilBART?
|
| 45 |
|
| 46 |
+
**DistilBART** is a **compressed version of the BART model** designed to be **lighter and faster** while retaining most of BARTβs performance. Itβs the result of **model distillation**, where a smaller model (the *student*) learns from a larger one (the *teacher*), in this case, `facebook/bart-large`.
|
| 47 |
+
|
| 48 |
| Attribute | Description |
|
| 49 |
+
|------------------|---------------------------------------------------------------------|
|
| 50 |
| **Full Name** | Distilled BART |
|
| 51 |
| **Base Model** | `facebook/bart-large` |
|
| 52 |
| **Distilled By** | Hugging Face π€ |
|
|
|
|
| 58 |
## βοΈ Key Differences: BART vs DistilBART
|
| 59 |
|
| 60 |
| Feature | BART (Large) | DistilBART |
|
| 61 |
+
|----------------|--------------|------------------------|
|
| 62 |
+
| Encoder Layers | 12 | 6 |
|
| 63 |
+
| Decoder Layers | 12 | 6 |
|
| 64 |
+
| Parameters | ~406M | ~222M |
|
| 65 |
+
| Model Size | ~1.6GB | ~400MB (~55% smaller) |
|
| 66 |
+
| Speed | Slower | ~2x faster |
|
| 67 |
+
| Performance | Very high | Slight drop (~1β2%) |
|
| 68 |
|
| 69 |
---
|
| 70 |
|
| 71 |
## π― Use Cases
|
| 72 |
|
| 73 |
+
- β
**Text Summarization** (primary use case)
|
| 74 |
+
- π **Translation** (basic use)
|
| 75 |
+
- β‘ Ideal for **edge devices** or **real-time systems** where speed & size matter
|
| 76 |
|
| 77 |
---
|
| 78 |
|
| 79 |
## π§ͺ Example: Summarization with DistilBART
|
| 80 |
|
| 81 |
+
You can easily use DistilBART with Hugging Face Transformers:
|
| 82 |
|
| 83 |
```python
|
| 84 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 85 |
|
| 86 |
+
# Load pretrained DistilBART model
|
| 87 |
tokenizer = AutoTokenizer.from_pretrained("sshleifer/distilbart-cnn-12-6")
|
| 88 |
model = AutoModelForSeq2SeqLM.from_pretrained("sshleifer/distilbart-cnn-12-6")
|
| 89 |
|
| 90 |
+
# Input text
|
| 91 |
ARTICLE = "The Indian Space Research Organisation (ISRO) launched a new satellite today from the Satish Dhawan Space Centre..."
|
| 92 |
|
| 93 |
# Tokenize and summarize
|
| 94 |
inputs = tokenizer([ARTICLE], max_length=1024, return_tensors="pt", truncation=True)
|
| 95 |
+
summary_ids = model.generate(
|
| 96 |
+
inputs["input_ids"],
|
| 97 |
+
max_length=150,
|
| 98 |
+
min_length=40,
|
| 99 |
+
length_penalty=2.0,
|
| 100 |
+
num_beams=4,
|
| 101 |
+
early_stopping=True
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
print(tokenizer.decode(summary_ids[0], skip_special_tokens=True))
|
| 105 |
+
````
|
| 106 |
|
| 107 |
---
|
| 108 |
|
|
|
|
| 113 |
| `sshleifer/distilbart-cnn-12-6` | Summarization | Distilled from `facebook/bart-large-cnn` |
|
| 114 |
| `philschmid/distilbart-xsum-12-6` | Summarization (XSUM dataset) | Short, abstractive summaries |
|
| 115 |
|
| 116 |
+
π [Find more on Hugging Face Model Hub](https://huggingface.co/models?search=distilbart)
|
| 117 |
|
| 118 |
---
|
| 119 |
|
| 120 |
## π Summary
|
| 121 |
|
| 122 |
+
* π§ **DistilBART** is a distilled, faster version of **BART**
|
| 123 |
+
* π§© Ideal for summarization tasks with lower memory and latency requirements
|
| 124 |
+
* π‘ Trained using **knowledge distillation** from `facebook/bart-large`
|
| 125 |
+
* βοΈ Works well in apps needing faster performance without significant loss in quality
|
| 126 |
+
|
| 127 |
+
---
|
| 128 |
+
|
| 129 |
+
β
**Try it now β it should be significantly faster!** πββοΈπ¨
|
| 130 |
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
Thank You
|
| 134 |
+
```
|