如何實現語法的自解釋(MLSQL易用性設計有感)
突然想明白了一件事, 語法應該是自解釋的。什麼意思呢,就是使用者需要有一個學習語法的語法,而這個語法應該極度簡單,他只要花上一分鐘,甚至依靠直覺就能知道怎麼用,透過這個口,以點窺面,讓使用者具備自主學習其他語法的能力。
系統如果能從這個層面考慮,那麼易用性就會好很多。通常而言,文件少了沒安全感,文件多了,尋找到對應的資訊又是難事,然後只能各種Google。
但是如果語法自解釋了,會是個什麼樣子的呢?
比如在MLSQL裡,對於模型,使用者只要記住一個關鍵字 model
一個簡單的load語法,然後完了就可以了。
第一次是這樣:
load model.`` as output;
會呈現如下三個資訊:
image.png
接著使用者使用者使用
load model.`list` as output;
得到可用模型的列表:
nametype --------------------------- PythonAlgprocess RandomForestalgorithm .....
然後我想試試RandomForest:
load model.`params` where alg="RandomForest"as output; -- or load modelParams.`RandomForest ` as output;
結果如下:
image.png
接著能給我例子麼?
load model.`example`where alg="RandomForest" as output; -- or load modelExample.`RandomForest ` as output;
則顯示如下內容
-- create test data set jsonStr=''' {"features":[5.1,3.5,1.4,0.2],"label":0.0}, {"features":[5.1,3.5,1.4,0.2],"label":1.0} {"features":[5.1,3.5,1.4,0.2],"label":0.0} {"features":[4.4,2.9,1.4,0.2],"label":0.0} {"features":[5.1,3.5,1.4,0.2],"label":1.0} {"features":[5.1,3.5,1.4,0.2],"label":0.0} {"features":[5.1,3.5,1.4,0.2],"label":0.0} {"features":[4.7,3.2,1.3,0.2],"label":1.0} {"features":[5.1,3.5,1.4,0.2],"label":0.0} {"features":[5.1,3.5,1.4,0.2],"label":0.0} '''; load jsonStr.`jsonStr` as data; select vec_dense(features) as features ,label as label from data as data1; -- use RandomForest train data1 as RandomForest.`/tmp/model` where -- once set true,every time you run this script, MLSQL will generate new directory for you model keepVersion="true" -- specicy the test dataset which will be used to feed evaluator to generate some metrics e.g. F1, Accurate and evaluateTable="data1" -- specify group 0 parameters and `fitParam.0.labelCol`="features" and `fitParam.0.featuresCol`="label" and `fitParam.0.maxDepth`="2" -- specify group 1 parameters and `fitParam.0.featuresCol`="features" and `fitParam.0.labelCol`="label" and `fitParam.1.maxDepth`="10" ;
自此,使用者其實已經自助看完了一篇文件。這麼做的好處是:
- 寫程式碼的同時也是寫文件
- 所有引數/模型都有自省機制。比如Spark MLlib params就做的非常好,可以很容易的羅列出可用引數。那麼其實模型也是可以做到的。比如這個模型是用來做資料處理的還是做演算法的,我們需要在類裡面有對應的資訊,無論是通過Annotation或者是方法。
- 使用者在使用load語法檢視功能的時候,就已經熟悉了MLSQL的使用模式了。