File size: 2,960 Bytes
70bc880
 
 
 
51ebe21
 
 
 
 
17f1839
70bc880
 
 
 
 
51ebe21
 
70bc880
 
 
 
 
 
 
8bf7a3f
 
 
 
 
70bc880
 
 
3022685
70bc880
 
 
 
3022685
 
70bc880
c079f78
 
 
 
51ebe21
c079f78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51ebe21
219d72f
 
 
 
 
 
 
aaf13a1
219d72f
 
 
 
 
 
 
 
 
c079f78
70bc880
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84d87a0
 
ce05d9f
 
 
70bc880
 
 
 
 
 
51ebe21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
license: apache-2.0
tags:
- generated_from_trainer
- t5
- flan
- small
- peft
- QLoRA
- cnn_dailymail
datasets:
- cnn_dailymail
model-index:
- name: QLoRA-Flan-T5-Small
  results: []
metrics:
- rouge
---

<!-- This model card has been generated automatically according to the information the Trainer had access to. You
should probably proofread and complete it, then remove this comment. -->

# QLoRA-Flan-T5-Small

This model is a fine-tuned version of [google/flan-t5-small](https://huggingface.co./google/flan-t5-small) on the cnn_dailymail dataset. It achieves the following on the test set:

- ROUGE-1: 0.3484265780526604
- ROUGE-2: 0.14343059577230782
- ROUGE-l: 0.32809541498574013

## Model description

This model was fine-tuned with the purpose of performing the task of abstractive summarization. 


## Training and evaluation data

Fine-tuned on cnn_dailymail training set
Evaluated on cnn_dailymail test set

## How to use model

1. Loading the model

```python
import torch
from peft import PeftModel, PeftConfig
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

# Load peft config for pre-trained checkpoint etc. 
peft_model_id = "emonty777/QLoRA-Flan-T5-Small"

config = PeftConfig.from_pretrained(peft_model_id)

# load base LLM model and tokenizer / runs on CPU
model = AutoModelForSeq2SeqLM.from_pretrained(config.base_model_name_or_path)
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)

# load base LLM model and tokenizer for GPU
model = AutoModelForSeq2SeqLM.from_pretrained(config.base_model_name_or_path,  load_in_8bit=True,  device_map={"":0})
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)

# Load the Lora model
model = PeftModel.from_pretrained(model, peft_model_id, device_map={"":0})
model.eval()
```
2. Generating summaries

```python
text = "Your text goes here..."

# If you want to use CPU
input_ids = tokenizer(text, return_tensors="pt", truncation=True).input_ids
# If you want to use GPU
input_ids = tokenizer(text, return_tensors="pt", truncation=True).input_ids.cuda()
# Adjust max_new_tokens based on size. This is set up for articles of text
outputs = model.generate(input_ids=input_ids, max_new_tokens=120, do_sample=False)

print(f"input sentence: {sample['article']}\n{'---'* 20}")
print(f"summary:\n{tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0]}")

```


## Training procedure

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 3e-05
- train_batch_size: 8
- eval_batch_size: 8
- seed: 42
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: linear
- num_epochs: 4

### Training results

Evaluated on full CNN Dailymail test set

- ROUGE-1: 0.3484265780526604
- ROUGE-2: 0.14343059577230782
- ROUGE-l: 0.32809541498574013

### Framework versions

- Transformers 4.27.1
- Pytorch 2.0.1+cu118
- Datasets 2.9.0
- Tokenizers 0.13.3