hikettei / cl-waffe Goto Github PK
View Code? Open in Web Editor NEW[Deprecated] Common Lisp Differentiable Matrix Operations for Mathematical Optimization.
Home Page: https://hikettei.github.io/cl-waffe-docs/
License: MIT License
[Deprecated] Common Lisp Differentiable Matrix Operations for Mathematical Optimization.
Home Page: https://hikettei.github.io/cl-waffe-docs/
License: MIT License
In the function trainer:
(defun valid (trainer dataset batch-size)
"Valid trainer"
(let ((count 0)
(correct 0))
(loop for index fixnum upfrom 0 below (get-dataset-length dataset) by batch-size
do (let* ((ds (get-dataset dataset index))
(x (car ds))
(y (second ds))
(out (const (value (call (slot-value trainer 'model) x))))
(out-labels (!argmax out))
(y-labels (!argmax (const (copy-mat (data y)))))) ; <--- Here
(with-facets ((out-labels ((data out-labels) 'backing-array :direction :input))
(y-labels ((data y-labels) 'backing-array :direction :input)))
(loop for i below (length out-labels)
do (progn
(incf count 1)
(if (= (aref out-labels i) (aref y-labels i))
(incf correct 1)
(incf correct 0)))))))
(format t "Accuracy:~a~C" (coerce (/ correct count) 'float) #\newline)))
This creates y's copy every time otherwise y-labels' value is not updated.
I guess this is due to accessing the wrong facets or something like that.
hmm
(defmodel Encoder (vocab-size embedding-dim hidden-size)
:parameters ((embedding (Embedding vocab-size embedding-dim :pad-idx 0))
(layer (RNN embedding-dim hidden-size :num-layers 1)))
:forward ((x)
(with-calling-layers x
(embedding x)
(layer x))))
(defmodel Decoder (vocab-size embedding-dim hidden-size)
:parameters ((embedding (Embedding vocab-size embedding-dim :pad-idx 0))
(layer (RNN embedding-dim hidden-size :num-layers 1))
(h2l (linearlayer hidden-size vocab-size)))
:forward ((encoder-state y)
(let* ((ye (call (self embedding) y))
(hs (call (self layer) ye encoder-state))
(h-output (call (self h2l) hs)))
h-output)))
(defmodel Seq2Seq (vocab-size-lang1 vocab-size-lang2 embedding-dim input-size)
:parameters ((encoder (Encoder vocab-size-lang1 embedding-dim input-size))
(decoder (Decoder vocab-size-lang2 embedding-dim input-size)))
:forward ((x y)
(let ((x-state (call (self encoder) x)))
(call (self decoder)
x-state
(!aref y t '(0 -1))))))```
こんな感じのSeq2Seqがあって、
```lisp
(setq model (Seq2Seq 1000 1000 100 100))
vocab_sizeを1000以上で初期化して、学習を進めると2~3回で勾配爆発を起こす
LinearLayer/Embeddingの重みの初期値は適切だと思うんだけど、どこが悪いんだぁ〜ぐあぁ〜〜
The total lines of files like ‘tensor. lisp’, ‘operators. lisp’ is too large and for example algorithms like sampling beta shouldn't write in that file.
Move them into /distributions, activations.lisp, copy.lisp
To Do: define it with using lazy-evaluation
FP16とか使いたいんだがねぇ・・・
Almost features are based on mgl-mat so it is not going to be a rocky road.
If possible, I want backends to support FP16
Optimize the overhead of generic functions It's done.call-forward
/call-backward
(Less Important)
make print-object rich(Done)
As of this writing, all matrices in cl-waffe is a type of mgl-mat, even if I enter simple-array, cl-waffe coerces it to mgl-mat. However, The only part that depends on mgl-mat is the standard implementation. Considering with-backend
allows to use other matrix operation libraries, it would be more reasonable not to restricted the datastructure of matrix.
sorry for being written in Japanese...
defnode-backendみたいなマクロを作る。←このマクロはdefnodeで定義されたマクロのバックエンドを拡張する。
バックエンドはシンボルで管理されていて、(display-backend)関数で定義されたバックエンド一覧とノードの数を表示する。
define-node-methodのcall-forward/call-backwardでカーネルを割り当てる。
カーネルが存在しない場合はcl-waffe標準の:mglカーネルで計算。
そのためテンソルの型などは変更しない、他のライブラリで使うときはfacetを作ってもらう。
→numericals等他のライブラリに拡張できるようにする。
→他のバックエンドのバージョンを:cl-waffe-openclみたいに別のライブラリとして書けるようにする
To update the computation nodes, (setf !aref) needed to be called like:
(setq tensor (setf (!aref tensor ~) x))
This should be rewritten with macro, being easy to cause mistakes.
(defgeneric call (self &rest inputs))
みたいに書き換えればいいのでは・・・
Tensorデータ型やBackendは全てdefparameterを参照しているから
(with-config (:dtype :float)
(:backends (:simd :numcl :mgl)) ; Backendの優先順位
...)```
みたいなマクロでまとめて設定できると便利そう。FP16対応する方法思いついたら作ろっかな〜
(!beta `(10 10) 1.0 1.0)
;arithmetic error FLOATING-POINT-INVALID-OPERATION signalled
;Operation was (/ 0.0 0.0).
後でなおす
型宣言がしずらくてうまく最適化できねぇ〜
!expands behaves like PyTorch's one
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.