{"id":13625535,"url":"https://github.com/zemlyansky/gpt-tfjs","last_synced_at":"2025-04-16T06:32:52.650Z","repository":{"id":165079892,"uuid":"631473914","full_name":"zemlyansky/gpt-tfjs","owner":"zemlyansky","description":"GPT in TensorFlow.js","archived":false,"fork":false,"pushed_at":"2023-10-16T20:10:53.000Z","size":41,"stargazers_count":28,"open_issues_count":2,"forks_count":7,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-11-01T15:03:24.284Z","etag":null,"topics":["gpt","tensorflowjs","tfjs","transformers"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/gpt-tfjs","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zemlyansky.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-04-23T06:05:35.000Z","updated_at":"2024-10-15T01:54:28.000Z","dependencies_parsed_at":"2024-08-01T22:02:57.340Z","dependency_job_id":null,"html_url":"https://github.com/zemlyansky/gpt-tfjs","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zemlyansky%2Fgpt-tfjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zemlyansky%2Fgpt-tfjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zemlyansky%2Fgpt-tfjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zemlyansky%2Fgpt-tfjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zemlyansky","download_url":"https://codeload.github.com/zemlyansky/gpt-tfjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223700574,"owners_count":17188349,"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":["gpt","tensorflowjs","tfjs","transformers"],"created_at":"2024-08-01T21:01:57.383Z","updated_at":"2024-11-08T14:31:46.912Z","avatar_url":"https://github.com/zemlyansky.png","language":"JavaScript","funding_links":[],"categories":["others"],"sub_categories":[],"readme":"# GPT in TensorFlow.js (gpt-tfjs)\nA minimal implementation of GPT architecture in TensorFlow.js more or less following the [minGPT](https://github.com/karpathy/minGPT) implementation in PyTorch. \n\n### Installation\n```bash\nnpm i gpt-tfjs\n```\n\n### Example \n```javascript\nconst tf = require('@tensorflow/tfjs') // or @tensorflow/tfjs-node or @tensorflow/tfjs-node-gpu\nconst { GPTLMHeadModel } = require('gpt-tfjs').model\nconst config = {\n  nLayer: 3,\n  nHead: 3,\n  nEmbd: 48,\n  vocabSize: 3,\n  blockSize: 11,\n  dropout: 0.1\n}\n(async () =\u003e {\n  const gpt = GPTLMHeadModel(config)\n  await gpt.train(trainDataset, {epochs: 10, verbose: true})\n  const inputs = [2, 2, 2, 1, 0, 1]\n  const idx = await gpt.generate([inputs], { maxNewTokens: 6 }) // Or gpt.generateSync(..., {...})\n  console.log(idx.arraySync()[0].slice(6)) // [0, 1, 1, 2, 2, 2]\n})()\n```\nWhere `trainDataset` is a tensorflow dataset, for example: [https://github.com/zemlyansky/gpt-tfjs/blob/main/projects/sort/sort.js](https://github.com/zemlyansky/gpt-tfjs/blob/main/projects/sort/sort.js)\n\n### Testing\nThe testing script relies on minGPT to generate the test data. Before running tests run the following command (you'll need Pytorch installed):\n```bash\npython test_gen.py\n```\n\n### Demo\n- [https://jsee.io/gpt2-tfjs/](https://jsee.io/gpt2-tfjs/) - Loading GPT-2 weights from Hugginface and running inference in the browser","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzemlyansky%2Fgpt-tfjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzemlyansky%2Fgpt-tfjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzemlyansky%2Fgpt-tfjs/lists"}