Skip to main content

A basic deep learning package

Project description

A simple neural network implementation which utilizes a simimilar API to TensorFlow's Sequential models.

Description

An in-depth paragraph about your project and overview of use.

Getting Started

Dependencies

  • NumPy
pip3 install -r requirements.txt

Sample Usage

Below is an example of a neural network with two Dense() layers using Tanh() activation functions learning the XOR function. Although seemingly trivial, the XOR function isn't linearly separable, meaning linear models such as logistic regression and single-layer perceptrons cannot learn XOR.

from nn import Sequential, Input, Dense, Tanh

np.random.seed(42)

# XOR input/output data
X = np.reshape([[0, 0], [0, 1], [1, 0], [1, 1]], (4, 2, 1))
Y = np.reshape([[0], [1], [1], [0]], (4, 1, 1))

# Model instantiation
model = Sequential([
    Input(2),
    Dense(3),
    Tanh(),
    Dense(1),
    Tanh(),
])
model.compile()

# Model training
model.fit(X, Y, epochs=10000, learning_rate=0.01)

# Predict
Y_pred = nn.predict(X)
for (y_true, y_pred) in zip(Y, Y_pred):
    print(f'Actual: {y_true}, Predicted: {y_pred}')

Output:

Actual: [[0]], Predicted: [[0.0003956]]
Actual: [[1]], Predicted: [[0.97018558]]
Actual: [[1]], Predicted: [[0.97092169]]
Actual: [[0]], Predicted: [[0.00186825]]

API

Sequential

nn.Sequential(
    layers=[]
)
Function Description
__init__ Instantiates a new Sequential model. If given a list of layers, it will add these to the model, similar to add().
add Add a single layer to the model.
compile Takes the added layers and the parameters of compile to generate a trainable model.
fit After compilation, fit() trains the model on its inputs and outputs.
predict Makes predictions after fitting to the data. Takes in a subset of the input data to make a prediction.

Layers

Layer Layer

Abstract class for the layers API. This shouldn't be used in an instance of a model.

Input Layer

This should always be the first layer of the Sequential model. Since the other layers take in an explicit output_size as their input, they infer their input_size from the previous layer's output_size. This means we must declare the model's first input_size.

Dense Layer

Just your regular densely-connected NN layer. At the moment, the dense layer only performs the dot product and bias addition, but no activation function. The activation function is out-sourced to the Activation layers.

Activation Layer

Applies an activation function to an output.

Tanh Layer

Hyperbolic tangent activation function.

Acknowledgements

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

tensorfaux-0.0.1.tar.gz (154.6 kB view details)

Uploaded Source

Built Distribution

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

tensorfaux-0.0.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file tensorfaux-0.0.1.tar.gz.

File metadata

  • Download URL: tensorfaux-0.0.1.tar.gz
  • Upload date:
  • Size: 154.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.9

File hashes

Hashes for tensorfaux-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f3c8d01e9caec118636152757df90c7afa426e7104fa78dffd7d412fc839fbf4
MD5 3916b558cd5c00ef17ff95a6656af6dd
BLAKE2b-256 d7d2c250f763aa03eceff17de639c6838cf9a5f254f48becb7d7c7ff085a0926

See more details on using hashes here.

File details

Details for the file tensorfaux-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: tensorfaux-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.9

File hashes

Hashes for tensorfaux-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2df937aeca37ecc491a5e6d06b257431fc6d71f8f842eb8c7e462abf1ecddeb2
MD5 6ce3d803e6d20887f346e5642433e0e2
BLAKE2b-256 3598ffe15bad5aca5e74418b9d4c1f2f92245334e2521504a064b562c389cc70

See more details on using hashes here.

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