Skip to main content

A package that provides advanced coding tools for training and deploying AI

Project description

instmodel

instmodel is a Python package designed to simplify the creation of instruction-based neural network models using a Keras backend. With instmodel, you can quickly build, train, and export your models into a compact “instruction” format suitable for lightweight inference, serialization, or deployment.


Features

  • High-Level Model Building: Easily construct neural networks using familiar Keras-like layers such as Dense, Attention, and more.
  • Instruction Model Export: Convert your trained models into a JSON-based “instruction model” that precisely reflects the network architecture, weights, and activations.
  • Validation & Debugging: Verify that the instruction model produces the same outputs as the original Keras model with built-in validation functions.
  • Easy Deployment: Use the exported instruction model for lightweight or custom inference scenarios (e.g., embedded systems).

Installation

Install the latest release from PyPI:

pip install instmodel

Quick Example

Below is a simplified example (adapted from the test suite) showing how to:

  1. Define a feed-forward network using Keras-like syntax.
  2. Train it on dummy data.
  3. Export it as an instruction model.
  4. Validate it against the original Keras model outputs.
import numpy as np
from instmodel.model import (
    Dense,
    InputBuffer,
    ModelGraph,
    ff_model,
    validate_keras_model
)
from instmodel.instruction_model import validate_instruction_model

# 1. Define a simple feed-forward model (three Dense layers).
input_buffer = InputBuffer(4, name="simple_input")
hidden = Dense(8, activation="relu", name="hidden_relu_1")(input_buffer)
hidden = Dense(6, activation="relu", name="hidden_relu_2")(hidden)
output = Dense(1, activation="sigmoid", name="output_sigmoid")(hidden)

model_graph = ModelGraph(input_buffer, output)
model_graph.compile(optimizer="adam", loss="binary_crossentropy")

# 2. Train the model on dummy data.
x_data = np.random.random((10, 4))
y_data = np.random.randint(0, 2, size=(10, 1))
model_graph.fit(x_data, y_data, epochs=1, verbose=0)

# 3. Export the trained Keras model to an instruction model.
instruction_model = model_graph.create_instruction_model()

# 4. Validate the exported instruction model against the original Keras outputs.
keras_pred = model_graph.predict(x_data, verbose=0)
instruction_model["validation_data"] = {
    "inputs": x_data.tolist(),
    "expected_outputs": keras_pred.tolist(),
}

validate_instruction_model(instruction_model)  # Check instruction-model output
validate_keras_model(model_graph.get_keras(), instruction_model["validation_data"])  # Compare with Keras model

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

instmodel-0.6.0.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

instmodel-0.6.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file instmodel-0.6.0.tar.gz.

File metadata

  • Download URL: instmodel-0.6.0.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for instmodel-0.6.0.tar.gz
Algorithm Hash digest
SHA256 e1cb372b27e3fb2de7793eaad70baa32f05d44867f00b6008e79bcd98d33a440
MD5 3872846fed96a93c2acdcbd9f37d7dca
BLAKE2b-256 8da5ac938c324f7d9d3e244aed174833f80f412769bba45ea3e02fb7707fe0f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for instmodel-0.6.0.tar.gz:

Publisher: pypi-publish.yml on Joaoprcf/instmodel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file instmodel-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: instmodel-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for instmodel-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d83ec257fcd37688658a01dc419728f3cc93cb1c14a17d3e7f46e814cc641c15
MD5 b95671f4dd18d681abd02c2cee076379
BLAKE2b-256 c66806da6609fc231fededa70e1f7bdf89606a96af8969359a03e32df4994021

See more details on using hashes here.

Provenance

The following attestation bundles were made for instmodel-0.6.0-py3-none-any.whl:

Publisher: pypi-publish.yml on Joaoprcf/instmodel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page