Downloads · 30 days
0
akaruineko/pi-predicter
pi-predicter is a machine learning model from akaruineko. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
A neural network model that memorizes and predicts digits of π (pi) using Fourier feature encoding. This model demonstrates the memorization capabilities of MLPs with positional encodings by learning to predict specif…
Downloads · 30 days
0
Access
Public
Updated Aug 25, 2026
Repo size
6.6 MB
Likes
0
Public
Click a slice to open those files.
.pt6.6 MB · 100%
From the Hugging Face model README
A neural network model that memorizes and predicts digits of π (pi) using Fourier feature encoding. This model demonstrates the memorization capabilities of MLPs with positional encodings by learning to predict specific digits of π at given positions.
pi-predicter is a multi-layer perceptron (MLP) that takes a position index as input and predicts the corresponding digit of π at that position. The model uses Fourier feature encoding to transform integer positions into high-dimensional representations, enabling the network to memorize up to 100,000 digits of π.
PiPredictor(
├── Input: position (integer)
├── Fourier Encoding: 16 frequencies → 32-dim vector
├── MLP: 32 → 512 → 512 → 512 → 10
└── Output: digit probability distribution (0-9)
)
Memorization and retrieval of π digits for positions 1-100,000 (after decimal point). The model serves as a demonstration of neural network memorization capabilities and positional encoding techniques.
pip install torch
import torch
from model import PiPredictor
# Load model
checkpoint = torch.load('model.pt', map_location='cpu')
config = checkpoint['config']
# Initialize model
model = PiPredictor(
max_pos=checkpoint['model_max_pos'],
num_frequencies=config['num_frequencies'],
hidden_dims=config['hidden_dims'],
dropout=config['dropout'],
encoding=config['encoding'],
embedding_dim=config['embedding_dim']
)
model.load_state_dict(checkpoint['model_state'])
model.eval()
# Predict digit at position 2 (should be 4: π = 3.14159...)
position = torch.tensor([2], dtype=torch.long)
with torch.no_grad():
logits = model(position)
predicted_digit = torch.argmax(logits, dim=-1).item()
print(f"Digit at position 2: {predicted_digit}") # Output: 4
# Predict multiple positions at once
positions = torch.tensor([1, 2, 3, 4, 5, 10, 100], dtype=torch.long)
with torch.no_grad():
logits = model(positions)
predictions = torch.argmax(logits, dim=-1)
# π = 3.1415926535...
# positions 1-5: [1, 4, 1, 5, 9]
print(predictions.tolist()) # [1, 4, 1, 5, 9, 5, 9]
The model uses Fourier features to transform scalar positions into high-dimensional vectors:
Despite memorizing 100,000 digits, the model achieves this with only ~550k parameters, demonstrating the efficiency of neural networks as lookup tables for structured data.
This model is released under the MIT License.
Note: This model is intended for educational and demonstration purposes, showcasing neural network memorization capabilities rather than mathematical computation. The digits of π are deterministic and can be computed exactly using algorithms; this model demonstrates an alternative approach using machine learning techniques.