Alright, I just had chatgpt write me a very small AI model code for python. Well, it actually gave me multiple models codes, with about 30 to 1000 code lines for different models.
It actually also offered me 3000 code lines model, but I dont want that many code lines because I dont have much experience in programming.
I am thinking to just test run a 100 lines, retrieval ranking mini AI, instead of larger AI.
import re
import math
import random
from collections import Counter
class OptimalMiniAI:
def __init__(self):
self.sentences = []
self.freqs = []
# ---------- Training ----------
def train(self, text):
text = text.lower()
self.sentences = re.split(r'[.!?]+', text)
self.sentences = [s.strip() for s in self.sentences if s.strip()]
self.freqs = []
for s in self.sentences:
self.freqs.append(Counter(s.split()))
# ---------- Scoring ----------
def _score(self, prompt_words, idx):
freq = self.freqs[idx]
# TF-like matching score
score = sum(freq.get(w, 0) for w in prompt_words)
# IDF-style rarity bonus
for w in prompt_words:
doc_count = sum(1 for f in self.freqs if w in f)
if doc_count > 0:
score += math.log(len(self.sentences) / doc_count + 1)
# Shorter, cleaner claims are slightly preferred
score += 1 / (len(self.sentences[idx]) + 1)
return score
# ---------- Response Engine ----------
def respond(self, prompt, top_k=3):
if not self.sentences:
return "No knowledge available."
prompt = prompt.lower()
words = prompt.split()
scored = []
for i in range(len(self.sentences)):
scored.append(
(self._score(words, i), self.sentences[i])
)
scored.sort(reverse=True, key=lambda x: x[0])
# Select best candidates
best = [s for score, s in scored[:top_k] if score > 0]
if best:
return ". ".join(best) + "."
# ---------- Smart fallback synthesis ----------
candidates = [
s for s in self.sentences
if any(w in s for w in words)
]
if candidates:
return random.choice(candidates) + "."
return "I am not sure, but I am learning."
# ---------- Example ----------
if __name__ == "__main__":
corpus = """
Artificial intelligence is the study of intelligent machines.
Machine learning enables systems to learn from data.
Neural networks approximate complex patterns.
Prompt keywords guide response selection.
Retrieval based AI repeats learned claims.
"""
ai = OptimalMiniAI()
ai.train(corpus)
while True:
q = input("You: ")
if q.lower() in ["exit", "quit"]:
break
print("AI:", ai.respond(q))
If you are really serious about pushing minimal AI design, I can show something extreme: