Downloads · 30 days
6
4% of all-time downloads
Vishal24/keyword_brand_cat_adapter_v1
keyword_brand_cat_adapter_v1 is a machine learning model from Vishal24. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft.
- 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 Informat…
Downloads · 30 days
6
4% of all-time downloads
All-time downloads
151
Public
Repo size
160 MB
Likes
0
Public
Click a slice to open those files.
.bin160 MB · 100%
From the Hugging Face model README
def generate_brand(keyword):
# Define the roles and markers
B_INST, E_INST = "[INST]", "[/INST]"
B_KW, E_KW = "[KW]", "[/KW]"
# Format your prompt template
prompt = f"""{B_INST} Extract the brand from keyword related to brand loyalty intent.{E_INST}\n
{B_KW} {keyword} {E_KW}
"""
# print("Prompt:")
# print(prompt)
encoding = tokenizer(prompt, return_tensors="pt").to("cuda:0")
output =model.generate(input_ids=encoding.input_ids,
attention_mask=encoding.attention_mask,
max_new_tokens=20,
do_sample=True,
temperature=0.01,
eos_token_id=tokenizer.eos_token_id,
top_k=0)
#print()
# Subtract the length of input_ids from output to get only the model's response
output_text = tokenizer.decode(output[0, len(encoding.input_ids[0]):], skip_special_tokens=False)
output_text = re.sub('\n+', '\n', output_text) # remove excessive newline characters
#print("Generated Assistant Response:")
return output_text
def generate_cat(list_cat,keyword):
# Define the roles and markers
B_INST, E_INST = "[INST]", "[/INST]"
B_KW, E_KW = "[KW]", "[/KW]"
# Format your prompt template
prompt = f"""{B_INST} Analyze the following keyword searched on amazon with intent of shopping. Identify the product category from the list {list_cat} {E_INST}\n
{B_KW} {keyword} {E_KW}
"""
# print("Prompt:")
# print(prompt)
encoding = tokenizer(prompt, return_tensors="pt").to("cuda:0")
output =model.generate(input_ids=encoding.input_ids,
attention_mask=encoding.attention_mask,
max_new_tokens=20,
do_sample=True,
temperature=0.01,
eos_token_id=tokenizer.eos_token_id,
top_k=0)
#print()
# Subtract the length of input_ids from output to get only the model's response
output_text = tokenizer.decode(output[0, len(encoding.input_ids[0]):], skip_special_tokens=False)
output_text = re.sub('\n+', '\n', output_text) # remove excessive newline characters
#print("Generated Assistant Response:")
return output_text
def generate_cat(list_cat,keyword):
# Define the roles and markers
B_INST, E_INST = "[INST]", "[/INST]"
B_KW, E_KW = "[KW]", "[/KW]"
# Format your prompt template
prompt = f"""{B_INST} Analyze the following keyword searched on amazon with intent of shopping. Identify the product category from the list {list_cat}.
Extract the brand from keyword related to brand loyalty intent. Output in JSON with keyword, product category, brand as keys.{E_INST}\n
{B_KW} {keyword} {E_KW}
"""
# print("Prompt:")
# print(prompt)
encoding = tokenizer(prompt, return_tensors="pt").to("cuda:0")
output =model.generate(input_ids=encoding.input_ids,
attention_mask=encoding.attention_mask,
max_new_tokens=20,
do_sample=True,
temperature=0.01,
eos_token_id=tokenizer.eos_token_id,
top_k=0)
#print()
# Subtract the length of input_ids from output to get only the model's response
output_text = tokenizer.decode(output[0, len(encoding.input_ids[0]):], skip_special_tokens=False)
output_text = re.sub('\n+', '\n', output_text) # remove excessive newline characters
#print("Generated Assistant Response:")
return output_text