wants to use UAE-LARGE -V1 instead of all-MiniLM-L6-v2 . CODE is given below please correct it
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from transformers import pipeline
import torch
import base64
import textwrap
from langchain.embeddings import SentenceTransformerEmbeddings
from langchain.vectorstores import Chroma
from langchain.llms import HuggingFacePipeline
from langchain.chains import RetrievalQA
from constants import CHROMA_SETTINGS
checkpoint = "LaMini-T5-738M"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
base_model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint, device_map='cpu', torch_dtype=torch.float32) #device_map=cuda/cpu
@st
.cache_resource
def llm_pipeline():
pipe = pipeline(
'text2text-generation',
model = base_model,
tokenizer = tokenizer,
max_length = 256,
do_sample=True,
temperature = 0.3,
top_p = 0.95
)
local_llm = HuggingFacePipeline(pipeline=pipe)
return local_llm
@st
.cache_resource
def qa_llm():
llm = llm_pipeline()
embeddings = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
db = Chroma(persist_directory="db", embedding_function=embeddings, client_settings=CHROMA_SETTINGS)
retriever = db.as_retriever()
qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever, return_source_documents=True)
return qa
def process_answer(instruction):
response = ''
instruction = instruction
qa = qa_llm()
generated_text = qa(instruction)
answer = generated_text['result']
return answer,generated_text
def main():
st.title("Search From your PDF📄")
with st.expander("About the App"):
st.markdown(
"""
This is a Generative AI powered Question and Answering app that responds to questions about your PDF File.
"""
)
question = st.text_area("Enter your Question")
if st.button("Ask"):
st.info("Your Question: " + question)
st.info("Your Answer")
answer, metadata = process_answer(question)
st.write(answer)
st.write(metadata)
if name == 'main':
main()
hi @ABHINAYY , thanks for following our work!
Currently, UAE cannot be used in langchain.
But we have created a PR to support UAE in langchain: https://github.com/langchain-ai/langchain/pull/15134.
When it is merged, I will inform you.
Stay tune:)
Hi @SeanLee97 How to finetune UAE-LARGE -V1? any tutorial? thanks
@pribadihcr
Due to time limitations, we haven't provided a tutorial yet.
You can follow this script to fine-tune your model: https://github.com/SeanLee97/AnglE/blob/angle-bellm/examples/UAE/train.py
There are two steps:
- you need to prepare your data into
jsonl
, as follows:
{"text1": "here is text1", "text2": "here is text2", "label": 0/1}
{"text1": "here is text1", "text2": "here is text2", "label": 0/1}
- start to fine-tune your model, as follows:
CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --nproc_per_node=4 --master_port=1234 train.py \
--train_path your_custom_data.jsonl --save_dir ./ckpts/your-custom-model \
--model_name WhereIsAI/UAE-Large-V1 \
--w2 35 --learning_rate 5e-8 --maxlen 128 \
--epochs 2 \
--batch_size 32 \
--apply_lora 0 \
--save_steps 1000 --seed -1 --gradient_accumulation_steps 4 --fp16 1
Please set a small learning_rate
if you fine-tune based on WhereIsAI/UAE-Large-V1
@pribadihcr Due to time limitations, we haven't provided a tutorial yet.
You can follow this script to fine-tune your model: https://github.com/SeanLee97/AnglE/blob/angle-bellm/examples/UAE/train.pyThere are two steps:
- you need to prepare your data into
jsonl
, as follows:{"text1": "here is text1", "text2": "here is text2", "label": 0/1} {"text1": "here is text1", "text2": "here is text2", "label": 0/1}
- start to fine-tune your model, as follows:
CUDA_VISIBLE_DEVICES=0,1,2,3 torchrun --nproc_per_node=4 --master_port=1234 train.py \ --train_path your_custom_data.jsonl --save_dir ./ckpts/your-custom-model \ --model_name WhereIsAI/UAE-Large-V1 \ --w2 35 --learning_rate 5e-8 --maxlen 128 \ --epochs 2 \ --batch_size 32 \ --apply_lora 0 \ --save_steps 1000 --seed -1 --gradient_accumulation_steps 4 --fp16 1
Please set a small
learning_rate
if you fine-tune based onWhereIsAI/UAE-Large-V1
@pribadihcr
BTW, if you would like to fine-tune a retrieval-based model, please specify --prompt "Represent this sentence for searching relevant passages: {text}"