Skip to content

Instantly share code, notes, and snippets.

View deepakachu5114's full-sized avatar

Deepak C Nayak deepakachu5114

View GitHub Profile
@deepakachu5114
deepakachu5114 / .py
Created October 30, 2025 05:20
TailoredAI - prompt optimization 5
def main():
train_set, test_set = train_test_split(
decisions_df, test_size=TEST_SET_SIZE, random_state=RANDOM_STATE
)
print(f”Total dataset: {len(decisions_df)} samples”)
print(f”Training on: {len(train_set)} samples”)
print(f”Validating on: {len(test_set)} samples”)
result = {”prompt”: [], “accuracy”: []}
@deepakachu5114
deepakachu5114 / .py
Created October 30, 2025 05:19
TailoredAI - prompt optimization 4
optimizer.zero_grad()
loss.backward()
optimizer.step()
new_pred = model(question)
print(new_pred.value)
print(system_prompt.get_gradient_text()) # this prints the textual gradients
print(system_prompt) # the system prompt after optimisation
@deepakachu5114
deepakachu5114 / .py
Created October 30, 2025 05:18
TailoredAI - prompt optimization 3
# choose a random data point
idx = 4
question_str = decisions_df.iloc[idx].question
answer_str = decisions_df.iloc[idx].answer
question = tg.Variable(question_str, role_description=”football situaion query”)
answer = tg.Variable(answer_str, role_description=”Ground Truth Answer”)
# get the model prediction before
pred = model(question)
@deepakachu5114
deepakachu5114 / .py
Created October 30, 2025 05:15
TailoredAI - prompt optimization 2
system_prompt = tg.Variable(
value=”“”You are an expert football referee. I will give you a situation in Football, and you must provide the correct official decision or restart.
Your output must exactly match the decision string. Do not provide any extra explanation, just the decision.
“”“,
requires_grad=True,
role_description=”System prompt to answer football queries”
)
model = tg.BlackboxLLM(llm_engine, system_prompt)
@deepakachu5114
deepakachu5114 / .py
Created October 30, 2025 05:08
TailoredAI - prompt optimization 1
# Install the library
!pip install textgrad -q
# --- Imports ---
import pandas as pd
import textgrad as tg
from textgrad import get_engine, Variable
from textgrad.optimizer import TextualGradientDescent
from sklearn.model_selection import train_test_split