Skip to main content

A neural network library built on top of TensorFlow for quickly building deep learning models.

Build Status

Usage

nn.Tensor is the core data structure which is a wrapper for tf.Tensor and provides additional functionality. It can be created using the nn.tensor() function:

import nn

a = nn.tensor([1, 2, 3])
assert isinstance(a, nn.Tensor)
assert a.shape == (3, )

It supports method chaining:

c = a.square().sum()
assert c.numpy() == 14

and can be used with tf.Tensor objects:

import tensorflow as tf

b = tf.constant(2)
c = (a - b).square().sum()
assert c.numpy() == 2

It can also be used with high level APIs such as tf.keras:

model = nn.Sequential([
  nn.Dense(128, activation='relu'),
  nn.Dropout(0.2),
  nn.Dense(10)
])

y = model(x)
assert isinstance(y, nn.Tensor)

and to perform automatic differentiation and optimization:

optimizer = nn.Adam()
with nn.GradientTape() as tape:
    outputs = model(inputs)
    loss = (targets - outputs).square().mean()
grads = tape.gradient(loss, model.trainable_variables)
optimizer.apply_gradients(zip(grads, model.trainable_variables))

To use it with ops that expect tf.Tensor objects as inputs, wrap the ops using nn.op():

mean = nn.op(tf.reduce_mean)
c = mean(a)
assert isinstance(c, nn.Tensor)

maximum = nn.op(tf.maximum, binary=True)
c = maximum(a, b)
assert isinstance(c, nn.Tensor)

or convert it to a tf.Tensor object using the tf() method or nn.tf() function:

b = a.tf()
assert isinstance(b, tf.Tensor)

b = nn.tf(a)
assert isinstance(b, tf.Tensor)

See more examples here.

Installation

Requirements:

  • TensorFlow >= 2.0
  • Python >= 3.6

Install from PyPI (recommended):

pip install nn

Alternatively, install from source:

git clone https://github.com/marella/nn.git
cd nn
pip install -e .

TensorFlow should be installed separately.

Testing

To run tests, install dependencies:

pip install -e .[tests]

and run:

pytest tests

Metadata

Release files for nn 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nn 0.1.1
File Size Uploaded Provenance
nn-0.1.1.tar.gz 5.0 kB Without provenance Details

Release files / nn-0.1.1.tar.gz

Download URL nn-0.1.1.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1c364054b0859d97ba1b600c95eb2992ef55701e8eeb6a3911db86b868937967
BLAKE2b-256 checksum
How to use checksums
b32ab00995cba3fda79210c0002355925b45a3abf882c2b3c42b5275dc6708df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.8.0 tqdm/4.20.0 CPython/3.6.4

Security for nn 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page