Coder Social home page Coder Social logo

zhutixiaojie0120 / tensorslow Goto Github PK

View Code? Open in Web Editor NEW

This project forked from danielsabinasz/tensorslow

0.0 0.0 0.0 4.63 MB

Re-implementation of TensorFlow in pure python, with an emphasis on code understandability

Home Page: http://www.deepideas.net

Jupyter Notebook 90.19% Python 9.81%

tensorslow's Introduction

TensorSlow

A re-implementation of TensorFlow functionality in pure python

TensorSlow is a minimalist machine learning API that mimicks the TensorFlow API, but is implemented in pure python (without a C backend). The source code has been built with maximal understandability in mind, rather than maximal efficiency. Therefore, TensorSlow should be used solely for educational purposes. If you want to understand how deep learning libraries like TensorFlow work under the hood, this may be your best shot.

I have written an article in my blog at deepideas.net that develops this library step by step, explaining all the math and algorithms on the way: Deep Learning From Scratch.

How to use

Import:

import tensorslow as ts

Create a computational graph:

ts.Graph().as_default()

Create input placeholders:

training_features = ts.placeholder()
training_classes = ts.placeholder()

Build a model:

weights = ts.Variable(np.random.randn(2, 2))
biases = ts.Variable(np.random.randn(2))
model = ts.softmax(ts.add(ts.matmul(X, W), b))

Create training criterion:

loss = ts.negative(ts.reduce_sum(ts.reduce_sum(ts.multiply(training_classes, ts.log(model)), axis=1)))

Create optimizer:

optimizer = ts.train.GradientDescentOptimizer(learning_rate=0.01).minimize(J)

Create placeholder inputs:

feed_dict = {
	training_features: my_training_features,
	training_classes: my_training_classes
}

Create session:

session = ts.Session()

Train:

for step in range(100):
	loss_value = session.run(loss, feed_dict)
	if step % 10 == 0:
		print("Step:", step, " Loss:", loss_value)
	session.run(optimizer, feed_dict)

Retrieve model parameters:

weights_value = session.run(weigths)
biases_value = session.run(biases)

Check out the examples directory for more.

tensorslow's People

Contributors

danielsabinasz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.