Update app.py
Browse files
app.py
CHANGED
@@ -18,4 +18,28 @@ question = tg.Variable(question_string,
|
|
18 |
requires_grad=False)
|
19 |
|
20 |
answer = model(question)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
st.write(answer)
|
|
|
18 |
requires_grad=False)
|
19 |
|
20 |
answer = model(question)
|
21 |
+
st.write(answer)
|
22 |
+
|
23 |
+
answer.set_role_description("concise and accurate answer to the question")
|
24 |
+
|
25 |
+
# Step 2: Define the loss function and the optimizer, just like in PyTorch!
|
26 |
+
# Here, we don't have SGD, but we have TGD (Textual Gradient Descent)
|
27 |
+
# that works with "textual gradients".
|
28 |
+
optimizer = tg.TGD(parameters=[answer])
|
29 |
+
evaluation_instruction = (f"Here's a question: {question_string}. "
|
30 |
+
"Evaluate any given answer to this question, "
|
31 |
+
"be smart, logical, and very critical. "
|
32 |
+
"Just provide concise feedback.")
|
33 |
+
|
34 |
+
|
35 |
+
# TextLoss is a natural-language specified loss function that describes
|
36 |
+
# how we want to evaluate the reasoning.
|
37 |
+
loss_fn = tg.TextLoss(evaluation_instruction)
|
38 |
+
|
39 |
+
# Step 3: Do the loss computation, backward pass, and update the punchline.
|
40 |
+
# Exact same syntax as PyTorch!
|
41 |
+
loss = loss_fn(answer)
|
42 |
+
st.write(loss)
|
43 |
+
loss.backward()
|
44 |
+
optimizer.step()
|
45 |
st.write(answer)
|