Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
ddbd137
1
Parent(s):
fc46fb1
improved description
Browse files
app.py
CHANGED
|
@@ -27,7 +27,6 @@ with open("model_configs.json", "r") as f:
|
|
| 27 |
|
| 28 |
# Extract instruction
|
| 29 |
extract_input = model_config["extract_input"]
|
| 30 |
-
|
| 31 |
terminators = [
|
| 32 |
tokenizer.eos_token_id,
|
| 33 |
tokenizer.convert_tokens_to_ids("<|eot_id|>"),
|
|
@@ -35,7 +34,7 @@ terminators = [
|
|
| 35 |
|
| 36 |
|
| 37 |
@spaces.GPU
|
| 38 |
-
def
|
| 39 |
instruction = pipeline(
|
| 40 |
extract_input,
|
| 41 |
max_new_tokens=2048,
|
|
@@ -45,11 +44,13 @@ def generate_instruction():
|
|
| 45 |
top_p=1,
|
| 46 |
)
|
| 47 |
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
return pipeline(
|
| 53 |
response_template,
|
| 54 |
max_new_tokens=2048,
|
| 55 |
eos_token_id=terminators,
|
|
@@ -58,13 +59,7 @@ def generate_response(response_template):
|
|
| 58 |
top_p=1,
|
| 59 |
)
|
| 60 |
|
| 61 |
-
|
| 62 |
-
def generate_instruction_response():
|
| 63 |
-
sanitized_instruction = generate_instruction()
|
| 64 |
-
response_template = f"""<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n{sanitized_instruction}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"""
|
| 65 |
-
|
| 66 |
user_message = sanitized_instruction
|
| 67 |
-
response = generate_response(response_template)
|
| 68 |
assistant_response = response[0]["generated_text"][len(response_template) :]
|
| 69 |
|
| 70 |
return user_message, assistant_response
|
|
@@ -72,7 +67,7 @@ def generate_instruction_response():
|
|
| 72 |
|
| 73 |
title = "Magpie demo"
|
| 74 |
description = """
|
| 75 |
-
This Gradio demo
|
| 76 |
|
| 77 |
In this demo, you can see how the model generates a user instruction and a model response.
|
| 78 |
|
|
|
|
| 27 |
|
| 28 |
# Extract instruction
|
| 29 |
extract_input = model_config["extract_input"]
|
|
|
|
| 30 |
terminators = [
|
| 31 |
tokenizer.eos_token_id,
|
| 32 |
tokenizer.convert_tokens_to_ids("<|eot_id|>"),
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
@spaces.GPU
|
| 37 |
+
def generate_instruction_response():
|
| 38 |
instruction = pipeline(
|
| 39 |
extract_input,
|
| 40 |
max_new_tokens=2048,
|
|
|
|
| 44 |
top_p=1,
|
| 45 |
)
|
| 46 |
|
| 47 |
+
sanitized_instruction = instruction[0]["generated_text"][
|
| 48 |
+
len(extract_input) :
|
| 49 |
+
].split("\n")[0]
|
| 50 |
|
| 51 |
+
response_template = f"""<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n{sanitized_instruction}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"""
|
| 52 |
|
| 53 |
+
response = pipeline(
|
|
|
|
| 54 |
response_template,
|
| 55 |
max_new_tokens=2048,
|
| 56 |
eos_token_id=terminators,
|
|
|
|
| 59 |
top_p=1,
|
| 60 |
)
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
user_message = sanitized_instruction
|
|
|
|
| 63 |
assistant_response = response[0]["generated_text"][len(response_template) :]
|
| 64 |
|
| 65 |
return user_message, assistant_response
|
|
|
|
| 67 |
|
| 68 |
title = "Magpie demo"
|
| 69 |
description = """
|
| 70 |
+
This Gradio demo showcases the approach described in the Magpie paper. Magpie is a data synthesis pipeline that creates high-quality alignment data without relying on prompt engineering or seed questions. Instead, it generates instruction data by prompting aligned LLMs with a pre-query template. This method does not prompt the model with a question or starting query. Instead, it uses the model's pre-query template to generate instructions. Essentially, the model is given only the template until a user instruction starts, and then it generates the instruction and the response.
|
| 71 |
|
| 72 |
In this demo, you can see how the model generates a user instruction and a model response.
|
| 73 |
|