Spaces:
Running
on
Zero
Running
on
Zero
Add noise start
Browse files
app.py
CHANGED
@@ -57,10 +57,10 @@ def get_noising_schedule(i, max_it, sharpness=5.0):
|
|
57 |
x = i / max_it
|
58 |
return (np.exp(-sharpness * x) - np.exp(-sharpness)) / (1 - np.exp(-sharpness))
|
59 |
|
60 |
-
def noisify_answer(input_ids, answer_start, threshold=1.0, eot_weight=1.0, clustering=0.5):
|
61 |
noised = input_ids.copy()
|
62 |
answer_len = len(noised) - answer_start
|
63 |
-
num_to_noise = int(threshold * answer_len)
|
64 |
|
65 |
if num_to_noise == 0:
|
66 |
return noised, []
|
@@ -144,7 +144,7 @@ def generate_diffusion_text(input_ids):
|
|
144 |
return sampled, conf
|
145 |
|
146 |
# --- Inference Wrapper ---
|
147 |
-
def diffusion_chat(question, eot_weight, max_it, pause_length, sharpness, clustering, use_confidence_noising, noise_clipping):
|
148 |
placeholder = "What do you know about the city of New York?"
|
149 |
if question.strip() == "":
|
150 |
question = placeholder
|
@@ -214,7 +214,7 @@ def diffusion_chat(question, eot_weight, max_it, pause_length, sharpness, cluste
|
|
214 |
just_noised_indices = []
|
215 |
else:
|
216 |
noised_answer, just_noised_indices = noisify_answer(
|
217 |
-
current_tokens, answer_start, threshold=threshold, eot_weight=eot_weight, clustering=clustering
|
218 |
)
|
219 |
|
220 |
# Compose full input again: prompt + noised answer
|
@@ -258,6 +258,7 @@ demo = gr.Interface(
|
|
258 |
gr.Slider(0.01, 5, value=0.01, step=0.01, label="↑ = longer pause (for visualization)"),
|
259 |
gr.Slider(1.0, 20.0, value=5.0, step=0.5, label="↓ = more noising (sharpness)"),
|
260 |
gr.Slider(0.0, 1.0, value=0.5, step=0.05, label="↑ = more clustered noising (fewer, larger edits)"),
|
|
|
261 |
gr.Checkbox(value=False, label="Use confidence-guided noising"),
|
262 |
gr.Slider(0.01, 1.0, value=0.05, step=0.01, label="↓ = more confidence guidance (noise clipping)"),
|
263 |
|
|
|
57 |
x = i / max_it
|
58 |
return (np.exp(-sharpness * x) - np.exp(-sharpness)) / (1 - np.exp(-sharpness))
|
59 |
|
60 |
+
def noisify_answer(input_ids, answer_start, threshold=1.0, eot_weight=1.0, clustering=0.5, noise_start = 0.5):
|
61 |
noised = input_ids.copy()
|
62 |
answer_len = len(noised) - answer_start
|
63 |
+
num_to_noise = int(threshold * answer_len * noise_start)
|
64 |
|
65 |
if num_to_noise == 0:
|
66 |
return noised, []
|
|
|
144 |
return sampled, conf
|
145 |
|
146 |
# --- Inference Wrapper ---
|
147 |
+
def diffusion_chat(question, eot_weight, max_it, pause_length, sharpness, clustering, noise_start, use_confidence_noising, noise_clipping):
|
148 |
placeholder = "What do you know about the city of New York?"
|
149 |
if question.strip() == "":
|
150 |
question = placeholder
|
|
|
214 |
just_noised_indices = []
|
215 |
else:
|
216 |
noised_answer, just_noised_indices = noisify_answer(
|
217 |
+
current_tokens, answer_start, threshold=threshold, eot_weight=eot_weight, clustering=clustering, noise_start = noise_start,
|
218 |
)
|
219 |
|
220 |
# Compose full input again: prompt + noised answer
|
|
|
258 |
gr.Slider(0.01, 5, value=0.01, step=0.01, label="↑ = longer pause (for visualization)"),
|
259 |
gr.Slider(1.0, 20.0, value=5.0, step=0.5, label="↓ = more noising (sharpness)"),
|
260 |
gr.Slider(0.0, 1.0, value=0.5, step=0.05, label="↑ = more clustered noising (fewer, larger edits)"),
|
261 |
+
gr.Slider(0.0, 1.0, value=0.5, step=0.05, label="↑ = more noise (noise start)"),
|
262 |
gr.Checkbox(value=False, label="Use confidence-guided noising"),
|
263 |
gr.Slider(0.01, 1.0, value=0.05, step=0.01, label="↓ = more confidence guidance (noise clipping)"),
|
264 |
|