README.md in tensor_stream-0.1.2 vs README.md in tensor_stream-0.1.3

- old
+ new

@@ -4,14 +4,15 @@ The goal of this gem is to have a high performance machine learning and compute solution for ruby with support for a wide range of hardware and software configuration. ## Features -- Replicates most of the commonly used low-level tensorflow ops +- Replicates most of the commonly used low-level tensorflow ops (tf.add, tf.constant, tf.placeholder, tf.matmul, tf.sin etc...) - Supports auto-differentiation via tf.gradients (mostly) - Provision to use your own opcode evaluator (opencl, sciruby and tensorflow backends planned) - Goal is to be as close to TensorFlow in behavior but with some freedom to add ruby specific enhancements (with lots of test cases) +- eager execution (experimental) Since this is a pure ruby implementation for now, performance is not there yet. However it should be a good enough environment to learn about tensorflow and experiment with some models. ## Installation @@ -89,9 +90,79 @@ puts("Optimization Finished!") training_cost = sess.run(cost, feed_dict: { X => train_X, Y => train_Y}) puts("Training cost=", training_cost, "W=", sess.run(W), "b=", sess.run(b), '\n') puts("time elapsed ", Time.now.to_i - start_time.to_i) end +``` + +## python to ruby guide + +Not all ops are available. Available ops are defined in lib/tensor_stream/ops.rb, corresponding gradients are found at lib/tensor_stream/math_gradients. + +There are also certain differences with regards to naming conventions, and named parameters: + +# Variables + +To make referencing python examples easier it is recommended to use "tf" as the TensorStream namespace + +At the beginning +```ruby +tf = TensorStream # recommended to use tf since most sample models on the net use this +ts = TensorStream # use this if you plan to use TensorStream only features, so other devs will know about that +``` + +Note the difference in named and optional parameters + +Python + +```python +w = tf.Variable(0, name='weights') +w = tf.Variable(0, 'weights') +``` + +Ruby + +```ruby +w =tf.variable(0, name: 'weights') +``` + +# Shapes + +Python +```python +x = tf.placeholder(tf.float32, shape=(1024, 1024)) +x = tf.placeholder(tf.float32, shape=(None, 1024)) +``` + +ruby supports symbols for specifying data types, nil can be used for None + +Ruby +```ruby +x = tf.placeholder(:float32, shape: [1024, 1024]) +x = tf.placeholder(:float32, shape: [nil, 1024]) +``` + +For debugging, each operation or tensor supports the to_math method + +```ruby +X = tf.placeholder("float") +Y = tf.placeholder("float") +W = tf.variable(rand, name: "weight") +b = tf.variable(rand, name: "bias") +pred = X * W + b +cost = tf.reduce_sum(tf.pow(pred - Y, 2)) / ( 2 * 10) +cost.to_math # "(reduce_sum(|((((Placeholder: * weight) + bias) - Placeholder_2:)^2)|) / 10.0)" +``` + +breakpoints can also be set, block will be evaluated during computation + +```ruby +a = tf.constant([2,2]) +b = tf.constant([3,3]) + +f = tf.matmul(a, b).breakpoint! { |tensor, a, b, result_value| binding.pry } + +tf.session.run(f) ``` ## Roadmap - Docs