Views
No views yet
Chatbots
Instruction-following assistants
Lightweight deployments on limited hardwareBase Model: openai-community/gpt2
Dataset: Custom greeting dataset with structured "User" and "AI" dialogue pairs.
Hardware: Fine-tuned on a single NVIDIA RTX 3060.
Optimization: Fine-tuning utilized LoRA (Low-Rank Adaptation) to improve memory efficiency.1from transformers import GPT2LMHeadModel, GPT2Tokenizer
2import torch
3
4# Load the model and tokenizer
5model_path = "theaithinker/OpenCelestial_1"
6model = GPT2LMHeadModel.from_pretrained(model_path)
7tokenizer = GPT2Tokenizer.from_pretrained(model_path)
8
9# Set the pad token to the EOS token if not already set
10tokenizer.pad_token = tokenizer.eos_token
11
12print("Chatbot is ready! Type 'exit' to quit.")
13
14while True:
15 user_input = input("You: ")
16 if user_input.lower() == "exit":
17 print("Chatbot: Goodbye!")
18 break
19
20 # Define the system prompt and the full prompt
21 system_prompt = "You are an intelligent AI assistant that will answer every question to the best of your ability. Be clear and polite with your answers."
22 prompt = f"{system_prompt}\n### Instruction:\n{user_input}\n### Response:"
23
24 # Tokenize the input
25 inputs = tokenizer(
26 prompt,
27 return_tensors="pt",
28 padding=True,
29 truncation=True,
30 max_length=1024,
31 )
32 input_ids = inputs.input_ids.to(model.device)
33 attention_mask = inputs.attention_mask.to(model.device)
34
35 # Generate the response
36 with torch.no_grad():
37 outputs = model.generate(
38 input_ids=input_ids,
39 attention_mask=attention_mask,
40 max_new_tokens=150,
41 pad_token_id=tokenizer.eos_token_id,
42 do_sample=True,
43 temperature=0.7,
44 top_k=50,
45 top_p=0.95,
46 )
47
48 # Decode the response and clean it up
49 response = tokenizer.decode(outputs[0], skip_special_tokens=True)
50 clean_response = response.split("### Response:")[-1].strip()
51 print(f"Chatbot: {clean_response}")LoRA Configuration:
Rank (r): 4
Alpha: 16
Dropout: 0.1
Target Modules: GPT-2’s attention layers (attn.c_attn)
Training Arguments:
Mixed precision: Enabled (fp16)
Epochs: 3
Batch size: 2 (to fit GPU memory)
Learning rate: 5e-5Clear conversational ability with polite, structured responses.
Low resource requirements, suitable for GPUs like the RTX 3060.
Consistency in instruction-following tasks.Conversational AI applications.
Instruction-based assistants that respond politely and clearly.
Lightweight deployments for hobbyists, small-scale developers, or educational purposes.Responses may still contain hallucinations or factual inaccuracies.
Performance is limited to the dataset scope and GPT-2’s inherent capabilities.Base Model: openai-community/gpt2
Fine-tuned using the LoRA technique for efficient memory usage.
Developed on a single NVIDIA RTX 3060 GPU.