Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A simple parser that turns a formulae written in unicode into an ExprGraph

License

NotificationsYou must be signed in to change notification settings

gorgonia/parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Report card

About

The goal of this project is to parse a mathematical formulae written in unicode and to transpile is into anExprGraph of the Gorgonia project.

Principle

This parser is generated from ayacc file from the subdirectorysrc.If you want to contribute or add some new functionalities, you may need thegoyacc tool and then rungo generate from thesrc dubdirectory.For a more complete explanation, you can refer to thisblog post

Available operations

As of today, the parser understands the following opreations on node objects (tensor based):

OperationGorgonia OperationSymbolUnicode character
MultiplicationMul·U+00B7
Hadamard ProductHadamardProd*
AdditionAdd+
SubstractionSub-
Pointwise NegationNeg-
SigmoidSigmoidσU+03C3
TanhTanhtanh
SoftmaxSoftmaxsoftmax

Example

import (G"gorgonia.org/gorgonia""github.com/gorgonia/parser""gorgonia.org/tensor")funcmain(){g:=G.NewGraph()wfT:=tensor.New(tensor.WithShape(2,2),tensor.WithBacking([]float32{1,1,1,1}))wf:=G.NewMatrix(g,tensor.Float32,G.WithName("wf"),G.WithShape(2,2),G.WithValue(wfT))htprevT:=tensor.New(tensor.WithBacking([]float32{1,1}),tensor.WithShape(2))htprev:=G.NewVector(g,tensor.Float32,G.WithName("ht-1"),G.WithShape(2),G.WithValue(htprevT))xtT:=tensor.New(tensor.WithBacking([]float32{1,1}),tensor.WithShape(2))xt:=G.NewVector(g,tensor.Float32,G.WithName("xt"),G.WithShape(2),G.WithValue(xtT))bfT:=tensor.New(tensor.WithBacking([]float32{1,1}),tensor.WithShape(2))bf:=G.NewVector(g,tensor.Float32,G.WithName("bf"),G.WithShape(2),G.WithValue(bfT))p:=parser.NewParser(g)p.Set(`Wf`,wf)p.Set(`h`,htprev)p.Set(`x`,xt)p.Set(`bf`,bf)result,_:=p.Parse(`σ(1*Wf·h+ Wf·x+ bf)`)machine:=G.NewLispMachine(g,G.ExecuteFwdOnly())iferr:=machine.RunAll();err!=nil {t.Fatal(err)        }res:=result.Value().Data().([]float32)}

Caution

  • The parser is internally using amap and is not concurrent safe.
  • The errors are not handle correctly

About

A simple parser that turns a formulae written in unicode into an ExprGraph

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp