Skip to content

Instantly share code, notes, and snippets.

View ScottCampit's full-sized avatar
🎯
Focusing on building AI-based running software with @Couro-io

Scott Campit ScottCampit

🎯
Focusing on building AI-based running software with @Couro-io
View GitHub Profile

Within the ### delimiter are user/system pairs for providing customer support:

User: "I received a damaged product. What should I do?" System: "I'm sorry to hear that! Please take a photo of the damaged item and upload it here. We'll arrange a replacement or refund for you immediately." User: "How do I track my order?" System: "You can track your order by entering your order number here: [link to tracking]. If you need further assistance, I'm here to help!" User: "Can I change my delivery address after placing an order?" System: "To ensure your package arrives correctly, please contact us immediately to change your delivery address. We can update the address if the order hasn't been shipped yet."

(User) What is a prompt, and how is it used for fine-tuning large language models? Provide a single sentence response.

(Model) A prompt is a specific input used to guide a large language model during fine-tuning to adapt its responses to particular tasks or styles.

Average evaluation accuracy (before fine-tuning): {'accuracy': 0.629} Average evaluation accuracy (after fine-tuning): {'accuracy': 0.805} Improvement: 17.6%

finetuning_accuracy = benchmark_metrics(finetuning_results)
print("Average evaluation accuracy (before fine-tuning):", baseline_accuracy)
print("Average evaluation accuracy (after fine-tuning):", finetuning_accuracy)
print(f"Improvement: {finetuning_accuracy['accuracy'] - baseline_accuracy['accuracy']:.1%}")
finetuning_results = small_eval_dataset.map(
predict,
batched=True,
load_from_cache_file=False,
desc="Inference"
)
checkpoint_path = "bert-twitter-reviews/checkpoint-12500/"
model = AutoModelForSequenceClassification.from_pretrained(checkpoint_path)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=small_train_dataset,
eval_dataset=small_eval_dataset,
compute_metrics=compute_metrics,
)
training_args = TrainingArguments(
hub_model_id="hf-bert-finetuning",
do_train=True,
output_dir="bert-twitter-reviews",
num_train_epochs=100,
evaluation_strategy="steps",
save_strategy="steps",
load_best_model_at_end=True,
)
def compute_metrics(eval_pred):
logits, labels = eval_pred
predictions = np.argmax(logits, axis=-1)
return metric.compute(predictions=predictions, references=labels)