Update README.md
Browse files
README.md
CHANGED
|
@@ -61,31 +61,31 @@ base_model: meta-llama/Llama-2-7b-chat-hf
|
|
| 61 |
|
| 62 |
##### for brand name
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
| 61 |
|
| 62 |
##### for brand name
|
| 63 |
|
| 64 |
+
def generate2(lista,keyword):
|
| 65 |
+
|
| 66 |
+
prompt = f"""[INST] Extract the brand of the keyword from the given list if present.[/INST]
|
| 67 |
+
|
| 68 |
+
[KW] {keyword} [/KW]
|
| 69 |
+
|
| 70 |
+
[LIST] {lista} [/LIST]
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
response ###"""
|
| 74 |
+
print("Prompt:")
|
| 75 |
+
print(prompt)
|
| 76 |
+
encoding = tokenizer(prompt, return_tensors="pt").to("cuda:0")
|
| 77 |
+
output = model.generate(input_ids=encoding.input_ids,
|
| 78 |
+
attention_mask=encoding.attention_mask,
|
| 79 |
+
max_new_tokens=200,
|
| 80 |
+
do_sample=True,
|
| 81 |
+
temperature=0.9,
|
| 82 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 83 |
+
top_p=0.9,
|
| 84 |
+
repetition_penalty=1.2)
|
| 85 |
+
|
| 86 |
+
print()
|
| 87 |
+
# Subtract the length of input_ids from output to get only the model's response
|
| 88 |
+
output_text = tokenizer.decode(output[0, len(encoding.input_ids[0]):], skip_special_tokens=False)
|
| 89 |
+
output_text = re.sub('\n+', '\n', output_text) # remove excessive newline characters
|
| 90 |
+
print("Generated Assistant Response:")
|
| 91 |
+
return output_text
|