I generated this program with the help of AI to create model weights from Ulises Carrión's 1975 text "The New Art of Making Books." Read more here. ~MS
A Python tool that generates deterministic neural network weights from input text. The weights are initialized using Xavier/Glorot initialization and can be saved in multiple formats.
- Python 3.x
- NumPy
- Pandas (for CSV output)
Install the required packages:
pip3 install numpy pandaspython3 text_to_weights.py <input_text_file> [--format FORMAT] [--output-dir DIR]input_text_file: Path to the text file to generate weights from--format: Output format (choices: 'npy', 'txt', 'csv', default: 'npy')--output-dir: Output directory (default: 'weights')
The program supports three output formats, organized in format-specific subdirectories:
-
NPY Format (weights/npy/)
- Binary NumPy format
- Most efficient for loading in Python
- Example:
weights/npy/layer_0.npy
-
TXT Format (weights/txt/)
- Plain text, comma-separated values
- Human-readable
- Example:
weights/txt/layer_0.txt
-
CSV Format (weights/csv/)
- Comma-separated values with headers
- Compatible with spreadsheet software
- Example:
weights/csv/layer_0.csv
Generate weights in NPY format:
python3 text_to_weights.py input.txtGenerate weights in CSV format:
python3 text_to_weights.py input.txt --format csvUse custom output directory:
python3 text_to_weights.py input.txt --format txt --output-dir my_weightsThe program generates three weight matrices with the following dimensions:
- Layer 1: 128 x 64
- Layer 2: 64 x 32
- Layer 3: 32 x 16
Each layer's weights are initialized using Xavier/Glorot initialization for better neural network training characteristics.
# Load NPY format
import numpy as np
weights = np.load('weights/npy/layer_0.npy')
# Load TXT format
weights = np.loadtxt('weights/txt/layer_0.txt', delimiter=',')
# Load CSV format
import pandas as pd
weights = pd.read_csv('weights/csv/layer_0.csv').values- Deterministic weight generation (same input text produces same weights)
- Multiple output formats for different use cases
- Xavier/Glorot initialization for better neural network training
- Organized directory structure by format
- Configurable layer sizes
Run the test suite:
python3 -m unittest test_text_to_weights.py -v