{"id":35183592,"url":"https://github.com/nguyenphuminh/catniff","last_synced_at":"2026-04-18T06:10:52.864Z","repository":{"id":302506484,"uuid":"1012717316","full_name":"nguyenphuminh/catniff","owner":"nguyenphuminh","description":"Torch-like deep learning framework for Javascript","archived":false,"fork":false,"pushed_at":"2026-04-02T09:16:34.000Z","size":465,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-08T19:37:10.652Z","etag":null,"topics":["ai","autodiff","autograd","catniff","deep-learning","dl","framework","gradient","library","machine-learning","maths","micrograd","ml","neural-network","pytorch","tensors","tinygrad","torch"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/nguyenphuminh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-02T19:10:59.000Z","updated_at":"2026-04-02T09:16:05.000Z","dependencies_parsed_at":"2025-08-28T13:37:10.883Z","dependency_job_id":"2803d137-75dc-411a-b9d0-9e41f12859d8","html_url":"https://github.com/nguyenphuminh/catniff","commit_stats":null,"previous_names":["nguyenphuminh/catniff"],"tags_count":64,"template":false,"template_full_name":null,"purl":"pkg:github/nguyenphuminh/catniff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nguyenphuminh%2Fcatniff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nguyenphuminh%2Fcatniff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nguyenphuminh%2Fcatniff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nguyenphuminh%2Fcatniff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nguyenphuminh","download_url":"https://codeload.github.com/nguyenphuminh/catniff/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nguyenphuminh%2Fcatniff/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31782740,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T02:24:21.117Z","status":"ssl_error","status_checked_at":"2026-04-14T02:24:20.627Z","response_time":153,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ai","autodiff","autograd","catniff","deep-learning","dl","framework","gradient","library","machine-learning","maths","micrograd","ml","neural-network","pytorch","tensors","tinygrad","torch"],"created_at":"2025-12-29T04:17:51.454Z","updated_at":"2026-04-18T06:10:52.858Z","avatar_url":"https://github.com/nguyenphuminh.png","language":"TypeScript","funding_links":[],"categories":["JavaScript"],"sub_categories":["[Tools](#tools-1)"],"readme":"# Catniff 😺🌿\r\n\r\nCatniff is a small deep learning framework for Javacript, built to be Torch-like, but more direct on tensors and autograd usage like Tinygrad. This project is under development currently, so keep in mind that APIs can be unstable and backwards-incompatible. On a side-note, the name is a play on \"catnip\" and \"differentiation\".\r\n\r\n## Setup\r\n\r\nInstall through npm:\r\n```\r\nnpm install catniff\r\n```\r\n\r\nEnsure you have Node v24 as well for things like float16 to work.\r\n\r\n## Tensors\r\n\r\nTensors in Catniff can be created by passing in a number or an nD array, and there are built-in methods that can be used to perform tensor arithmetic:\r\n```js\r\nconst { Tensor } = require(\"catniff\");\r\n\r\n// Tensor init\r\nconst A = new Tensor([ 1, 2, 3 ]);\r\nconst B = new Tensor(3);\r\n\r\n// Tensor addition (.val() returns the raw value rather than the tensor object)\r\nconsole.log(A.add(B).val());\r\n```\r\n\r\n## Autograd\r\n\r\nTo compute the gradient wrt multiple variables of our mathematical expression, we can simply set `requiresGrad` to `true`:\r\n```js\r\nconst { Tensor } = require(\"catniff\");\r\n\r\nconst X = new Tensor(\r\n    [\r\n        [ 0.5, -1.0 ],\r\n        [ 2.0,  0.0 ]\r\n    ],\r\n    { requiresGrad: true }\r\n);\r\n\r\nconst Y = new Tensor(\r\n    [\r\n        [ 1.0, -2.0 ],\r\n        [ 0.5,  1.5 ]\r\n    ],\r\n    { requiresGrad: true }\r\n);\r\n\r\nconst D = X.sub(Y);\r\nconst E = D.exp();\r\nconst F = E.add(1);\r\nconst G = F.log();\r\n\r\nG.backward();\r\n\r\n// X.grad and Y.grad are tensor objects themselves, so we call .val() here to see their raw values\r\nconsole.log(X.grad.val(), Y.grad.val());\r\n```\r\n\r\n## Optimizer\r\n\r\nCatniff comes bundled with optimizers as well:\r\n```js\r\nconst { Tensor, Optim } = require(\"catniff\");\r\n\r\n// Define some parameter\r\nconst w = new Tensor([1.0], { requiresGrad: true });\r\n// Define a fake loss function: L = (w - 3)^2\r\nconst loss = w.sub(3).pow(2);\r\n// Calculate gradient\r\nloss.backward();\r\n// Use Adam optimizer\r\nconst optim = new Optim.Adam([w]);\r\n// Optimization step\r\noptim.step();\r\n\r\nconsole.log(\"Updated weight:\", w.data);  // Should move toward 3.0\r\n```\r\n\r\n## Neural networks \u0026 Deep learning\r\n\r\nThere are built-in neural network constructs in Catniff as well, from simple prebuilt nn layers:\r\n```js\r\nconst { Tensor, nn } = require(\"catniff\");\r\n\r\n// Linear layer with input size of 20 and output size of 10\r\nconst linear = nn.Linear(20, 10);\r\n// RNN cell with input size of 32 and hidden size of 64\r\nconst rnnCell = nn.RNNCell(32, 64);\r\n// Same thing but using GRU\r\nconst gruCell = nn.GRUCell(32, 64);\r\n// Same thing but using LSTM\r\nconst lstmCell = nn.LSTMCell(32, 64);\r\n\r\n// Forward passes\r\nconst a = Tensor.randn([20]);\r\nconst b = Tensor.randn([32]);\r\nconst c = Tensor.randn([64]);\r\n\r\nlinear.forward(a);\r\nrnnCell.forward(b, c);\r\ngruCell.forward(b, c);\r\nlstmCell.forward(b, c, c);\r\n```\r\n\r\nto more advanced constructs like normalization, embedding, and attention:\r\n```js\r\n// 1. Embedding: tokens -\u003e vectors\r\nconst embedding = new nn.Embedding(100, 64);\r\nconst tokens = new Tensor([[1, 5, 23], [8, 2, 15]]);\r\nconst embedded = embedding.forward(tokens);\r\n\r\n// 2. Self-Attention\r\nconst attention = new nn.MultiheadAttention(64, 8, 0.1);\r\nconst [output, weights] = attention.forward(embedded, embedded, embedded);\r\n\r\n// 3. Layer Normalization\r\nconst layerNorm = new nn.LayerNorm(64);\r\nconst normalized = layerNorm.forward(output);\r\n\r\nconsole.log(normalized.val());\r\n```\r\n\r\nAnd it can still do much more, check out the docs and examples below for more information.\r\n\r\n## Documentation\r\n\r\nFull documentation is available in [`./docs/documentation.md`](./docs/documentation.md).\r\n\r\nAll available APIs are in [`./src/`](./src/) if you want to dig deeper.\r\n\r\n## Examples\r\n\r\n* [Shakespeare-style text generator](https://github.com/nguyenphuminh/shakespeare-lm).\r\n* [Simple neural net for XOR calculation](./examples/xornet.js).\r\n* [N-th order derivative calculation](./examples/nthorder.js).\r\n* [Tensors](./examples/tensors.js).\r\n* [Optimizer](./examples/optim.js).\r\n* [Simple quadratic equation](./examples/quadratic.js).\r\n\r\n## Todos\r\n\r\n* More general tensor ops.\r\n* More general neural net APIs.\r\n* GPU acceleration, possibly through WebGPU, Libtorch bindings, or CUDA.\r\n* Proper optimization.\r\n* More detailed documentation.\r\n* Code refactoring.\r\n* Proper tests.\r\n\r\n## Cite Catniff\r\n\r\n```bibtex\r\n@misc{catniff,\r\n  author = {Phu Minh Nguyen},\r\n  title = {Catniff: Torch-like deep learning framework for Javascript},\r\n  year = {2025},\r\n  publisher = {GitHub},\r\n  url = {https://github.com/nguyenphuminh/catniff}\r\n}\r\n```\r\n\r\n## Copyrights and License\r\n\r\nCopyrights © 2025 Nguyen Phu Minh.\r\n\r\nThis project is licensed under the Apache 2.0 license.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnguyenphuminh%2Fcatniff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnguyenphuminh%2Fcatniff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnguyenphuminh%2Fcatniff/lists"}