From 581b5e8faaaa1f1a4548bd76287cadf5da8158e3 Mon Sep 17 00:00:00 2001 From: vinid Date: Tue, 11 Jun 2024 22:04:45 -0400 Subject: [PATCH] update example --- README.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4736732..69e9663 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,9 @@ question_string = ("If it takes 1 hour to dry 25 shirts under the sun, " "how long will it take to dry 30 shirts under the sun? " "Reason step by step") -question = tg.Variable(question_string, role_description="question to the LLM", requires_grad=False) +question = tg.Variable(question_string, + role_description="question to the LLM", + requires_grad=False) answer = model(question) ``` @@ -56,19 +58,26 @@ As you can see, **the model's answer is incorrect.** We can optimize the answer answer.set_role_description("concise and accurate answer to the question") # Step 2: Define the loss function and the optimizer, just like in PyTorch! -# Here, we don't have SGD, but we have TGD (Textual Gradient Descent) that works with "textual gradients". +# Here, we don't have SGD, but we have TGD (Textual Gradient Descent) +# that works with "textual gradients". optimizer = tg.TGD(parameters=[answer]) -evaluation_instruction = f"Here's a question: {question_string}. Evaluate any given answer to this question, be smart, logical, and very critical. Just provide concise feedback." - -# TextLoss is a natural-language specified loss function that describes how we want to evaluate the reasoning. +evaluation_instruction = (f"Here's a question: {question_string}. " + "Evaluate any given answer to this question, " + "be smart, logical, and very critical. " + "Just provide concise feedback.") + + +# TextLoss is a natural-language specified loss function that describes +# how we want to evaluate the reasoning. loss_fn = tg.TextLoss(evaluation_instruction) ``` > :brain: loss: [...] Your step-by-step reasoning is clear and logical, -> but it contains a critical flaw in the assumption that drying time is directly proportional -> to the number of shirts. [...] +> but it contains a critical flaw in the assumption that drying time is +> directly proportional to the number of shirts. [...] ```python -# Step 3: Do the loss computation, backward pass, and update the punchline. Exact same syntax as PyTorch! +# Step 3: Do the loss computation, backward pass, and update the punchline. +# Exact same syntax as PyTorch! loss = loss_fn(answer) loss.backward() optimizer.step()