AI Code
Hands-on implementations for neural networks, natural language processing, and machine learning algorithms using TensorFlow, PyTorch, and Scikit-learn.
Neural Network Implementation
This example demonstrates a simple neural network using TensorFlow to classify MNIST digits.
import tensorflow as tf
from tensorflow.keras.datasets import mnist
# Load and normalize data
(images, labels), (test_images, test_labels) = mnist.load_data()
images = images / 255.0
# Build sequential model
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
# Compile model
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# Train
model.fit(images, labels, epochs=5, batch_size=32)
# Evaluate
test_loss, test_acc = model.evaluate(test_images, test_labels)
print(f"Accuracy: {test_acc:.4f}")
Network Architecture
This simple network contains 784 input units (28x28 pixels), 128 hidden units, and 10 output units (digit classes). The ReLU activation introduces nonlinearity between the layers.
- Input Layer: 784 Neurons
- Hidden Layer: 128 Neurons (ReLU)
- Output Layer: 10 Neurons (Softmax)
Advanced Implementations
Explore more complex implementations in natural language processing, reinforcement learning, and computer vision.
GPT Mini
Lightweight transformer-based model for text generation and language understanding.
View ImplementationReinforcement Learning
Q-learning implementation for solving grid-world challenges using policy gradients.
Explore Agent CodeReady to Code?
Clone the repository, install dependencies, and modify these examples to suit your specific use case.