Migrate model card from transformers-repo
Browse filesRead announcement at https://discuss.huggingface.co/t/announcement-all-model-cards-will-be-migrated-to-hf-co-model-repos/2755
Original file history: https://github.com/huggingface/transformers/commits/master/model_cards/mrm8488/bert-mini2bert-mini-finetuned-cnn_daily_mail-summarization/README.md
README.md
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
license: apache-2.0
|
4 |
+
datasets:
|
5 |
+
- cnn_dailymail
|
6 |
+
tags:
|
7 |
+
- summarization
|
8 |
+
---
|
9 |
+
|
10 |
+
# Bert-mini2Bert-mini Summarization with 🤗EncoderDecoder Framework
|
11 |
+
|
12 |
+
This model is a warm-started *BERT2BERT* ([mini](https://huggingface.co/google/bert_uncased_L-4_H-256_A-4)) model fine-tuned on the *CNN/Dailymail* summarization dataset.
|
13 |
+
|
14 |
+
The model achieves a **16.51** ROUGE-2 score on *CNN/Dailymail*'s test dataset.
|
15 |
+
|
16 |
+
For more details on how the model was fine-tuned, please refer to
|
17 |
+
[this](https://colab.research.google.com/drive/1Ekd5pUeCX7VOrMx94_czTkwNtLN32Uyu?usp=sharing) notebook.
|
18 |
+
|
19 |
+
## Results on test set 📝
|
20 |
+
|
21 |
+
| Metric | # Value |
|
22 |
+
| ------ | --------- |
|
23 |
+
| **ROUGE-2** | **16.51** |
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
## Model in Action 🚀
|
28 |
+
|
29 |
+
```python
|
30 |
+
from transformers import BertTokenizerFast, EncoderDecoderModel
|
31 |
+
import torch
|
32 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
33 |
+
tokenizer = BertTokenizerFast.from_pretrained('mrm8488/bert-mini2bert-mini-finetuned-cnn_daily_mail-summarization')
|
34 |
+
model = EncoderDecoderModel.from_pretrained('mrm8488/bert-mini2bert-mini-finetuned-cnn_daily_mail-summarization').to(device)
|
35 |
+
|
36 |
+
def generate_summary(text):
|
37 |
+
# cut off at BERT max length 512
|
38 |
+
inputs = tokenizer([text], padding="max_length", truncation=True, max_length=512, return_tensors="pt")
|
39 |
+
input_ids = inputs.input_ids.to(device)
|
40 |
+
attention_mask = inputs.attention_mask.to(device)
|
41 |
+
|
42 |
+
output = model.generate(input_ids, attention_mask=attention_mask)
|
43 |
+
|
44 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
45 |
+
|
46 |
+
text = "your text to be summarized here..."
|
47 |
+
generate_summary(text)
|
48 |
+
```
|
49 |
+
|
50 |
+
> Created by [Manuel Romero/@mrm8488](https://twitter.com/mrm8488) | [LinkedIn](https://www.linkedin.com/in/manuel-romero-cs/)
|
51 |
+
|
52 |
+
> Made with <span style="color: #e25555;">♥</span> in Spain
|