Skip to content

Commit 90d5ab3

Browse files
authored
Create README.md (huggingface#8761)
1 parent 29d4992 commit 90d5ab3

File tree

1 file changed

+52
-0
lines changed
  • model_cards/mrm8488/bert-small2bert-small-finetuned-cnn_daily_mail-summarization

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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-small2Bert-small Summarization with 🤗EncoderDecoder Framework
11+
12+
This model is a warm-started *BERT2BERT* ([small](https://huggingface.co/google/bert_uncased_L-4_H-512_A-8)) model fine-tuned on the *CNN/Dailymail* summarization dataset.
13+
14+
The model achieves a **17.37** 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** | **17.37** |
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-small2bert-small-finetuned-cnn_daily_mail-summarization')
34+
model = EncoderDecoderModel.from_pretrained('mrm8488/bert-small2bert-small-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;">&hearts;</span> in Spain

0 commit comments

Comments
 (0)