{"id":13879409,"url":"https://github.com/ankane/tensorflow-ruby","last_synced_at":"2025-09-12T07:30:52.142Z","repository":{"id":51445194,"uuid":"209236152","full_name":"ankane/tensorflow-ruby","owner":"ankane","description":"Deep learning for Ruby","archived":false,"fork":false,"pushed_at":"2023-12-26T14:50:20.000Z","size":239,"stargazers_count":369,"open_issues_count":2,"forks_count":13,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-05-19T03:00:34.833Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankane.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-09-18T06:37:23.000Z","updated_at":"2024-05-08T16:18:55.000Z","dependencies_parsed_at":"2024-01-05T21:59:46.884Z","dependency_job_id":null,"html_url":"https://github.com/ankane/tensorflow-ruby","commit_stats":null,"previous_names":["ankane/tensorflow"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Ftensorflow-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Ftensorflow-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Ftensorflow-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Ftensorflow-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/tensorflow-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232704373,"owners_count":18563735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T08:02:20.081Z","updated_at":"2025-01-06T10:10:02.441Z","avatar_url":"https://github.com/ankane.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# TensorFlow Ruby\n\n:fire: [TensorFlow](https://github.com/tensorflow/tensorflow) - the end-to-end machine learning platform - for Ruby\n\nThis gem is currently experimental and only supports basic tensor operations at the moment. Check out [Torch.rb](https://github.com/ankane/torch-rb) for a more complete deep learning library.\n\nTo run a TensorFlow model in Ruby, [convert it to ONNX](https://github.com/onnx/tensorflow-onnx) and use [ONNX Runtime](https://github.com/ankane/onnxruntime). Check out [this tutorial](https://ankane.org/tensorflow-ruby) for a full example.\n\n[![Build Status](https://github.com/ankane/tensorflow-ruby/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/tensorflow-ruby/actions)\n\n## Installation\n\n[Install TensorFlow](#tensorflow-installation). For Homebrew, use:\n\n```sh\nbrew install libtensorflow\n```\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem \"tensorflow\"\n```\n\n## Getting Started\n\nThis library follows the TensorFlow 2 [Python API](https://www.tensorflow.org/api_docs/python/tf). Many methods and options are missing at the moment. Here’s the [current plan](https://github.com/ankane/tensorflow/issues/1). Additional PRs welcome!\n\n## Constants\n\n```ruby\na = Tf.constant([1, 2, 3])\nb = Tf.constant([4, 5, 6])\na + b\n```\n\n## Variables\n\n```ruby\nv = Tf::Variable.new(0.0)\nw = v + 1\n```\n\n## Math\n\n```ruby\nTf::Math.abs([-1, -2])\nTf::Math.sqrt([1.0, 4.0, 9.0])\n```\n\n## FizzBuzz\n\n```ruby\ndef fizzbuzz(max_num)\n  max_num.times do |i|\n    num = Tf.constant(i + 1)\n    if (num % 3).to_i == 0 \u0026\u0026 (num % 5).to_i == 0\n      puts \"FizzBuzz\"\n    elsif (num % 3).to_i == 0\n      puts \"Fizz\"\n    elsif (num % 5).to_i == 0\n      puts \"Buzz\"\n    else\n      puts num.to_i\n    end\n  end\nend\n\nfizzbuzz(15)\n```\n\n## Data::Dataset\n\n```ruby\n# load\ntrain_dataset = Tf::Data::Dataset.from_tensor_slices([train_examples, train_labels])\ntest_dataset = Tf::Data::Dataset.from_tensor_slices([test_examples, test_labels])\n\n# shuffle and batch\ntrain_dataset = train_dataset.shuffle(100).batch(32)\ntest_dataset = test_dataset.batch(32)\n\n# iterate\ntrain_dataset.each do |examples, labels|\n  # ...\nend\n```\n\n## Keras [coming soon]\n\n```ruby\nmnist = Tf::Keras::Datasets::MNIST\n(x_train, y_train), (x_test, y_test) = mnist.load_data\nx_train = x_train / 255.0\nx_test = x_test / 255.0\n\nmodel = Tf::Keras::Models::Sequential.new([\n  Tf::Keras::Layers::Flatten.new(input_shape: [28, 28]),\n  Tf::Keras::Layers::Dense.new(128, activation: \"relu\"),\n  Tf::Keras::Layers::Dropout.new(0.2),\n  Tf::Keras::Layers::Dense.new(10, activation: \"softmax\")\n])\n\nmodel.compile(optimizer: \"adam\", loss: \"sparse_categorical_crossentropy\", metrics: [\"accuracy\"])\nmodel.fit(x_train, y_train, epochs: 5)\nmodel.evaluate(x_test, y_test)\n```\n\n## TensorFlow Installation\n\n### Mac\n\nRun:\n\n```sh\nbrew install tensorflow\n```\n\nAlternatively, download the [shared library](https://www.tensorflow.org/install/lang_c#download) and move the files in `lib` to `/usr/local/lib`.\n\n### Linux\n\nDownload the [shared library](https://www.tensorflow.org/install/lang_c#download) and move the files in `lib` to `/usr/local/lib`.\n\n### Windows\n\nDownload the [shared library](https://www.tensorflow.org/install/lang_c#download) and move `tensorflow.dll` to `C:\\Windows\\System32`.\n\n## History\n\nView the [changelog](https://github.com/ankane/tensorflow-ruby/blob/master/CHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/ankane/tensorflow-ruby/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/tensorflow-ruby/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development:\n\n```sh\ngit clone https://github.com/ankane/tensorflow-ruby.git\ncd tensorflow-ruby\nbundle install\nbundle exec rake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Ftensorflow-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Ftensorflow-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Ftensorflow-ruby/lists"}