Examples and Tutorials - krishanth7/EveryO GitHub Wiki

Examples and Tutorials

EveryO โ€” Practical Machine Learning Development

Learn ยท Build ยท Train ยท Evaluate ยท Deploy

Python EveryO Tutorials License

A practical guide to numerical computation, tensor operations, automatic differentiation, neural network development, optimization, model evaluation, and reproducible experimentation.

Home ยท Installation ยท Quick Start ยท API Reference


Maintained By & Owner: EveryO Contributors & @krishanth7

Important

Tutorial Compatibility

These tutorials target the EveryO v0.2.0 source API reviewed from the repository's default branch.

The examples use documented public exports and standard Python libraries. Exact runtime behavior should be verified with the installed version, and numerical outputs may vary slightly with floating-point precision.


Table of Contents

  1. Overview
  2. Development Environment
  3. Tutorial 1 โ€” First Tensor
  4. Tutorial 2 โ€” Tensor Mathematics
  5. Tutorial 3 โ€” Shapes and Matrix Multiplication
  6. Tutorial 4 โ€” Automatic Differentiation
  7. Tutorial 5 โ€” First Neural Network
  8. Tutorial 6 โ€” Loss Functions
  9. Tutorial 7 โ€” Training a Regression Model
  10. Tutorial 8 โ€” Adam Optimizer
  11. Tutorial 9 โ€” Model Evaluation
  12. Tutorial 10 โ€” Inference
  13. Reproducibility
  14. Performance and Diagnostics
  15. Common Errors
  16. Testing Your Examples
  17. Additional Learning Resources
  18. Next Steps

1. Overview

This page introduces EveryO through progressively more advanced practical examples.

The tutorials begin with tensor creation and progress toward building and training a neural network.

1.1 Learning Objectives

After completing the tutorials, developers should understand how to:

  • Create and inspect tensors.
  • Perform numerical operations.
  • Work with tensor dimensions.
  • Calculate gradients.
  • Construct neural networks.
  • Select loss functions.
  • Configure optimizers.
  • Train a simple model.
  • Evaluate predictions.
  • Use inference contexts.

1.2 Recommended Learning Path

Installation
     |
     v
Tensor Fundamentals
     |
     v
Mathematical Operations
     |
     v
Automatic Differentiation
     |
     v
Neural Network Construction
     |
     v
Loss Functions
     |
     v
Model Training
     |
     v
Evaluation and Inference

2. Development Environment

2.1 Requirements

  • Python 3.9 or newer.
  • Git.
  • Python package installer.
  • Supported operating system.
  • EveryO source or installed package.

2.2 Clone Repository

git clone https://github.com/krishanth7/EveryO.git
cd EveryO

2.3 Create Virtual Environment

python -m venv .venv

Activate the environment.

Windows PowerShell:

.venv\Scripts\Activate.ps1

Linux / macOS:

source .venv/bin/activate

2.4 Install EveryO

python -m pip install -e .

For development:

python -m pip install -e ".[dev]"

2.5 Verify Installation

import everyo as eo

print("EveryO version:", eo.__version__)

3. Tutorial 1 โ€” First Tensor

Difficulty: Beginner

Objective: Create a tensor and inspect its data.

3.1 Example

import everyo as eo

x = eo.tensor([1.0, 2.0, 3.0])

print("Tensor:", x)
print("Shape:", x.shape)
print("Data:", x.data)

3.2 Expected Shape

(3,)

3.3 Explanation

The tensor function creates a tensor from supported input data.

The tensor's shape describes its dimensions.

The data property exposes the underlying NumPy array.

3.4 Key Concepts

Concept Meaning
Tensor Numerical data structure
Shape Dimensions
Data Stored numerical values
Dtype Numerical representation

Related: Tensor Engine


4. Tutorial 2 โ€” Tensor Mathematics

Difficulty: Beginner

Objective: Perform basic mathematical operations.

4.1 Addition

import everyo as eo

a = eo.tensor([1.0, 2.0, 3.0])
b = eo.tensor([4.0, 5.0, 6.0])

result = eo.add(a, b)

print(result.data)

Expected numerical result:

[5. 7. 9.]

4.2 Multiplication

result = eo.multiply(a, b)

print(result.data)

Expected numerical result:

[ 4. 10. 18.]

4.3 Tensor Operators

EveryO also provides arithmetic operators through its tensor class.

result = a + b

print(result.data)

4.4 Mathematical Relationship

For element-wise addition:

[ c_i=a_i+b_i ]

For element-wise multiplication:

[ c_i=a_ib_i ]

4.5 Practical Applications

These operations are used in:

  • Feature transformations.
  • Neural network computations.
  • Loss calculations.
  • Gradient computation.
  • Numerical experimentation.

5. Tutorial 3 โ€” Shapes and Matrix Multiplication

Difficulty: Beginner to Intermediate

Objective: Understand matrix dimensions and multiplication.

5.1 Example

import everyo as eo

a = eo.tensor([
    [1.0, 2.0],
    [3.0, 4.0]
])

b = eo.tensor([
    [5.0, 6.0],
    [7.0, 8.0]
])

result = eo.matmul(a, b)

print(result.data)
print("Output shape:", result.shape)

Expected numerical result:

[[19. 22.]
 [43. 50.]]

Output shape:

(2, 2)

5.2 Mathematical Formula

For matrices (A) and (B):

[ C=AB ]

Each result element is:

[ C_{ij}=\sum_k A_{ik}B_{kj} ]

5.3 Shape Compatibility

If:

[ A\in\mathbb{R}^{m\times n} ]

and:

[ B\in\mathbb{R}^{n\times p} ]

then:

[ C\in\mathbb{R}^{m\times p} ]

5.4 Common Mistake

Matrix multiplication requires compatible inner dimensions.

For example:

(2, 3) @ (4, 2)

is not valid standard matrix multiplication.


6. Tutorial 4 โ€” Automatic Differentiation

Difficulty: Intermediate

Objective: Compute a gradient using EveryO's autograd system.

6.1 Mathematical Example

Consider:

[ f(x)=x^2 ]

Its derivative is:

[ f'(x)=2x ]

At:

[ x=3 ]

the derivative is:

[ f'(3)=6 ]

6.2 Example

import everyo as eo

x = eo.tensor(
    3.0,
    requires_grad=True
)

y = eo.multiply(x, x)

y.backward()

print("Gradient:", x.grad)

The expected gradient is approximately 6.0.

6.3 Explanation

  1. The input tensor enables gradient tracking.
  2. The multiplication creates a differentiable result.
  3. Calling backward() computes gradients.
  4. The gradient is stored on the input tensor.

6.4 Computational Graph

x = 3
  |
  +------+
  |      |
  v      v
  x  *   x
     |
     v
   y = 9
     |
     v
 backward()
     |
     v
 dy/dx = 6

6.5 Important Considerations

  • Gradient tracking is required for relevant inputs.
  • Operations must support differentiation.
  • Repeated backward calls may accumulate gradients.
  • Gradient shape must match the differentiated input.

Related: Automatic Differentiation


7. Tutorial 5 โ€” First Neural Network

Difficulty: Intermediate

Objective: Build a feedforward neural network.

7.1 Architecture

Input: 4 Features
       |
       v
Linear(4, 16)
       |
       v
ReLU
       |
       v
Linear(16, 2)
       |
       v
Output: 2 Features

7.2 Example

import everyo as eo

model = eo.Sequential(
    eo.Linear(4, 16, seed=0),
    eo.ReLU(),
    eo.Linear(16, 2, seed=1)
)

x = eo.zeros(3, 4)

output = model(x)

print("Output shape:", output.shape)

Expected output:

Output shape: (3, 2)

7.3 Explanation

The model contains:

  • An input transformation.
  • A nonlinear activation.
  • An output transformation.

The batch contains three samples, each with four input features.

7.4 Parameter Count

For the first layer:

[ P_1=4(16)+16=80 ]

For the second layer:

[ P_2=16(2)+2=34 ]

Total:

[ P=80+34=114 ]

This assumes biases are enabled in both linear layers.

7.5 Why Sequential?

The Sequential container executes its child modules in order.

Each layer receives the output of the previous layer.

Related: Neural Networks


8. Tutorial 6 โ€” Loss Functions

Difficulty: Intermediate

Objective: Measure prediction error.

8.1 Mean Squared Error

For regression:

[ L_{MSE}= \frac{1}{N} \sum_{i=1}^{N} (y_i-\hat y_i)^2 ]

8.2 Example

import everyo as eo

predictions = eo.tensor([2.0, 4.0])
targets = eo.tensor([1.0, 3.0])

criterion = eo.MSELoss()

loss = criterion(predictions, targets)

print("Loss:", loss.item())

Expected output:

Loss: 1.0

8.3 Other Loss Classes

EveryO also exports:

Loss Typical Task
MSELoss Regression
MAELoss Regression
BCELoss Binary classification
BCEWithLogitsLoss Binary classification using logits
CrossEntropyLoss Multiclass classification

8.4 Reduction Options

The inspected loss implementation supports:

  • mean
  • sum
  • none

Example:

criterion = eo.MSELoss(reduction="mean")

9. Tutorial 7 โ€” Training a Regression Model

Difficulty: Intermediate

Objective: Train a neural network to approximate a linear relationship.

9.1 Problem Definition

We want the model to learn:

[ y=2x+1 ]

Training examples:

Input Target
0 1
1 3
2 5
3 7
4 9

9.2 Complete Example

import everyo as eo

# 1. Prepare training data.
x = eo.tensor([
    [0.0],
    [1.0],
    [2.0],
    [3.0],
    [4.0],
])

y = eo.tensor([
    [1.0],
    [3.0],
    [5.0],
    [7.0],
    [9.0],
])

# 2. Create the model.
model = eo.Sequential(
    eo.Linear(1, 1, seed=42)
)

# 3. Configure loss and optimizer.
criterion = eo.MSELoss()

optimizer = eo.SGD(
    model.parameters(),
    lr=0.01
)

# 4. Train the model.
for epoch in range(1000):
    optimizer.zero_grad()

    predictions = model(x)
    loss = criterion(predictions, y)

    loss.backward()
    optimizer.step()

    if (epoch + 1) % 100 == 0:
        print(
            f"Epoch {epoch + 1}: "
            f"Loss = {loss.item():.6f}"
        )

# 5. Evaluate.
with eo.no_grad():
    test = eo.tensor([[5.0]])
    prediction = model(test)

print("Prediction:", prediction.data)

9.3 Expected Behavior

As training progresses, the loss should generally decrease for this simple dataset and configuration.

The prediction for input 5.0 should move toward:

[ y=2(5)+1=11 ]

The exact prediction depends on the learned parameters and training behavior.

9.4 Training Pipeline

Training Data
     |
     v
Linear Model
     |
     v
Predictions
     |
     v
MSE Loss
     |
     v
Backward Propagation
     |
     v
SGD Parameter Update
     |
     v
Repeat

9.5 Training Considerations

  • The learning rate controls update size.
  • The loss measures prediction error.
  • Backward propagation computes gradients.
  • The optimizer updates parameters.
  • Evaluation should use a separate dataset for realistic applications.

Related: Optimization


10. Tutorial 8 โ€” Adam Optimizer

Difficulty: Intermediate

Objective: Configure adaptive gradient optimization.

10.1 Example

import everyo as eo

model = eo.Sequential(
    eo.Linear(4, 8, seed=0),
    eo.ReLU(),
    eo.Linear(8, 1, seed=1)
)

optimizer = eo.Adam(
    model.parameters(),
    lr=0.001
)

print("Optimizer configured")

10.2 Verified Adam Constructor

Adam(
    parameters,
    lr=0.001,
    *,
    betas=(0.9, 0.999),
    eps=1e-8,
    weight_decay=0.0,
    amsgrad=False
)

10.3 Parameters

Parameter Purpose
parameters Trainable tensors
lr Learning rate
betas Moment decay coefficients
eps Numerical stability term
weight_decay L2 penalty
amsgrad AMSGrad variant

10.4 SGD Versus Adam

Feature SGD Adam
Update Gradient-based Adaptive moment-based
State Optional momentum First and second moments
Default LR 0.01 0.001
Use General optimization Adaptive optimization

These default learning rates are taken from the inspected optimizer implementations.


11. Tutorial 9 โ€” Model Evaluation

Difficulty: Intermediate

Objective: Compare predictions with target values.

11.1 Regression Evaluation

Useful regression metrics include:

  • Mean squared error.
  • Mean absolute error.
  • Root mean squared error.
  • Coefficient of determination.

11.2 MSE Calculation

import everyo as eo

predictions = eo.tensor([
    [2.0],
    [4.0],
    [6.0]
])

targets = eo.tensor([
    [2.5],
    [3.5],
    [5.5]
])

criterion = eo.MSELoss()

loss = criterion(predictions, targets)

print("MSE:", loss.item())

Expected result:

MSE: 0.25

11.3 Evaluation Best Practices

  • Separate training and evaluation data.
  • Avoid data leakage.
  • Use metrics appropriate to the task.
  • Compare against a baseline.
  • Report dataset limitations.
  • Track both training and validation performance.

12. Tutorial 10 โ€” Inference

Difficulty: Intermediate

Objective: Generate predictions without recording unnecessary gradient computations.

12.1 Example

import everyo as eo

model = eo.Sequential(
    eo.Linear(3, 8, seed=0),
    eo.ReLU(),
    eo.Linear(8, 2, seed=1)
)

model.eval()

input_data = eo.tensor([
    [0.5, 1.0, 1.5]
])

with eo.no_grad():
    prediction = model(input_data)

print("Prediction shape:", prediction.shape)
print("Prediction:", prediction.data)

12.2 Expected Shape

(1, 2)

12.3 Why Inference Mode Matters

Evaluation workflows may require:

  • Disabling training-specific layer behavior.
  • Avoiding unnecessary gradient tracking.
  • Reducing computational overhead.
  • Consistent preprocessing.

The eval() method controls module evaluation behavior, while no_grad() controls gradient recording.


13. Reproducibility

Reproducibility helps developers investigate and compare experimental results.

13.1 Important Factors

  • Random initialization.
  • Dataset ordering.
  • Dependency versions.
  • Hardware.
  • Numerical precision.
  • Training hyperparameters.
  • Backend behavior.

13.2 Deterministic Layer Initialization

EveryO's inspected Linear constructor accepts a seed.

import everyo as eo

layer_a = eo.Linear(4, 2, seed=42)
layer_b = eo.Linear(4, 2, seed=42)

This provides a reproducible initialization mechanism for the layer under the same implementation and environment.

13.3 Record Experiment Metadata

Recommended fields:

Field Example
Framework Version 0.2.0
Python Version Installed version
Model Architecture Linear network
Optimizer SGD
Learning Rate 0.01
Epochs 1000
Seed 42
Dataset Experiment-specific

14. Performance and Diagnostics

14.1 Framework Information

everyo info

14.2 Environment Diagnostics

everyo doctor

14.3 Run Tests

python -m pytest

14.4 Performance Considerations

  • Batch size.
  • Tensor dimensions.
  • Numerical precision.
  • Backend selection.
  • Memory allocation.
  • Python overhead.
  • Model complexity.

14.5 Benchmarking

When reporting performance, include:

  • Hardware.
  • Operating system.
  • Python version.
  • EveryO version.
  • Model architecture.
  • Input shape.
  • Number of repetitions.
  • Timing methodology.

15. Common Errors

ModuleNotFoundError: everyo

Confirm the active Python environment and install the package:

python -m pip install -e .
Tensor shape mismatch

Check the input and output dimensions of the operation.

For linear layers, the last input dimension must match in_features.

Gradients are missing

Check whether gradient tracking is enabled and whether the computation uses differentiable operations.

Loss does not decrease

Investigate:

  • Learning rate.
  • Model parameters.
  • Data preprocessing.
  • Gradient calculation.
  • Training loop order.
Training produces NaN values

Check numerical stability, invalid operations, learning rate, and gradient magnitudes.

Optional backend unavailable

Verify installed dependencies, supported hardware, and EveryO backend compatibility.


16. Testing Your Examples

EveryO includes a test suite that developers can use to validate supported functionality.

16.1 Run All Tests

python -m pytest

16.2 Test Categories

Recommended validation includes:

  • Tensor creation.
  • Mathematical operations.
  • Gradient correctness.
  • Layer output shapes.
  • Loss calculations.
  • Optimizer updates.
  • Model evaluation.
  • Serialization.
  • Backend compatibility.

16.3 Regression Testing

When an example fails:

  1. Record the error.
  2. Check the installed version.
  3. Reduce the example to a minimal reproduction.
  4. Compare the relevant API with the source.
  5. Create a focused regression test.
  6. Report unresolved issues.

Report an Issue


17. Additional Learning Resources

Resource Description
Getting Started Introduction and setup
Installation Installation instructions
Quick Start First framework examples
Tensor Engine Numerical operations
Automatic Differentiation Gradients and backpropagation
Neural Networks Model architecture
Optimization Optimizers
Backend System Numerical execution
API Reference Public Python API

Source Code


18. Next Steps

After completing these tutorials, developers can explore more advanced workflows.

Next Page Focus
Model Training Training pipelines and callbacks
Data Pipeline Datasets and preprocessing
Model Serialization Saving and loading models
Performance Optimization Profiling and benchmarking
Contributing Development contributions

Wiki links become active after the corresponding pages are created.


Examples and Tutorials โ€” Documentation Prepared

Next Recommended Page: Model Training โ†’

Home ยท Quick Start ยท API Reference ยท Neural Networks


EveryO โ€” Open Machine Learning. Built for Developers.

Maintained By & Owner:
EveryO Contributors & @krishanth7

Open Source ยท MIT Licensed ยท Community Driven

ยฉ 2026 EveryO Contributors

โš ๏ธ **GitHub.com Fallback** โš ๏ธ