Views
No views yet
Lora config : LoraConfig(
r=16, # the rank of the adapter, the lower the fewer parameters you'll need to train
lora_alpha=32, # multiplier, usually 2*r
bias="none", # BEWARE: training biases *modifies* base model's behavior
lora_dropout=0.05,
task_type="QUESTION_ANS",
target_modules='all-linear',
)from transformers import pipeline
QS = "I need colors,sizes and cutomer riviews for product id 100986 for the date between 01/02/2020 to 11/11/2025 and make a comparative summary"
try:
print("Query :\n", QS)
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": QS},
]
outputs = pipe(messages, max_new_tokens=2024, do_sample=True, temperature=0.1, top_k=50, top_p=0.95, num_beams=1)
print("\nAssistant answer :: \n", outputs[0]["generated_text"][-1]['content'])
res = outputs[0]["generated_text"][-1]['content']
actual_res = res.split("Response:")[-1].split("can be mapped to")
for r in actual_res:
print("\n reasoning map >> ", r.split("::")[0])
# status, json_obj = json_match(res=res)
# print("\n\n JSON SCHEMA \n", json_obj)
JS = res.split("JSON response will be ")[-1]
JS = '"'+JS+'"'
new_json = json.loads(JS)
print("JSON RES :", new_json)
except:
traceback.print_exc()Since user query includes some parameters as following product id:100986 can be mapped to product_id:100986:: user wants to know some values as following ['colors','sizes', 'cutomer reviews'].
User also mentioned the start time 01/02/2020 and end time 11/11/2025 so start_time and end_time will be included in JSON response.
and corresponding JSON response will be {'params': [{'product_id': '100986'}],'start_time': '01/02/2020', 'end_time': '11/11/2025', 'variable': ['colors','sizes', 'cutomer reviews']}{'params': [{'product_id': '100986'}],'start_time': '01/02/2020', 'end_time': '11/11/2025', 'variable': ['colors','sizes', 'cutomer reviews']}parameters: (To be used to filter DB to have desired variables/values)
- 'timestamp'
- 'brand'
- 'product_id'
- 'product_name'
- 'category_name'
- 'free_returns'
- 'final_price'
- 'sku'
- 'rating'
- 'discount'
- 'unit_price'
- 'initial_price
Variable/values : (Desired variables against given)
- 'specifications'
- 'currency'
- 'top reviews'
- 'rating stars'
- 'review count'
- 'description'
- 'customer reviews'
- 'final price'
- 'sku'
- 'rating'
- ' sizes'
- 'discount'
- 'rating'
- 'unit price'
- 'colors'
- 'initial price'
1.Desired variables (Ex: I need colors,sizes and cutomer reviews)
2.Given parameters ( Ex : for product id 100986 and brand ZARA)
3.Date (Ex : between 01/02/2020 to 11/11/2025)
4.Your Extended promptprompt = "provide available data for brand ZARA and rating 4.5"
LLM answer:
" Since user query includes some parameters as following brand:ZARA can be mapped to brand:ZARA::rating:4.5 can be mapped to rating:4.5::
Corresponding JSON response will be {'params': [{'brand': 'ZARA', 'rating': '4.5'}]}"
Fintered JSON:
{'params': [{'brand': 'ZARA', 'rating': '4.5'}]}prompt = "can you tell me something about JAPAN?"
LLM answer:
" This conversation is out of scope for this LLM and corresponding JSON response will be {'topic': 'out of scope'}"
If you desire to have only single value then use a comma(",")
Example:
prompt = "get all unit price, for product id 002322827"
LLM answer:
"Since user query includes some parameters as following product id:002322827 can be mapped to product_id:002322827::
user wants to know some values as following ['unit price'].
Corresponding JSON response will be {'params': [{'product_id': '002322827'}], 'variable': ['unit price']}"
Model is somewhat biased to following starting words for quering values
- "give me report on"
- "report on"
- "I need"
- "get"
- "I want"