A LoRA fine-tuned version of
facebook/bart-large-cnn for abstractive summarization of educational and lesson texts. Only ~2.08% of parameters were trained using PEFT/LoRA, resulting in a lightweight adapter on top of the already summarization-capable BART model.
1import torch
2from transformers import AutoTokenizer, BartForConditionalGeneration
3from peft import PeftModel
4
5model_id = "SeifElden2342532/children_educational_summarizer"
6
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8
9base = BartForConditionalGeneration.from_pretrained("facebook/bart-large-cnn").to("cuda")
10model = PeftModel.from_pretrained(base, model_id)
11model = model.merge_and_unload()
12model.eval()
13
14text = "your lesson text here..."
15
16inputs = tokenizer(
17 text,
18 max_length=1024,
19 truncation=True,
20 padding="max_length",
21 return_tensors="pt",
22).to("cuda")
23
24with torch.no_grad():
25 summary_ids = model.generate(
26 input_ids = inputs["input_ids"],
27 attention_mask = inputs["attention_mask"],
28 num_beams = 4,
29 max_length = 256,
30 early_stopping = True,
31 )
32
33summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
34print(summary)
Apache 2.0 — same as the base model.