[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-HuwCampbell--grenade":3,"tool-HuwCampbell--grenade":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",160411,2,"2026-04-18T23:33:24",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",109154,"2026-04-18T11:18:24",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":75,"owner_location":76,"owner_email":75,"owner_twitter":75,"owner_website":77,"owner_url":78,"languages":79,"stars":92,"forks":93,"last_commit_at":94,"license":95,"difficulty_score":96,"env_os":97,"env_gpu":98,"env_ram":99,"env_deps":100,"category_tags":109,"github_topics":110,"view_count":32,"oss_zip_url":75,"oss_zip_packed_at":75,"status":17,"created_at":117,"updated_at":118,"faqs":119,"releases":149},9483,"HuwCampbell\u002Fgrenade","grenade","Deep Learning in Haskell","Grenade 是一个专为 Haskell 语言设计的深度学习库，专注于构建高效、可组合的循环神经网络（RNN）。它主要解决了在静态类型语言中定义复杂神经网络时，难以在编译期确保网络结构正确性和数据维度匹配的问题。通过引入依赖类型技术，Grenade 将网络层级与数据形状（如 1D 向量、2D 图像、3D 张量）直接编码进类型系统中。这意味着如果层与层之间的数据维度不兼容，代码将无法通过编译，从而在运行前就消除了大量潜在的维度错误。\n\n该工具特别适合熟悉 Haskell 的开发者、函数式编程爱好者以及希望利用强类型系统保障模型严谨性的研究人员使用。其核心技术亮点在于“异构列表”设计：网络的类型定义不仅包含层结构，还完整描述了数据在各层间的流转形态。用户只需几行代码即可精确定义如卷积神经网络或 LSTM 等复杂架构，无需编写繁琐的底层维度检查逻辑。虽然名字带有“手榴弹”的戏谑意味，暗示其强大威力，但 Grenade 实际上为构建安全、精确且高性能的神经网络提供了一套优雅的类型安全方案。","Grenade\n=======\n\n[![Build Status](https:\u002F\u002Fapi.travis-ci.org\u002FHuwCampbell\u002Fgrenade.svg?branch=master)](https:\u002F\u002Ftravis-ci.org\u002FHuwCampbell\u002Fgrenade)\n[![Hackage page (downloads and API reference)][hackage-png]][hackage]\n[![Hackage-Deps][hackage-deps-png]][hackage-deps]\n\n\n```\nFirst shalt thou take out the Holy Pin, then shalt thou count to three, no more, no less.\nThree shall be the number thou shalt count, and the number of the counting shall be three.\nFour shalt thou not count, neither count thou two, excepting that thou then proceed to three.\nFive is right out.\n```\n\n💣 Machine learning which might blow up in your face 💣\n\nGrenade is a composable, dependently typed, practical, and fast recurrent neural network library\nfor concise and precise specifications of complex networks in Haskell.\n\nAs an example, a network which can achieve ~1.5% error on MNIST can be\nspecified and initialised with random weights in a few lines of code with\n```haskell\ntype MNIST\n  = Network\n    '[ Convolution 1 10 5 5 1 1, Pooling 2 2 2 2, Relu\n     , Convolution 10 16 5 5 1 1, Pooling 2 2 2 2, Reshape, Relu\n     , FullyConnected 256 80, Logit, FullyConnected 80 10, Logit]\n    '[ 'D2 28 28\n     , 'D3 24 24 10, 'D3 12 12 10 , 'D3 12 12 10\n     , 'D3 8 8 16, 'D3 4 4 16, 'D1 256, 'D1 256\n     , 'D1 80, 'D1 80, 'D1 10, 'D1 10]\n\nrandomMnist :: MonadRandom m => m MNIST\nrandomMnist = randomNetwork\n```\n\nAnd that's it. Because the types are so rich, there's no specific term level code\nrequired to construct this network; although it is of course possible and\neasy to construct and deconstruct the networks and layers explicitly oneself.\n\nIf recurrent neural networks are more your style, you can try defining something\n[\"unreasonably effective\"](http:\u002F\u002Fkarpathy.github.io\u002F2015\u002F05\u002F21\u002Frnn-effectiveness\u002F)\nwith\n```haskell\ntype Shakespeare\n  = RecurrentNetwork\n    '[ R (LSTM 40 80), R (LSTM 80 40), F (FullyConnected 40 40), F Logit]\n    '[ 'D1 40, 'D1 80, 'D1 40, 'D1 40, 'D1 40 ]\n```\n\nDesign\n------\n\nNetworks in Grenade can be thought of as a heterogeneous lists of layers, where\ntheir type includes not only the layers of the network, but also the shapes of\ndata that are passed between the layers.\n\nThe definition of a network is surprisingly simple:\n```haskell\ndata Network :: [*] -> [Shape] -> * where\n    NNil  :: SingI i\n          => Network '[] '[i]\n\n    (:~>) :: (SingI i, SingI h, Layer x i h)\n          => !x\n          -> !(Network xs (h ': hs))\n          -> Network (x ': xs) (i ': h ': hs)\n```\n\nThe `Layer x i o` constraint ensures that the layer `x` can sensibly perform a\ntransformation between the input and output shapes `i` and `o`.\n\nThe lifted data kind `Shape` defines our 1, 2, and 3 dimension types, used to\ndeclare what shape of data is passed between the layers.\n\nIn the MNIST example above, the input layer can be seen to be a two dimensional\n(`D2`), image with 28 by 28 pixels. When the first *Convolution* layer runs, it\noutputs a three dimensional (`D3`) 24x24x10 image. The last item in the list is\none dimensional (`D1`) with 10 values, representing the categories of the MNIST\ndata.\n\nUsage\n-----\n\nTo perform back propagation, one can call the eponymous function\n```haskell\nbackPropagate :: forall shapes layers.\n                 Network layers shapes -> S (Head shapes) -> S (Last shapes) -> Gradients layers\n```\nwhich takes a network, appropriate input and target data, and returns the\nback propagated gradients for the network. The shapes of the gradients are\nappropriate for each layer, and may be trivial for layers like `Relu` which\nhave no learnable parameters.\n\nThe gradients however can always be applied, yielding a new (hopefully better)\nlayer with\n```haskell\napplyUpdate :: LearningParameters -> Network ls ss -> Gradients ls -> Network ls ss\n```\n\nLayers in Grenade are represented as Haskell classes, so creating one's own is\neasy in downstream code. If the shapes of a network are not specified correctly\nand a layer can not sensibly perform the operation between two shapes, then\nit will result in a compile time error.\n\nComposition\n-----------\n\nNetworks and Layers in Grenade are easily composed at the type level. As a `Network`\nis an instance of `Layer`, one can use a trained Network as a small component in a\nlarger network easily. Furthermore, we provide 2 layers which are designed to run\nlayers in parallel and merge their output (either by concatenating them across one\ndimension or summing by pointwise adding their activations). This allows one to\nwrite any Network which can be expressed as a\n[series parallel graph](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSeries-parallel_graph).\n\nA residual network layer specification for instance could be written as\n```haskell\ntype Residual net = Merge Trivial net\n```\nIf the type `net` is an instance of `Layer`, then `Residual net` will be too. It will\nrun the network, while retaining its input by passing it through the `Trivial` layer,\nand merge the original image with the output.\n\nSee the [MNIST](https:\u002F\u002Fgithub.com\u002FHuwCampbell\u002Fgrenade\u002Fblob\u002Fmaster\u002Fexamples\u002Fmain\u002Fmnist.hs)\nexample, which has been overengineered to contain both residual style learning as well\nas inception style convolutions.\n\nGenerative Adversarial Networks\n-------------------------------\n\nAs Grenade is purely functional, one can compose its training functions in flexible\nways. [GAN-MNIST](https:\u002F\u002Fgithub.com\u002FHuwCampbell\u002Fgrenade\u002Fblob\u002Fmaster\u002Fexamples\u002Fmain\u002Fgan-mnist.hs)\nexample displays an interesting, type safe way of writing a generative adversarial\ntraining function in 10 lines of code.\n\nLayer Zoo\n---------\n\nGrenade layers are normal haskell data types which are an instance of `Layer`, so\nit's easy to build one's own downstream code. We do however provide a decent set\nof layers, including convolution, deconvolution, pooling, pad, crop, logit, relu,\nelu, tanh, and fully connected.\n\nBuild Instructions\n------------------\nGrenade is most easily built with the [mafia](https:\u002F\u002Fgithub.com\u002Fambiata\u002Fmafia)\nscript that is located in the repository. You will also need the `lapack` and\n`blas` libraries and development tools. Once you have all that, Grenade can be\nbuild using:\n\n```\n.\u002Fmafia build\n```\n\nand the tests run using:\n\n```\n.\u002Fmafia test\n```\n\nGrenade builds with ghc 7.10, 8.0, 8.2 and 8.4.\n\nThanks\n------\nWriting a library like this has been on my mind for a while now, but a big shout\nout must go to [Justin Le](https:\u002F\u002Fgithub.com\u002Fmstksg), whose\n[dependently typed fully connected network](https:\u002F\u002Fblog.jle.im\u002Fentry\u002Fpractical-dependent-types-in-haskell-1.html)\ninspired me to get cracking, gave many ideas for the type level tools I\nneeded, and was a great starting point for writing this library.\n\nPerformance\n-----------\nGrenade is backed by hmatrix, BLAS, and LAPACK, with critical functions optimised\nin C. Using the im2col trick popularised by Caffe, it should be sufficient for\nmany problems.\n\nBeing purely functional, it should also be easy to run batches in parallel, which\nwould be appropriate for larger networks, my current examples however are single\nthreaded.\n\nTraining 15 generations over Kaggle's 41000 sample MNIST training set on a single\ncore took around 12 minutes, achieving 1.5% error rate on a 1000 sample holdout set.\n\nContributing\n------------\nContributions are welcome.\n\n [hackage]: http:\u002F\u002Fhackage.haskell.org\u002Fpackage\u002Fgrenade\n [hackage-png]: http:\u002F\u002Fimg.shields.io\u002Fhackage\u002Fv\u002Fgrenade.svg\n [hackage-deps]: http:\u002F\u002Fpackdeps.haskellers.com\u002Freverse\u002Fgrenade\n [hackage-deps-png]: https:\u002F\u002Fimg.shields.io\u002Fhackage-deps\u002Fv\u002Fgrenade.svg\n","手榴弹\n=======\n\n[![构建状态](https:\u002F\u002Fapi.travis-ci.org\u002FHuwCampbell\u002Fgrenade.svg?branch=master)](https:\u002F\u002Ftravis-ci.org\u002FHuwCampbell\u002Fgrenade)\n[![Hackage 页面（下载量和 API 参考）][hackage-png]][hackage]\n[![Hackage 依赖][hackage-deps-png]][hackage-deps]\n\n\n```\n首先你必须取出圣针，然后你要数到三，不多也不少。\n三就是你要数的数字，而计数的次数也必须是三。\n四你不能数，二也不能数，除非你接着数到三。\n五绝对不行。\n```\n\n💣 可能会让你大吃一惊的机器学习 💣\n\nGrenade 是一个可组合、依赖类型、实用且快速的循环神经网络库，\n用于在 Haskell 中简洁而精确地定义复杂的神经网络。\n\n例如，一个在 MNIST 数据集上能达到约 1.5% 错误率的网络，\n只需几行代码即可用随机权重进行定义和初始化：\n```haskell\ntype MNIST\n  = Network\n    '[ Convolution 1 10 5 5 1 1, Pooling 2 2 2 2, Relu\n     , Convolution 10 16 5 5 1 1, Pooling 2 2 2 2, Reshape, Relu\n     , FullyConnected 256 80, Logit, FullyConnected 80 10, Logit]\n    '[ 'D2 28 28\n     , 'D3 24 24 10, 'D3 12 12 10 , 'D3 12 12 10\n     , 'D3 8 8 16, 'D3 4 4 16, 'D1 256, 'D1 256\n     , 'D1 80, 'D1 80, 'D1 10, 'D1 10]\n\nrandomMnist :: MonadRandom m => m MNIST\nrandomMnist = randomNetwork\n```\n\n仅此而已。由于类型非常丰富，无需特定的运行时代码来构造这个网络；\n当然，也可以轻松地显式地构造和拆解网络及层。\n\n如果你更喜欢循环神经网络，可以尝试定义一些“不合理有效”的东西：\n```haskell\ntype Shakespeare\n  = RecurrentNetwork\n    '[ R (LSTM 40 80), R (LSTM 80 40), F (FullyConnected 40 40), F Logit]\n    '[ 'D1 40, 'D1 80, 'D1 40, 'D1 40, 'D1 40 ]\n```\n\n设计\n------\n\nGrenade 中的网络可以被视为由不同类型的层组成的异构列表，\n其类型不仅包含网络的各层，还包含了层间传递的数据形状。\n\n网络的定义非常简单：\n```haskell\ndata Network :: [*] -> [Shape] -> * where\n    NNil  :: SingI i\n          => Network '[] '[i]\n\n    (:~>) :: (SingI i, SingI h, Layer x i h)\n          => !x\n          -> !(Network xs (h ': hs))\n          -> Network (x ': xs) (i ': h ': hs)\n```\n\n`Layer x i o` 约束确保层 `x` 能够合理地在输入形状 `i` 和输出形状 `o` 之间进行变换。\n\n提升后的数据种类 `Shape` 定义了我们的 1、2 和 3 维类型，\n用于声明层间传递的数据形状。\n\n在上面的 MNIST 示例中，输入层是一个二维（`D2`）图像，大小为 28×28 像素。\n当第一个 *卷积* 层运行时，它会输出一个三维（`D3`）图像，大小为 24×24×10。\n列表中的最后一项是一维（`D1`），包含 10 个值，代表 MNIST 数据的类别。\n\n使用\n-----\n\n为了执行反向传播，可以调用同名函数\n```haskell\nbackPropagate :: forall shapes layers.\n                 Network layers shapes -> S (Head shapes) -> S (Last shapes) -> Gradients layers\n```\n该函数接受一个网络、适当的输入和目标数据，并返回网络的反向传播梯度。\n梯度的形状与每一层相匹配，对于像 `Relu` 这样没有可学习参数的层来说，梯度可能是空的。\n\n然而，这些梯度总是可以应用的，从而产生一个新的（希望更好的）层：\n```haskell\napplyUpdate :: LearningParameters -> Network ls ss -> Gradients ls -> Network ls ss\n```\n\nGrenade 中的层以 Haskell 类的形式表示，因此在下游代码中很容易创建自定义层。\n如果网络的形状指定不正确，导致某一层无法在两个形状之间合理地执行操作，\n则会在编译时引发错误。\n\n组合\n------\n\nGrenade 中的网络和层可以在类型级别轻松组合。由于 `Network` 是 `Layer` 的实例，\n因此可以将训练好的网络作为大型网络中的一个小组件轻松使用。\n此外，我们还提供了两种层，旨在并行运行多个层并将它们的输出合并起来\n（可以通过在一个维度上连接它们，或通过逐点相加激活值来实现）。\n这使得我们可以编写任何可以用\n[串并联图](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSeries-parallel_graph) 表示的网络。\n\n例如，残差网络层的定义可以写成：\n```haskell\ntype Residual net = Merge Trivial net\n```\n如果类型 `net` 是 `Layer` 的实例，那么 `Residual net` 也将是。它会运行该网络，\n同时通过 `Trivial` 层保留输入，并将原始图像与输出合并。\n\n请参阅 [MNIST](https:\u002F\u002Fgithub.com\u002FHuwCampbell\u002Fgrenade\u002Fblob\u002Fmaster\u002Fexamples\u002Fmain\u002Fmnist.hs) 示例，\n该示例经过过度工程化，既包含了残差风格的学习，也包含了 inception 风格的卷积。\n\n生成对抗网络\n-------------\n\n由于 Grenade 是纯函数式的，因此可以灵活地组合其训练函数。\n[GAN-MNIST](https:\u002F\u002Fgithub.com\u002FHuwCampbell\u002Fgrenade\u002Fblob\u002Fmaster\u002Fexamples\u002Fmain\u002Fgan-mnist.hs) 示例展示了一种有趣且类型安全的方式，\n仅用 10 行代码就能写出一个生成对抗训练函数。\n\n层动物园\n---------\n\nGrenade 的层是普通的 Haskell 数据类型，同时也是 `Layer` 的实例，\n因此很容易在下游代码中构建自己的层。不过，我们也提供了一系列不错的层，\n包括卷积、反卷积、池化、填充、裁剪、logit、relu、elu、tanh 和全连接层。\n\n构建说明\n---------\nGrenade 最容易通过位于仓库中的 [mafia](https:\u002F\u002Fgithub.com\u002Fambiata\u002Fmafia) 脚本进行构建。\n你还需要 `lapack` 和 `blas` 库以及开发工具。准备好这些之后，\n就可以使用以下命令构建 Grenade：\n\n```\n.\u002Fmafia build\n```\n\n并使用以下命令运行测试：\n\n```\n.\u002Fmafia test\n```\n\nGrenade 支持 ghc 7.10、8.0、8.2 和 8.4 版本。\n\n致谢\n------\n编写这样的库一直在我脑海中酝酿已久，但我要特别感谢 [Justin Le](https:\u002F\u002Fgithub.com\u002Fmstksg)，\n他的\n[依赖类型全连接网络](https:\u002F\u002Fblog.jle.im\u002Fentry\u002Fpractical-dependent-types-in-haskell-1.html)\n激励我开始动手，为我提供了许多关于所需类型级工具的想法，\n并成为编写这个库的一个极佳起点。\n\n性能\n-----\nGrenade 后端使用 hmatrix、BLAS 和 LAPACK，并对关键函数进行了 C 语言优化。\n借助 Caffe 推广的 im2col 技巧，它应该足以应对许多问题。\n\n由于它纯粹是功能性的，因此也应该很容易并行运行批处理，这对于较大的网络来说是合适的。不过，我目前的示例仍然是单线程的。\n\n在 Kaggle 的 41000 个样本 MNIST 训练集上，使用单核训练 15 代大约花了 12 分钟，在 1000 个样本的保留集中达到了 1.5% 的错误率。\n\n贡献\n------------\n欢迎贡献。\n\n[hackage]: http:\u002F\u002Fhackage.haskell.org\u002Fpackage\u002Fgrenade\n[hackage-png]: http:\u002F\u002Fimg.shields.io\u002Fhackage\u002Fv\u002Fgrenade.svg\n[hackage-deps]: http:\u002F\u002Fpackdeps.haskellers.com\u002Freverse\u002Fgrenade\n[hackage-deps-png]: https:\u002F\u002Fimg.shields.io\u002Fhackage-deps\u002Fv\u002Fgrenade.svg","# Grenade 快速上手指南\n\nGrenade 是一个基于 Haskell 的组合式、依赖类型（dependently typed）循环神经网络库。它允许开发者通过类型系统精确地定义复杂的网络结构，并在编译期检查维度匹配，从而构建安全且高效的深度学习模型。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**: Linux 或 macOS (Windows 需通过 WSL 或类似环境)。\n*   **Haskell 编译器**: 支持 GHC 7.10, 8.0, 8.2 或 8.4 版本。\n*   **底层数学库**: 必须安装 `BLAS` 和 `LAPACK` 库及其开发头文件。\n    *   **Ubuntu\u002FDebian**: `sudo apt-get install libblas-dev liblapack-dev`\n    *   **macOS (Homebrew)**: `brew install openblas lapack`\n*   **构建工具**: 项目推荐使用仓库自带的 `mafia` 脚本进行构建管理。\n\n> **提示**：国内用户若遇到 Hackage 包下载缓慢的问题，建议配置清华大学或中国科学技术大学的 Haskell 镜像源以加速依赖安装。\n\n## 安装步骤\n\nGrenade 推荐通过源码并使用其内置的 `mafia` 脚本进行构建，以确保依赖版本的一致性。\n\n1.  **克隆仓库**\n    ```bash\n    git clone https:\u002F\u002Fgithub.com\u002FHuwCampbell\u002Fgrenade.git\n    cd grenade\n    ```\n\n2.  **构建项目**\n    执行以下命令编译库：\n    ```bash\n    .\u002Fmafia build\n    ```\n\n3.  **运行测试（可选）**\n    验证安装是否成功：\n    ```bash\n    .\u002Fmafia test\n    ```\n\n## 基本使用\n\nGrenade 的核心优势在于通过类型定义网络结构。以下是一个最简单的示例，展示如何定义并初始化一个用于 MNIST 手写数字识别的卷积神经网络。\n\n### 1. 定义网络结构\n\n在 Haskell 代码中，通过类型别名定义网络层序列和数据形状变化：\n\n```haskell\ntype MNIST\n  = Network\n    '[ Convolution 1 10 5 5 1 1, Pooling 2 2 2 2, Relu\n     , Convolution 10 16 5 5 1 1, Pooling 2 2 2 2, Reshape, Relu\n     , FullyConnected 256 80, Logit, FullyConnected 80 10, Logit]\n    '[ 'D2 28 28\n     , 'D3 24 24 10, 'D3 12 12 10 , 'D3 12 12 10\n     , 'D3 8 8 16, 'D3 4 4 16, 'D1 256, 'D1 256\n     , 'D1 80, 'D1 80, 'D1 10, 'D1 10]\n```\n\n*   第一行列表定义了层类型（如卷积、池化、全连接等）。\n*   第二行列表定义了每一层输入\u002F输出的数据维度（`D2` 为 2D 图像，`D3` 为 3D 张量，`D1` 为向量）。\n*   如果层与层之间的维度不匹配，代码将无法通过编译。\n\n### 2. 初始化网络\n\n利用随机权重初始化网络实例：\n\n```haskell\nrandomMnist :: MonadRandom m => m MNIST\nrandomMnist = randomNetwork\n```\n\n### 3. 训练步骤\n\nGrenade 提供了函数式的训练原语。典型的训练步骤包括计算梯度和应用更新：\n\n*   **反向传播**：计算梯度\n    ```haskell\n    backPropagate :: forall shapes layers.\n                     Network layers shapes -> S (Head shapes) -> S (Last shapes) -> Gradients layers\n    ```\n    传入网络、输入数据和目标标签，返回各层的梯度。\n\n*   **应用更新**：根据梯度更新网络权重\n    ```haskell\n    applyUpdate :: LearningParameters -> Network ls ss -> Gradients ls -> Network ls ss\n    ```\n    传入学习率参数、当前网络和计算出的梯度，返回更新后的新网络。\n\n由于 Grenade 是纯函数式的，网络更新不会修改原对象，而是返回一个新的网络状态，这使得组合复杂的训练逻辑（如 GAN 或残差网络）变得非常灵活且类型安全。","某函数式编程团队正在为金融风控系统构建一个高可靠性的时序预测模型，要求代码在编译阶段就能杜绝维度不匹配的错误。\n\n### 没有 grenade 时\n- **运行时崩溃风险高**：在传统深度学习框架中，神经网络层之间的输入输出维度错误往往要等到模型训练启动后才会暴露，导致宝贵的计算资源浪费。\n- **重构成本巨大**：当需要调整网络结构（如增加卷积层或修改池化大小）时，开发者必须手动追踪并修改每一层的数据形状定义，极易出错。\n- **类型安全缺失**：缺乏编译期的形状检查，无法利用 Haskell 强大的类型系统来保证数据流转的逻辑正确性，只能依赖繁琐的单元测试。\n- **代码冗长且易读性差**：为了显式管理张量形状和层间连接，需要编写大量样板代码，掩盖了核心的算法逻辑。\n\n### 使用 grenade 后\n- **编译期绝对安全**：grenade 利用依赖类型技术，将数据形状（如 28x28 图像或 10 维向量）嵌入类型定义，若层间维度不匹配，代码根本无法通过编译。\n- **极简的网络定义**：只需几行代码即可通过异构列表声明复杂的卷积或循环神经网络（如 LSTM），无需手动编写任何底层形状转换逻辑。\n- **无忧的结构重构**：修改网络架构时，编译器会自动推导并验证所有受影响的层级形状，开发者可大胆调整结构而无需担心隐性错误。\n- **逻辑与数据合一**：网络定义即包含了完整的数据流拓扑，代码即文档，显著提升了复杂模型的可维护性和可读性。\n\ngrenade 通过将深度学习中的形状校验提前至编译阶段，让 Haskell 开发者能以数学般的严谨度构建零运行时错误的神经网络。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FHuwCampbell_grenade_77ea7326.png","HuwCampbell","Huw Campbell","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002FHuwCampbell_b2b98eef.png",null,"Australia","https:\u002F\u002Fhuwcampbell.com\u002F","https:\u002F\u002Fgithub.com\u002FHuwCampbell",[80,84,88],{"name":81,"color":82,"percentage":83},"Haskell","#5e5086",95.3,{"name":85,"color":86,"percentage":87},"C","#555555",3.8,{"name":89,"color":90,"percentage":91},"Shell","#89e051",0.9,1453,82,"2026-03-05T14:34:11","BSD-2-Clause",4,"未说明 (需支持 GHC 及 BLAS\u002FLAPACK 的系统，通常为 Linux\u002FmacOS)","未说明 (基于 CPU 的 BLAS\u002FLAPACK，示例提及单核运行，未提及 CUDA 或 GPU 加速)","未说明",{"notes":101,"python":102,"dependencies":103},"该工具是使用 Haskell 编写的机器学习库，非 Python 项目。构建时需要安装 BLAS 和 LAPACK 库及其开发工具。推荐使用仓库中的 mafia 脚本进行构建和测试。性能依赖于底层的 C 语言优化（通过 hmatrix 调用 BLAS\u002FLAPACK），目前示例为单线程运行。","不适用 (基于 Haskell)",[104,105,106,107,108],"GHC 7.10 - 8.4","hmatrix","BLAS","LAPACK","mafia (构建工具)",[14],[111,112,113,114,115,116],"machine-learning","deep-neural-networks","haskell","deep-learning","generative-adversarial-networks","convolutional-neural-networks","2026-03-27T02:49:30.150509","2026-04-19T15:38:19.509332",[120,125,130,135,140,145],{"id":121,"question_zh":122,"answer_zh":123,"source_url":124},42521,"使用 `mafia build` 构建项目时因警告（warnings）导致失败怎么办？","Mafia 工具对警告非常严格，默认启用 `-Wall` 并将警告视为错误。如果构建因警告失败，可以添加 `-w` 标志来忽略警告并继续构建，命令为：`mafia build -w`。\n\n维护者说明：Mafia 旨在设置正确的沙盒环境，之后通常可以使用标准的 `cabal` 命令进行编译。由于使用了高级 GHC 特性，在不同版本间保持无警告代码较为困难，因此临时忽略警告是可行的解决方案。","https:\u002F\u002Fgithub.com\u002FHuwCampbell\u002Fgrenade\u002Fissues\u002F82",{"id":126,"question_zh":127,"answer_zh":128,"source_url":129},42522,"如何在同一个网络中结合使用循环层（Recurrent\u002FLSTM）和拼接层（Concat）？","要在递归网络中并行运行多个 LSTM 并拼接结果，需要使用专门的 `ConcatRecurrent` 构造器，而不是普通的 `Concat`。\n\n示例代码如下：\n```haskell\ntype R = Recurrent\ntype F = FeedForward\n\ntype ShapeInput = 'D1 10\n\ntype LearnPlayer = RecurrentNetwork '[ R (LSTM 10 20) ] '[ ShapeInput , D1 20 ]\ntype LearnOpponent = RecurrentNetwork '[ R (LSTM 10 20) ] '[ ShapeInput, D1 20 ]\n\ntype RecNet = RecurrentNetwork\n    '[ R (\n        ConcatRecurrent\n          (D1 20)\n          (R LearnPlayer)\n          (D1 20)\n          (R LearnOpponent)\n        )\n    ]\n   '[ ShapeInput, 'D1 40 ]\n\nrandomNet :: MonadRandom m => m RecNet\nrandomNet = randomRecurrent\n```\n注意：运行此类网络时，需要使用 `runRecurrentForwards` 和 `runRecurrentBackwards` 等专用函数，而非普通的运行函数。","https:\u002F\u002Fgithub.com\u002FHuwCampbell\u002Fgrenade\u002Fissues\u002F30",{"id":131,"question_zh":132,"answer_zh":133,"source_url":134},42523,"Grenade 是否支持 OpenCL 或 GPU 加速以达到类似 PyTorch 的性能？","目前 Grenade 没有原生的 OpenCL 或 GPU 后端支持。\n\n关于未来的可能性：\n1. 社区曾讨论过依赖 `accelerate` 库来开发 OpenCL 后端，但这需要更多的人力资源投入。\n2. 另一种潜在路径是利用 `hmatrix` 的不同 BLAS 后端，但 `hmatrix` 对 3D 和 4D 矩阵的支持较弱。\n3. 维护者认为 Haskell 生态需要一个更强大的新 NDArray 库来更好地支持此类高性能计算，但目前该功能暂无具体的行动计划。","https:\u002F\u002Fgithub.com\u002FHuwCampbell\u002Fgrenade\u002Fissues\u002F55",{"id":136,"question_zh":137,"answer_zh":138,"source_url":139},42524,"如何处理 MNIST 数据集？应该使用 CSV 文件还是原始二进制文件？数据需要归一化吗？","建议直接使用 MNIST 的原始二进制数据（可从 http:\u002F\u002Fyann.lecun.com\u002Fexdb\u002Fmnist\u002F 获取），以保证可比性。虽然项目中存在 CSV 文件，但那只是为了方便教学（避免处理解压等步骤）。\n\n关于数据格式：\n1. 原始数据是字节字符串（byte strings）。\n2. 文件中的值通常**没有**归一化到 `[0..1.0]` 范围。\n3. 用户需要使用 `ByteString` 轻松解码压缩的 `.gz` 数据，并根据需要自行进行归一化处理。","https:\u002F\u002Fgithub.com\u002FHuwCampbell\u002Fgrenade\u002Fissues\u002F94",{"id":141,"question_zh":142,"answer_zh":143,"source_url":144},42525,"Grenade 库是否已经发布到 Hackage？如何安装？","是的，Grenade 已经正式发布到 Hackage。\n\n你可以通过标准的 Cabal 或 Stack 命令进行安装：\n- 包地址：http:\u002F\u002Fhackage.haskell.org\u002Fpackage\u002Fgrenade\n- 安装命令示例：`cabal install grenade` 或在 stack.yaml 中添加对应版本。\n\n此前为了发布，项目已移除了子模块依赖并完成了清理工作。","https:\u002F\u002Fgithub.com\u002FHuwCampbell\u002Fgrenade\u002Fissues\u002F5",{"id":146,"question_zh":147,"answer_zh":148,"source_url":139},42526,"遇到 \"Wrong category of family instance\" 编译错误该如何解决？","该错误通常发生在 GHC 版本不匹配时（例如在 GHC 8.8+ 中使用旧版代码）。\n\n错误信息示例：\n```\n• Wrong category of family instance; declaration was for a type family\n• In the data instance declaration for'Sing'\n```\n\n解决方案：\n1. 检查你的 GHC 版本与项目要求的版本是否一致。\n2. 确保你使用的是与当前 GHC 版本兼容的 `base` 库和 `singletons` 库版本。\n3. 如果是在较新的 GHC 上构建旧代码，可能需要更新类型族实例的定义语法，或者升级 Grenade 到支持新 GHC 版本的分支。",[150],{"id":151,"version":152,"summary_zh":153,"released_at":154},342281,"v0.1.0","初始发布","2017-12-18T22:35:35"]