This is a complex project. If you are unfamiliar with how AI works, please refrain from modifying the core components. This will not always work. Enable Turbo Mode When you start the project, the AI will begin training. Once training finishes (which should only take a few seconds with Turbo Mode enabled), you can draw a 1 or a 0 on the grid (treating white as the background). Press Space when you are finished to trigger a prediction. Variable Definitions Epochs: The total number of repetitions used to train the AI. If you modify this value, you must restart the project to retrain the model. Epoch: Tracks the current repetition; this value only updates during the initial training phase. Learning Rate: The multiplier that determines how quickly the AI adapts. If you modify this value, you must restart the project. Input: The grid data condensed into a single Scratch list. This variable is updated automatically based on the white grid; you cannot edit it manually and do not need to restart the project to update it. Error: A measurement of the AI's inaccuracy, used to calculate how the weights should be updated. Dataset: The data the project uses for training. You can generate a new dataset using the Python code provided below. This code can be run on Google Colab. Note: The code produces a massive output. Approximately the last 1/65th of the output should be copied into the targets_var variable in the project. Everything above that point should be copied into dataset_var. Targets: These represent the expected outputs (what the AI should be seeing). Do not modify this unless you are also modifying the dataset. Val: The mathematical dot product. This represents the AI's raw calculation before it is converted into a final answer.
#DO NOT MODIFY THIS CODE, YOU WILL GET A WEIRD DATASET IN MOST CASES import numpy as np def get_custom_1d_index(r, c): """ Maps 2D (row, col) to 1D: Right-to-Left, Top-to-Bottom. Index 0 is (0, 7), Index 7 is (0, 0), Index 8 is (1, 7). """ return (r * 8) + (7 - c) def gd(num_samples=100): images = [] labels = [] for _ in range(num_samples): # Initialize a blank 8x8 binary grid grid = np.zeros((8, 8), dtype=int) digit = np.random.choice([0, 1]) if digit == 0: # Randomize dimensions: Height (3-7), Width (2-6) h = np.random.randint(3, 8) w = np.random.randint(2, 7) # Random anchor position ensuring it fits in the 8x8 r0 = np.random.randint(0, 8 - h + 1) c0 = np.random.randint(0, 8 - w + 1) # Draw the '0' (hollow rectangle) grid[r0:r0+h, c0] = 1 # Left wall grid[r0:r0+h, c0+w-1] = 1 # Right wall grid[r0, c0:c0+w] = 1 # Top grid[r0+h-1, c0:c0+w] = 1 # Bottom else: # Randomize Height (3-7) and Column position h = np.random.randint(3, 8) r0 = np.random.randint(0, 8 - h + 1) col = np.random.randint(0, 8) # Draw the '1' (vertical line) grid[r0:r0+h, col] = 1 # Randomly add a 'base' or a 'top hook' variety = np.random.random() if variety > 0.7 and 0 < col < 7: grid[r0+h-1, col-1:col+2] = 1 # Base elif variety < 0.2 and col > 0: grid[r0, col-1] = 1 # Simple top hook images.append(grid) labels.append(digit) return np.array(images), np.array(labels) # Example: Generate 1000 samples images, targets = gd(100) for i in range(len(images)): for q in range(len(images[i])): for c in range(len(images[i][q])): print(images[i][q][c]) print("--------targets-----------") for i in range(len(targets)): print(targets[i])