license: mit
library_name: peft
datasets:
- samsum
language:
- en
tags:
- summarization
- text-generation
- toxicity-reduction
- reinforcement-learning
widget:
- text: >-
Summarize the following Conversation: Kate: Good morning. Kai: Hi! How
official! Kate: I wrote it at 4am Kai: I've noticed. Why? Kate: I had to
get up early to catch the bus to the airport Kai: Where are you flying?
Kate: To Antwerp! I'm fed up with Cambridge Kai: poor thing. Why? Kate:
Just a stupid, elitist place without a soul. Or with a soul made of money.
Kai: Try to rest a bit in Belgium, do not work too much. Kate: I have to
work, but at least not in this soulless place. Kai: When are you coming
back? Kate: I have to see my supervisor on Monday <unk> Kai: not too long
a break Kate: Still better than nothing. Summary:
example_title: Summarization Example 1
- text: >-
Summarize the following Conversation: Dean: I feel sick Scott: hungover?
Dean: no, like I ate something bad Scott: what did you eat yesterday?
Dean: breakfast at Coffee Lovers' Scott: this is a rather safe place Dean:
and Chinese from TaoTao for dinner Scott: now we have a suspect Summary:
example_title: Summarization Example 2
pipeline_tag: text2text-generation
inference:
parameters:
max_new_tokens: 256
repetition_penalty: 2.5
top_p: 0.95
top_k: 50
temperature: 0.7
num_beams: 3
no_repeat_ngram_size: 2
num_return_sequences: 1
do_sample: true
Flan-T5 (base-sized) Dialogue Summarization with reduced toxicity using RLAIF
This model is a fine-tuned Flan-T5 model on the SAMSUM dataset.
The Base Model(Flan-T5) is based on Pre-trained T5 (Raffel et al., 2020) and fine-tuned with instructions for better zero-shot and few-shot performance
Our Model is fine-tuned specifically on a single downstream task of Dialogue Summarization on the above mentioned dataset with a primary objective of reduced toxicity while generating summaries.
Model description
This Model has the same architecture and Parameters as its base model. Please refer to this link to know more about the model details.
Intended Use & Limitations
This model is intended to summarize the given dialogue in a way that outputs the less toxic summary even when we pass a dialogue that contains toxic phrases or words.
I've fine-tuned the model with an instruction of Summarize the following Conversation:
that's prepended at the start of each dialogue followed by Summary:
keyword at the end that indicates the start of summary.
Note: The model is primarily trained with an objective of reduced toxicity in the outputs, we can sometimes expect relatively short outputs that might sometimes(rarely) miss the important message in the dialogue but still being true to its primary goal.
Usage
You can use this model directly to get the summaries:
import torch
from peft import PeftModel, PeftConfig
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
# Load peft config for pre-trained checkpoint etc.
peft_model_id = "DeathReaper0965/flan-t5-samsum-lora-RLAIF-detoxified"
config = PeftConfig.from_pretrained(peft_model_id)
# load base LLM model and tokenizer
model = AutoModelForSeq2SeqLM.from_pretrained(config.base_model_name_or_path, device_map='auto') # If required, you can add `load_in_8bit=True` for loading model in 8-bit
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
# Load the Lora model
model = PeftModel.from_pretrained(model, peft_model_id, device_map='auto')
input_ids = tokenizer.encode(
"Summarize the following Conversation: Dean: I feel sick Scott: hungover? Dean: no, like I ate something bad Scott: what did you eat yesterday? Dean: breakfast at Coffee Lovers' Scott: this is a rather safe place Dean: and Chinese from TaoTao for dinner Scott: now we have a suspect Summary:",
return_tensors="pt"
).to("cuda" if torch.cuda.is_available() else "cpu")
summary = model.generate(
input_ids = input_ids,
max_new_tokens=256,
repetition_penalty=2.5,
top_p=0.95,
top_k=50,
temperature=0.7,
no_repeat_ngram_size=2,
num_return_sequences=1,
do_sample=True)
output = tokenizer.batch_decode(summary, skip_special_tokens=True)
###########OUTPUT###########
# "Dean ate breakfast at Coffee Lovers' yesterday and Chinese from TaoTao for dinner."
Designed and Developed with ♥ by Praneet | LinkedIn | GitHub