1DS/adapter-keyword-brand-mapping-Llama-2-7b-chat-hf-v1
Model Card for Model ID
<!-- Provide a quick summary of what the model is/does. -->
Model Details
Model Description
<!-- Provide a longer summary of what this model is. -->
- Developed by: [More Information Needed]
- Funded by [optional]: [More Information Needed]
- Shared by [optional]: [More Information Needed]
- Model type: [More Information Needed]
- Language(s) (NLP): [More Information Needed]
- License: [More Information Needed]
- Finetuned from model [optional]: [More Information Needed]
Model Sources [optional]
<!-- Provide the basic links for the model. -->
- Repository: [More Information Needed]
- Paper [optional]: [More Information Needed]
- Demo [optional]: [More Information Needed]
Infrence Function
for keyword brand
def generatebrand(keyword): # Define the roles and markers BINST, EINST = "[INST]", "[/INST]" BKW, EKW = "[KW]", "[/KW]" # Format your prompt template prompt = f"""{BINST} Extract the brand from keyword related to brand loyalty intent.{EINST}\n {BKW} {keyword} {EKW} """ # print("Prompt:") # print(prompt) encoding = tokenizer(prompt, returntensors="pt").to("cuda:0") output =model.generate(inputids=encoding.inputids, attentionmask=encoding.attentionmask, maxnewtokens=20, dosample=True, temperature=0.01, eostokenid=tokenizer.eostokenid, topk=0) #print() # Subtract the length of inputids from output to get only the model's response outputtext = tokenizer.decode(output[0, len(encoding.inputids[0]):], skipspecialtokens=False) outputtext = re.sub('\n+', '\n', outputtext) # remove excessive newline characters #print("Generated Assistant Response:") return outputtext
for keyword category
def generatecat(listcat,keyword): # Define the roles and markers BINST, EINST = "[INST]", "[/INST]" BKW, EKW = "[KW]", "[/KW]" # Format your prompt template prompt = f"""{BINST} Analyze the following keyword searched on amazon with intent of shopping. Identify the product category from the list {listcat} {EINST}\n {BKW} {keyword} {EKW} """ # print("Prompt:") # print(prompt) encoding = tokenizer(prompt, returntensors="pt").to("cuda:0") output =model.generate(inputids=encoding.inputids, attentionmask=encoding.attentionmask, maxnewtokens=20, dosample=True, temperature=0.01, eostokenid=tokenizer.eostokenid, topk=0) #print() # Subtract the length of inputids from output to get only the model's response outputtext = tokenizer.decode(output[0, len(encoding.inputids[0]):], skipspecialtokens=False) outputtext = re.sub('\n+', '\n', outputtext) # remove excessive newline characters #print("Generated Assistant Response:") return outputtext
for keyword category and brand
def generatecat(listcat,keyword): # Define the roles and markers BINST, EINST = "[INST]", "[/INST]" BKW, EKW = "[KW]", "[/KW]" # Format your prompt template prompt = f"""{BINST} Analyze the following keyword searched on amazon with intent of shopping. Identify the product category from the list {listcat}. Extract the brand from keyword related to brand loyalty intent. Output in JSON with keyword, product category, brand as keys.{EINST}\n {BKW} {keyword} {EKW} """ # print("Prompt:") # print(prompt) encoding = tokenizer(prompt, returntensors="pt").to("cuda:0") output =model.generate(inputids=encoding.inputids, attentionmask=encoding.attentionmask, maxnewtokens=20, dosample=True, temperature=0.01, eostokenid=tokenizer.eostokenid, topk=0) #print() # Subtract the length of inputids from output to get only the model's response outputtext = tokenizer.decode(output[0, len(encoding.inputids[0]):], skipspecialtokens=False) outputtext = re.sub('\n+', '\n', outputtext) # remove excessive newline characters #print("Generated Assistant Response:") return outputtext
