{"id":19389012,"url":"https://github.com/gorgonia/parser","last_synced_at":"2025-04-23T23:31:55.452Z","repository":{"id":57501777,"uuid":"128369803","full_name":"gorgonia/parser","owner":"gorgonia","description":"A simple parser that turns a formulae written in unicode into an ExprGraph","archived":false,"fork":false,"pushed_at":"2022-10-08T08:15:32.000Z","size":22,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-02T22:33:08.514Z","etag":null,"topics":["golang","gorgonia","goyacc","parser","unicode"],"latest_commit_sha":null,"homepage":null,"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/gorgonia.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}},"created_at":"2018-04-06T08:33:21.000Z","updated_at":"2025-01-07T02:50:42.000Z","dependencies_parsed_at":"2022-09-19T08:50:29.302Z","dependency_job_id":null,"html_url":"https://github.com/gorgonia/parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gorgonia%2Fparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gorgonia%2Fparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gorgonia%2Fparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gorgonia%2Fparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gorgonia","download_url":"https://codeload.github.com/gorgonia/parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250532178,"owners_count":21446133,"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":["golang","gorgonia","goyacc","parser","unicode"],"created_at":"2024-11-10T10:14:32.156Z","updated_at":"2025-04-23T23:31:55.146Z","avatar_url":"https://github.com/gorgonia.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![](https://godoc.org/github.com/gorgonia/parser?status.svg)](http://godoc.org/github.com/gorgonia/parser)\n[![Report card](https://goreportcard.com/badge/github.com/gorgonia/parser)](https://goreportcard.com/report/github.com/gorgonia/parser)\n\n# About\n\nThe goal of this project is to parse a mathematical formulae written in unicode and to transpile is into an `ExprGraph` of the Gorgonia project.\n\n## Principle\n\nThis parser is generated from a `yacc` file from the subdirectory `src`.\nIf you want to contribute or add some new functionalities, you may need the `goyacc` tool and then run `go generate` from the `src` dubdirectory.\nFor a more complete explanation, you can refer to this [blog post](https://blog.owulveryck.info/2017/12/18/parsing-mathematical-equation-to-generate-computation-graphs---first-step-from-software-1.0-to-2.0-in-go.html)\n\n## Available operations\n\nAs of today, the parser understands the following opreations on node objects (tensor based):\n\n| Operation          | Gorgonia Operation                                                   | Symbol  | Unicode character |\n|--------------------|----------------------------------------------------------------------|---------|-------------------|\n| Multiplication     | [Mul](https://godoc.org/gorgonia.org/gorgonia#Mul)                   | ·       | U+00B7            |\n| Hadamard Product   | [HadamardProd](https://godoc.org/gorgonia.org/gorgonia#HadamardProd) | *       |                   |\n| Addition           | [Add](https://godoc.org/gorgonia.org/gorgonia#Add)                   | +       |                   |\n| Substraction       | [Sub](https://godoc.org/gorgonia.org/gorgonia#Sub)                   | -       |                   |\n| Pointwise Negation | [Neg](https://godoc.org/gorgonia.org/gorgonia#Neg)                   | -       |                   |\n| Sigmoid            | [Sigmoid](https://godoc.org/gorgonia.org/gorgonia#Sigmoid)           | σ       | U+03C3            |\n| Tanh               | [Tanh](https://godoc.org/gorgonia.org/gorgonia#Tanh)                 | tanh    |                   |\n| Softmax            | [Softmax](https://godoc.org/gorgonia.org/gorgonia#Softmax)           | softmax |                   |\n\n## Example\n\n```go\nimport (\n\tG \"gorgonia.org/gorgonia\"\n\t\"github.com/gorgonia/parser\"\n\t\"gorgonia.org/tensor\"\n)\n\nfunc main(){\n\tg := G.NewGraph()\n\twfT := tensor.New(tensor.WithShape(2, 2), tensor.WithBacking([]float32{1, 1, 1, 1}))\n\twf := G.NewMatrix(g, tensor.Float32, G.WithName(\"wf\"), G.WithShape(2, 2), G.WithValue(wfT))\n\thtprevT := tensor.New(tensor.WithBacking([]float32{1, 1}), tensor.WithShape(2))\n\thtprev := G.NewVector(g, tensor.Float32, G.WithName(\"ht-1\"), G.WithShape(2), G.WithValue(htprevT))\n\txtT := tensor.New(tensor.WithBacking([]float32{1, 1}), tensor.WithShape(2))\n\txt := G.NewVector(g, tensor.Float32, G.WithName(\"xt\"), G.WithShape(2), G.WithValue(xtT))\n\tbfT := tensor.New(tensor.WithBacking([]float32{1, 1}), tensor.WithShape(2))\n\tbf := G.NewVector(g, tensor.Float32, G.WithName(\"bf\"), G.WithShape(2), G.WithValue(bfT))\n\n\tp := parser.NewParser(g)\n\tp.Set(`Wf`, wf)\n\tp.Set(`h`, htprev)\n\tp.Set(`x`, xt)\n\tp.Set(`bf`, bf)\n        result, _ := p.Parse(`σ(1*Wf·h+ Wf·x+ bf)`)\n        machine := G.NewLispMachine(g, G.ExecuteFwdOnly())\n        if err := machine.RunAll(); err != nil {\n              t.Fatal(err)\n        }\n        res := result.Value().Data().([]float32)\n}\n```\n\n# Caution\n\n* The parser is internally using a `map` and is not concurrent safe.\n* The errors are not handle correctly\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgorgonia%2Fparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgorgonia%2Fparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgorgonia%2Fparser/lists"}