Notes
Notes - notes.io |
!pip install accelerate
!pip install peft
!pip install SentencePiece
!pip install langchain
!pip install bitsandbytes
import transformers
from peft import PeftModel
from transformers import pipeline
import torch
from transformers import LlamaTokenizer, LlamaForCausalLM, AutoModel, AutoModelForCausalLM, LlamaForCausalLM
from huggingface_hub import notebook_login
notebook_login()
def load_model_and_tokenizer(base_model):
model = LlamaForCausalLM.from_pretrained(
base_model,
load_in_8bit = True,
torch_dtype=torch.float16,
use_auth_token='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'
)
# Load the tokenizer
tokenizer = LlamaTokenizer.from_pretrained(base_model)
# Set tokenizer parameters
tokenizer.pad_token_id = 0 # unk. we want this to be different from the eos token
tokenizer.padding_side = "left"
return model, tokenizer
BASE_MODEL = "meta-llama/Llama-2-7b-chat-hf"
#DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
model, tokenizer = load_model_and_tokenizer(BASE_MODEL)
pipe = pipeline("text-generation",
model=model,
tokenizer= tokenizer,
torch_dtype=torch.bfloat16,
device_map="auto",
max_new_tokens = 512,
do_sample=True,
top_k=30,
num_return_sequences=1,
eos_token_id=tokenizer.eos_token_id
)
from langchain import HuggingFacePipeline
from langchain import PromptTemplate, LLMChain
llm = HuggingFacePipeline(pipeline = pipe, model_kwargs = {'temperature':1})
template = """
You are an AI assistant whose main function is to extract question and answer from a script. Meaning you would need to identify what is the question(query of customer) and resolution(answer of the same query).
now your main task is to frame the question and respective resolution as first person, not second and third person. After finding the query and reolution, you need to show it like
query : question
resolution : answer
[Additional Guidance]
Be sure to accurately identify and extract the main issue as query and resolution as answer. If the conversation contains multiple issues or resolutions, focus on most prominent issue. Ensure that the extracted text is clear and concise.
Question: {question}
Answer:
"""
prompt = PromptTemplate(template=template, input_variables=["question"])
llm_chain = LLMChain(prompt=prompt, llm=llm)
question = """Ruth asked if Manny available. He was not available. Ruth asked if she can talk to someone who is superior to Manny as she received call regarding the fire alarm issue. Ruth was connected to Manny’s superior. Ruth asked him to share the photo of the device that needs battery replacement and shared it to the number 6463976555"""
x = llm_chain.run(question)
print(x)
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team