Views
No views yet
1# install package
2!pip install transformers[torch] -U
3!pip install -q -U peft
4
5import torch
6from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
7from huggingface_hub import notebook_login
8
9# login to hugging_face
10notebook_login() # use model on GPU
11device = "cuda" if torch.cuda.is_available() else "cpu"
12
13# load base model
14model_name = "knkarthick/MEETING_SUMMARY"
15model = AutoModelForSeq2SeqLM.from_pretrained(model_name).to(device)
16tokenizer = AutoTokenizer.from_pretrained(model_name)
17
18# load trained adapter
19adapter_id = "Joaaaane/510_ABW_LoRaAdapter_PostDisasterConv"
20model.load_adapter(adapter_id) # set the model to evaluation mode
21model.eval()
22input_text = """
23PA: Hello, I need urgent housing help as a refugee from Ukraine. Can you assist?
24agent: Hello, thank you for reaching out to the Red Cross. We’re here to help with housing.
25agent: Have you registered with the local authorities yet?
26PA: Yes, but they mentioned delays, and we need something soon. It's urgent.
27agent: We have temporary shelters available. How many are with you, and are there any special needs?
28PA: It's just me and my elderly mother; we need accessible housing.
29agent: We can arrange for accessible temporary shelter. I’ll expedite your request and aim to place you within a few days.
30agent: I'll also connect you with a Ukrainian-speaking volunteer to help with your paperwork and make your mother more comfortable.
31PA: Thank you so much. This help means a lot to us right now.
32agent: You're welcome! Expect a call from our volunteer by tomorrow. We’ll make sure you both are settled quickly.
33PA: Thanks again. Looking forward to resolving this soon.
34"""
35
36# tokenized inputs
37inputs = tokenizer(input_text, return_tensors="pt", max_length=1024, truncation=True).to(device)
38# generate summary tokens
39outputs = model.generate(inputs['input_ids'], max_length=62, num_beams=5, early_stopping=True)
40# decode tokens
41summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
42
43print("Generated Summary:", summary)| Metric | Before LoRA | After LoRA |
|---|---|---|
| ROUGE 1 | 22.50 | 28.30 |
| ROUGE 2 | 4.96 | 8.64 |
| ROUGE L | 17.24 | 22.50 |