Commit
•
6c26a59
1
Parent(s):
ddb0f47
Upload 8 files
Browse files- README.md +52 -0
- config.json +141 -0
- index.gitattributes +8 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +1 -0
- tokenizer_config.json +1 -0
- training_args.bin +3 -0
- vocab.txt +0 -0
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
|
config.json
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"EncoderDecoderModel"
|
4 |
+
],
|
5 |
+
"decoder": {
|
6 |
+
"_name_or_path": "google/bert_uncased_L-4_H-256_A-4",
|
7 |
+
"add_cross_attention": true,
|
8 |
+
"architectures": null,
|
9 |
+
"attention_probs_dropout_prob": 0.1,
|
10 |
+
"bad_words_ids": null,
|
11 |
+
"bos_token_id": null,
|
12 |
+
"chunk_size_feed_forward": 0,
|
13 |
+
"decoder_start_token_id": null,
|
14 |
+
"do_sample": false,
|
15 |
+
"early_stopping": false,
|
16 |
+
"eos_token_id": null,
|
17 |
+
"finetuning_task": null,
|
18 |
+
"gradient_checkpointing": false,
|
19 |
+
"hidden_act": "gelu",
|
20 |
+
"hidden_dropout_prob": 0.1,
|
21 |
+
"hidden_size": 256,
|
22 |
+
"id2label": {
|
23 |
+
"0": "LABEL_0",
|
24 |
+
"1": "LABEL_1"
|
25 |
+
},
|
26 |
+
"initializer_range": 0.02,
|
27 |
+
"intermediate_size": 1024,
|
28 |
+
"is_decoder": true,
|
29 |
+
"is_encoder_decoder": false,
|
30 |
+
"label2id": {
|
31 |
+
"LABEL_0": 0,
|
32 |
+
"LABEL_1": 1
|
33 |
+
},
|
34 |
+
"layer_norm_eps": 1e-12,
|
35 |
+
"length_penalty": 1.0,
|
36 |
+
"max_length": 20,
|
37 |
+
"max_position_embeddings": 512,
|
38 |
+
"min_length": 0,
|
39 |
+
"model_type": "bert",
|
40 |
+
"no_repeat_ngram_size": 0,
|
41 |
+
"num_attention_heads": 4,
|
42 |
+
"num_beams": 1,
|
43 |
+
"num_hidden_layers": 4,
|
44 |
+
"num_return_sequences": 1,
|
45 |
+
"output_attentions": false,
|
46 |
+
"output_hidden_states": false,
|
47 |
+
"pad_token_id": 0,
|
48 |
+
"prefix": null,
|
49 |
+
"pruned_heads": {},
|
50 |
+
"repetition_penalty": 1.0,
|
51 |
+
"return_dict": true,
|
52 |
+
"sep_token_id": null,
|
53 |
+
"task_specific_params": null,
|
54 |
+
"temperature": 1.0,
|
55 |
+
"tie_encoder_decoder": false,
|
56 |
+
"tie_word_embeddings": true,
|
57 |
+
"tokenizer_class": null,
|
58 |
+
"top_k": 50,
|
59 |
+
"top_p": 1.0,
|
60 |
+
"torchscript": false,
|
61 |
+
"type_vocab_size": 2,
|
62 |
+
"use_bfloat16": false,
|
63 |
+
"use_cache": true,
|
64 |
+
"vocab_size": 30522,
|
65 |
+
"xla_device": null
|
66 |
+
},
|
67 |
+
"decoder_start_token_id": 101,
|
68 |
+
"early_stopping": true,
|
69 |
+
"encoder": {
|
70 |
+
"_name_or_path": "google/bert_uncased_L-4_H-256_A-4",
|
71 |
+
"add_cross_attention": false,
|
72 |
+
"architectures": null,
|
73 |
+
"attention_probs_dropout_prob": 0.1,
|
74 |
+
"bad_words_ids": null,
|
75 |
+
"bos_token_id": null,
|
76 |
+
"chunk_size_feed_forward": 0,
|
77 |
+
"decoder_start_token_id": null,
|
78 |
+
"do_sample": false,
|
79 |
+
"early_stopping": false,
|
80 |
+
"eos_token_id": null,
|
81 |
+
"finetuning_task": null,
|
82 |
+
"gradient_checkpointing": false,
|
83 |
+
"hidden_act": "gelu",
|
84 |
+
"hidden_dropout_prob": 0.1,
|
85 |
+
"hidden_size": 256,
|
86 |
+
"id2label": {
|
87 |
+
"0": "LABEL_0",
|
88 |
+
"1": "LABEL_1"
|
89 |
+
},
|
90 |
+
"initializer_range": 0.02,
|
91 |
+
"intermediate_size": 1024,
|
92 |
+
"is_decoder": false,
|
93 |
+
"is_encoder_decoder": false,
|
94 |
+
"label2id": {
|
95 |
+
"LABEL_0": 0,
|
96 |
+
"LABEL_1": 1
|
97 |
+
},
|
98 |
+
"layer_norm_eps": 1e-12,
|
99 |
+
"length_penalty": 1.0,
|
100 |
+
"max_length": 20,
|
101 |
+
"max_position_embeddings": 512,
|
102 |
+
"min_length": 0,
|
103 |
+
"model_type": "bert",
|
104 |
+
"no_repeat_ngram_size": 0,
|
105 |
+
"num_attention_heads": 4,
|
106 |
+
"num_beams": 1,
|
107 |
+
"num_hidden_layers": 4,
|
108 |
+
"num_return_sequences": 1,
|
109 |
+
"output_attentions": false,
|
110 |
+
"output_hidden_states": false,
|
111 |
+
"pad_token_id": 0,
|
112 |
+
"prefix": null,
|
113 |
+
"pruned_heads": {},
|
114 |
+
"repetition_penalty": 1.0,
|
115 |
+
"return_dict": true,
|
116 |
+
"sep_token_id": null,
|
117 |
+
"task_specific_params": null,
|
118 |
+
"temperature": 1.0,
|
119 |
+
"tie_encoder_decoder": false,
|
120 |
+
"tie_word_embeddings": true,
|
121 |
+
"tokenizer_class": null,
|
122 |
+
"top_k": 50,
|
123 |
+
"top_p": 1.0,
|
124 |
+
"torchscript": false,
|
125 |
+
"type_vocab_size": 2,
|
126 |
+
"use_bfloat16": false,
|
127 |
+
"use_cache": true,
|
128 |
+
"vocab_size": 30522,
|
129 |
+
"xla_device": null
|
130 |
+
},
|
131 |
+
"eos_token_id": 102,
|
132 |
+
"is_encoder_decoder": true,
|
133 |
+
"length_penalty": 2.0,
|
134 |
+
"max_length": 142,
|
135 |
+
"min_length": 56,
|
136 |
+
"model_type": "encoder-decoder",
|
137 |
+
"no_repeat_ngram_size": 3,
|
138 |
+
"num_beams": 4,
|
139 |
+
"pad_token_id": 0,
|
140 |
+
"vocab_size": 30522
|
141 |
+
}
|
index.gitattributes
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.tar.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0db6945137885092d5c2eb915204187933a460c9baffc21481e56dc7b4fad8ae
|
3 |
+
size 93795803
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"do_lower_case": true, "do_basic_tokenize": true, "never_split": null, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "special_tokens_map_file": null, "tokenizer_file": null, "name_or_path": "google/bert_uncased_L-4_H-256_A-4"}
|
training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:73fadf0a9554678334ac7069bdb38f38f6851c277253aeabbf0f54c6dd8f97d4
|
3 |
+
size 1967
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|