import json import struct import numpy as np import random import os print("🛠️ Krynex 200K Parameters Testing") print("="*40) dataset_path = "/storage/emulated/0/Download/dataset.jsonl" if not os.path.exists(dataset_path): dataset_path = "dataset.jsonl" text_data = [] with open(dataset_path, "r", encoding="utf-8") as f: for line in f: data = json.loads(line) text_data.append(data.get("instruction", "") + " " + data.get("output", "")) full_text = " ".join(text_data) words = sorted(list(set(full_text.lower().split()))) t2i = {w: i for i, w in enumerate(words)} i2t = {i: w for i, w in enumerate(words)} vocab_size = len(t2i) hidden_size = 64 tflite_path = "full_dataset_model.tflite" if not os.path.exists(tflite_path): tflite_path = f"/storage/emulated/0/Download/{tflite_path}" with open(tflite_path, "rb") as f: magic, offset = struct.unpack('<4sI', f.read(8)) l1 = struct.unpack('= seq_length else res ctx = ctx + [" "] * (seq_length - len(ctx)) idx = [t2i.get(w, 0) for w in ctx] X = np.zeros((vocab_size, seq_length)) X[idx, np.arange(seq_length)] = 1 h = np.tanh(W1 @ X + b1) y_pred = softmax(W2 @ h + b2) probs = y_pred[:, -1].flatten() probs = probs / (np.sum(probs) + 1e-12) probs = np.clip(probs, 0, 1) probs = probs / (np.sum(probs) + 1e-12) next_idx = np.random.choice(vocab_size, p=probs) res.append(i2t.get(next_idx, "")) return " ".join(res) print("💬 Chat ('exit' - stop)") while True: u = input("\n👤 You: ").strip() if u.lower() in ['выход', 'exit', 'stop', 'стоп']: print("🤖 Goodbye!") break if u: print(f"\n🤖 AI: {gen(u, 15)}")