thefutureofai commited on
Commit
6ceb866
·
verified ·
1 Parent(s): eb8dcdc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +87 -3
README.md CHANGED
@@ -1,3 +1,87 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+ **Lazarus, the best small LLM**
5
+
6
+ Lazarus is a next-generation LLM based off of GPT2-medium and distilled from Llama3 3b using the vicgalle/alpaca-gpt4 dataset.
7
+
8
+ Lazarus shows exceptional understanding of questions and reasoning compared to other small models its size. Much better, larger model sizes are coming.
9
+
10
+ Here are some of Lazarus's responses:
11
+
12
+ User: what is AI?
13
+ Lazarus: Artificial Intelligence (AI) is a technology that helps humans solve complex problems and communicate with each other. It can help humans solve complex problems by analyzing and modeling data, and can help them understand complex information.
14
+
15
+ User: what is the Pythagorean Theorem?
16
+ Lazarus: The pythagorean theorem is a theorem used to find the hypotenuse of a triangle.
17
+
18
+ Here is the code to run:
19
+
20
+ '''
21
+
22
+ from transformers import AutoTokenizer, AutoModelForCausalLM
23
+ import torch
24
+
25
+ print("CUDA Available:", torch.cuda.is_available())
26
+
27
+ model_name = "./gpt2-lora-magpie-mistral"
28
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
29
+ model = AutoModelForCausalLM.from_pretrained(model_name)
30
+ model.eval()
31
+
32
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
33
+ model.to(device)
34
+
35
+ system_prompt = (
36
+ "Your name is Lazarus. You are an intelligent AI assistant. You help users with whatever they need. "
37
+ "You always think before answering, and explain your reasoning out loud step by step.\n"
38
+ )
39
+
40
+ chat_history = []
41
+
42
+ def chat():
43
+ print("Chatting with GPT-2 (type 'exit' to quit)\n")
44
+
45
+ while True:
46
+ user_input = input("You: ")
47
+ if user_input.lower() == "exit":
48
+ break
49
+
50
+ # Add user's message
51
+ chat_history.append(f"You: {user_input}")
52
+
53
+ # Keep last 3 exchanges (6 lines)
54
+ recent_history = chat_history[-6:]
55
+ full_prompt = system_prompt + "\n".join(recent_history) + "\nAI:"
56
+
57
+ inputs = tokenizer(full_prompt, return_tensors="pt", truncation=True).to(device)
58
+
59
+ with torch.no_grad():
60
+ outputs = model.generate(
61
+ **inputs,
62
+ max_length=inputs["input_ids"].shape[1] + 150,
63
+ pad_token_id=tokenizer.eos_token_id,
64
+ do_sample=True,
65
+ top_k=100,
66
+ top_p=0.92,
67
+ temperature=0.7,
68
+ eos_token_id=tokenizer.eos_token_id
69
+ )
70
+
71
+ # Extract model's new output portion
72
+ response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
73
+ response = response.strip()
74
+
75
+ # Filter out low-quality or empty responses
76
+ bad_responses = {"I hope that", "I don't know", "", "I'm excited"}
77
+ if response in bad_responses:
78
+ print("AI: [Regenerating due to low-quality response]")
79
+ continue
80
+
81
+ print(f"AI: {response}")
82
+ chat_history.append(f"AI: {response}")
83
+
84
+ if __name__ == "__main__":
85
+ chat()
86
+
87
+ '''