{"id":16390889,"url":"https://github.com/lwch/tnn","last_synced_at":"2025-07-28T11:05:47.696Z","repository":{"id":151768286,"uuid":"624304825","full_name":"lwch/tnn","owner":"lwch","description":"go版本机器学习框架","archived":false,"fork":false,"pushed_at":"2025-05-08T12:29:26.000Z","size":38638,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"gotorch","last_synced_at":"2025-05-08T12:34:22.837Z","etag":null,"topics":["ai","cnn","deep-learning","golang","mlp","neural-network","rnn"],"latest_commit_sha":null,"homepage":"","language":"Go","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/lwch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2023-04-06T07:15:01.000Z","updated_at":"2025-05-08T12:29:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"fd3e8ea9-1a49-4f32-82a3-6129387366e8","html_url":"https://github.com/lwch/tnn","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/lwch/tnn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwch%2Ftnn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwch%2Ftnn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwch%2Ftnn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwch%2Ftnn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lwch","download_url":"https://codeload.github.com/lwch/tnn/tar.gz/refs/heads/gotorch","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lwch%2Ftnn/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267505099,"owners_count":24098346,"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","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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","cnn","deep-learning","golang","mlp","neural-network","rnn"],"created_at":"2024-10-11T04:44:35.306Z","updated_at":"2025-07-28T11:05:47.626Z","avatar_url":"https://github.com/lwch.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tnn\n\ngo版本神经网络框架，支持模型训练和推理，libgotorch库的安装方式请看[libgotorch安装](https://github.com/lwch/gotorch#%E5%AE%89%E8%A3%85)\n\n## 工具\n\n- ~~[minfo](cmd/minfo/): 这是tnn框架中的一个工具，用于查看保存模型的定义信息~~\n\n## 示例\n\n- [xor](example/xor/): 该示例是一个四层的神经网络，用于训练异或运算（回归）\n- [sin](example/sin/): 该示例使用rnn网络来进行sin函数的时序任务训练（回归）\n- [sin_attention](example/sin_attention/): 使用transformer来实现sin曲线的预测（回归）\n- [couplet](example/couplet/): 使用GPT模型来对对联（回归）\n\n## 构造网络\n\n首先定义网络的每个层\n\n```go\nhiddenLayer := layer.NewDense(10)\nrelu := activation.NewReLU()\noutputLayer := layer.NewDense(1)\n```\n\n选定一个优化器\n\n```go\noptimizer := optimizer.NewAdam()\n```\n\n定义forward函数\n\n```go\nfunc forward(x *tensor.Tensor) *tensor.Tensor {\n    y := hiddenLayer.Forward(x)\n    y = relu.Forward(y)\n    y = outputLayer.Forward(y)\n    return y\n}\n```\n\n最后构造出模型并进行模型训练\n\n```go\nfor i := 0; i \u003c 10; i++ {\n    loss := loss.NewMse(forward(input), output)\n    loss.Backward()\n    optimizer.Step(net.Params())\n    fmt.Printf(\"Epoch: %d, Loss: %.05f\\n\", i, loss.Value())\n}\n```\n\n模型推理方法如下\n\n```go\npred := forward(input)\nfmt.Println(pred.Float32Value())\n```\n\n## 感谢\n\n- [tinynn](https://github.com/borgwang/tinynn)\n- [gonum](https://github.com/gonum/gonum)\n- [pytorch](https://pytorch.org)\n- [cobra](github.com/spf13/cobra)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flwch%2Ftnn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flwch%2Ftnn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flwch%2Ftnn/lists"}