{"id":13541475,"url":"https://github.com/tensorflow/haskell","last_synced_at":"2025-05-14T12:11:20.995Z","repository":{"id":50276722,"uuid":"71028374","full_name":"tensorflow/haskell","owner":"tensorflow","description":"Haskell bindings for TensorFlow","archived":false,"fork":false,"pushed_at":"2024-08-15T15:09:36.000Z","size":10161,"stargazers_count":1595,"open_issues_count":39,"forks_count":200,"subscribers_count":87,"default_branch":"master","last_synced_at":"2025-05-08T00:09:45.650Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://tensorflow.github.io/haskell/haddock/","language":"Haskell","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/tensorflow.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-16T03:40:47.000Z","updated_at":"2025-05-07T09:39:16.000Z","dependencies_parsed_at":"2023-02-18T20:16:06.845Z","dependency_job_id":"527e00da-6ae3-4fd1-a195-78f08f7673cd","html_url":"https://github.com/tensorflow/haskell","commit_stats":{"total_commits":189,"total_committers":39,"mean_commits":4.846153846153846,"dds":0.835978835978836,"last_synced_commit":"925c2e95151c0ea1592c26b51a5d98e4ca4a2fe7"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorflow%2Fhaskell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorflow%2Fhaskell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorflow%2Fhaskell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensorflow%2Fhaskell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tensorflow","download_url":"https://codeload.github.com/tensorflow/haskell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254140766,"owners_count":22021220,"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-01T10:00:48.696Z","updated_at":"2025-05-14T12:11:20.934Z","avatar_url":"https://github.com/tensorflow.png","language":"Haskell","readme":"![Build Status](https://storage.googleapis.com/tensorflow-kokoro-build-badges/haskell/github.png)\n\nThe tensorflow-haskell package provides Haskell bindings to\n[TensorFlow](https://www.tensorflow.org/).\n\nThis is not an official Google product.\n\n# Documentation\n\nhttps://tensorflow.github.io/haskell/haddock/\n\n[TensorFlow.Core](https://tensorflow.github.io/haskell/haddock/tensorflow-0.3.0.0/TensorFlow-Core.html)\nis a good place to start.\n\n# Examples\n\nNeural network model for the MNIST dataset: [code](tensorflow-mnist/app/Main.hs)\n\nToy example of a linear regression model\n([full code](tensorflow-ops/tests/RegressionTest.hs)):\n\n```haskell\nimport Control.Monad (replicateM, replicateM_)\nimport System.Random (randomIO)\nimport Test.HUnit (assertBool)\n\nimport qualified TensorFlow.Core as TF\nimport qualified TensorFlow.GenOps.Core as TF\nimport qualified TensorFlow.Minimize as TF\nimport qualified TensorFlow.Ops as TF hiding (initializedVariable)\nimport qualified TensorFlow.Variable as TF\n\nmain :: IO ()\nmain = do\n    -- Generate data where `y = x*3 + 8`.\n    xData \u003c- replicateM 100 randomIO\n    let yData = [x*3 + 8 | x \u003c- xData]\n    -- Fit linear regression model.\n    (w, b) \u003c- fit xData yData\n    assertBool \"w == 3\" (abs (3 - w) \u003c 0.001)\n    assertBool \"b == 8\" (abs (8 - b) \u003c 0.001)\n\nfit :: [Float] -\u003e [Float] -\u003e IO (Float, Float)\nfit xData yData = TF.runSession $ do\n    -- Create tensorflow constants for x and y.\n    let x = TF.vector xData\n        y = TF.vector yData\n    -- Create scalar variables for slope and intercept.\n    w \u003c- TF.initializedVariable 0\n    b \u003c- TF.initializedVariable 0\n    -- Define the loss function.\n    let yHat = (x `TF.mul` TF.readValue w) `TF.add` TF.readValue b\n        loss = TF.square (yHat `TF.sub` y)\n    -- Optimize with gradient descent.\n    trainStep \u003c- TF.minimizeWith (TF.gradientDescent 0.001) loss [w, b]\n    replicateM_ 1000 (TF.run trainStep)\n    -- Return the learned parameters.\n    (TF.Scalar w', TF.Scalar b') \u003c- TF.run (TF.readValue w, TF.readValue b)\n    return (w', b')\n```\n\n# Installation Instructions\n\nNote: building this repository with `stack` requires version `2.3.1` or newer.\nCheck your stack version with `stack --version` in a terminal.\n\n## Build with Docker on Linux\n\nAs an expedient we use [docker](https://www.docker.com/) for building. Once you have docker\nworking, the following commands will compile and run the tests.\n\n```\ngit clone --recursive https://github.com/tensorflow/haskell.git tensorflow-haskell\ncd tensorflow-haskell\ndocker build -t tensorflow/haskell:2.12.0 docker\n# TODO: move the setup step to the docker script.\nstack --docker setup\nstack --docker test\n```\n\nThere is also a demo application:\n\n```\ncd tensorflow-mnist\nstack --docker build --exec Main\n```\n\n### Stack + Docker + GPU\n\nIf you want to use GPU you can do:\n\n```\nIMAGE_NAME=tensorflow/haskell:2.12.0-gpu\ndocker build -t $IMAGE_NAME docker/gpu\n# TODO: move the setup step to the docker script.\nstack --docker --docker-image=$IMAGE_NAME setup\nstack --docker --docker-image=$IMAGE_NAME test\n```\n\n### Using nvidia-docker version 2\nSee [Nvidia docker 2 install instructions](https://github.com/nvidia/nvidia-docker/wiki/Installation-(version-2.0))\n\n```\nstack --docker --docker-image=$IMAGE_NAME setup\nstack --docker --docker-run-args \"--runtime=nvidia\" --docker-image=$IMAGE_NAME test\n```\n\n### Using nvidia-docker classic\n\nStack needs to use `nvidia-docker` instead of the normal `docker` for GPU support. We must wrap 'docker' with a script. This script will shadow the normal `docker` command.\n\n```\nln -s `pwd`/tools/nvidia-docker-wrapper.sh \u003csomewhere in your path\u003e/docker\nstack --docker --docker-image=$IMAGE_NAME setup\nstack --docker --docker-image=$IMAGE_NAME test\n```\n\n## Build on macOS\n\nRun the [install_macos_dependencies.sh](./tools/install_macos_dependencies.sh)\nscript in the `tools/` directory. The script installs dependencies\nvia [Homebrew](https://brew.sh/) and then downloads and installs the TensorFlow\nlibrary on your machine under `/usr/local`.\n\nAfter running the script to install system dependencies, build the project with stack:\n\n    stack test\n\n## Build on NixOS\n\nThe `stack.yaml` file describes a NixOS environment containing the necessary\ndependencies. To build, run:\n\n    $ stack --nix build\n\n## Installation on CentOS\n\n[Xiaokui Shu (@subbyte)](https://github.com/subbyte) maintains [separate instructions for installation on CentOS](https://github.com/subbyte/haskell-learn/blob/master/tensorflow_setup.md).\n\n# Related Projects\n\n## Statically validated tensor shapes\n\nhttps://github.com/helq/tensorflow-haskell-deptyped is experimenting with using dependent types to statically validate tensor shapes. May be merged with this repository in the future.\n\nExample:\n\n```haskell\n{-# LANGUAGE DataKinds, ScopedTypeVariables #-}\n\nimport Data.Maybe (fromJust)\nimport Data.Vector.Sized (Vector, fromList)\nimport TensorFlow.DepTyped\n\ntest :: IO (Vector 8 Float)\ntest = runSession $ do\n  (x :: Placeholder \"x\" '[4,3] Float) \u003c- placeholder\n\n  let elems1 = fromJust $ fromList [1,2,3,4,1,2]\n      elems2 = fromJust $ fromList [5,6,7,8]\n      (w :: Tensor '[3,2] '[] Build Float) = constant elems1\n      (b :: Tensor '[4,1] '[] Build Float) = constant elems2\n      y = (x `matMul` w) `add` b -- y shape: [4,2] (b shape is [4.1] but `add` broadcasts it to [4,2])\n\n  let (inputX :: TensorData \"x\" [4,3] Float) =\n          encodeTensorData . fromJust $ fromList [1,2,3,4,1,0,7,9,5,3,5,4]\n\n  runWithFeeds (feed x inputX :~~ NilFeedList) y\n\nmain :: IO ()\nmain = test \u003e\u003e= print\n```\n\n# License\nThis project is licensed under the terms of the [Apache 2.0 license](LICENSE).\n","funding_links":[],"categories":["Haskell Packages","Haskell"],"sub_categories":["Packages Under Active Development"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftensorflow%2Fhaskell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftensorflow%2Fhaskell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftensorflow%2Fhaskell/lists"}