This model is a fine-tuned version of GPT-2, adapted for instruction-based tasks. It has been trained to provide helpful and coherent responses to a variety of prompts.
This model is based on OpenAI's GPT-2 architecture and has been fine-tuned to respond to instructions in a format that mimics conversational exchanges. The fine-tuning process enhances its ability to follow specific instructions and generate appropriate responses, making it a valuable tool for interactive applications.
1import torch
2import random
3import numpy as np
4from transformers import GPT2LMHeadModel, GPT2Tokenizer
5
6# Load the fine-tuned model and tokenizer
7model = GPT2LMHeadModel.from_pretrained("Autsadin/gpt2_instruct")
8tokenizer = GPT2Tokenizer.from_pretrained("Autsadin/gpt2_instruct")
9
10# Define the template for instruction-based prompts
11template = '''<s>[INST] <<SYS>>
12You are a helpful assistant
13<</SYS>>
14
15{instruct}[/INST]'''
16
17# Function to format prompts using the template
18def format_entry(prompt):
19 return template.format(instruct=prompt)
20
21# Define the input prompt
22prompt = "What is a dog?"
23
24# Tokenize the input prompt
25inputs = tokenizer.encode(format_entry(prompt), return_tensors='pt')
26
27# Generate a response
28outputs = model.generate(
29 inputs,
30 max_length=256,
31 num_return_sequences=1,
32 top_k=50,
33 top_p=0.95,
34 temperature=0.8,
35 pad_token_id=tokenizer.eos_token_id,
36 do_sample=True,
37 early_stopping=True
38)
39
40# Decode and print the generated text
41generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
42print(generated_text)
#Training Data
The model was fine-tuned using the Alpaca GPT-4 dataset available at the following GitHub repository.
https://github.com/hy5468/TransLLM/tree/main/data/train
Specifically, the alpaca_gpt4_data_en.zip dataset was utilized.
This dataset includes a wide range of instruction-based prompts and responses,
providing a robust foundation for the model's training.
#Training Procedure
The fine-tuning process was carried out with the following hyperparameters:
Learning Rate: 2e-5
Batch Size (Train): 4
Batch Size (Eval): 4
Number of Epochs: 1
Weight Decay: 0.01
#Training Environment
The model was trained using PyTorch and the Hugging Face transformers library. The training was performed on a GPU-enabled environment to accelerate the fine-tuning process.The training script ensures reproducibility by setting a consistent random seed across different components.