3. 発表の構成
•What is Hivemall
•Why Hivemall
•What Hivemall can do
•How to use Hivemall
•How Hivemall works
•イテレーションへの対処方法(Sparkと比較)
•性能評価
•DEMO
•Hivemallについてのまとめ
•データベース屋から見た機械学習の研究課題
ACM SIGMOD 日本支部第57回支部大会 3
基本的にHadoop Summit 2014, San Jose
で喋った内容を踏襲しております
3 / 66
4. What is Hivemall
•Hiveのユーザ定義関数またはユーザ定義テーブル 生成関数として実装された機械学習ライブラリ
•クラス分類と回帰分析
•推薦
•K近傍探索
.. and more
•オープンソースプロジェクト
•LGPLライセンス
•github.com/myui/hivemall(bit.ly/hivemall)
•コントリビュータは現在5人
ACM SIGMOD 日本支部第57回支部大会 4
4 / 66
18. ACM SIGMOD 日本支部第57回支部大会
CWの精度が何故よいか?
文章をpositiveかnegativeかに分類する二値分類 を想定してみる
→ 単語(特徴)ごとに重みを計算する
I like this author
Positive
I like this author, but found this book dull
Negative
Label
Feature Vector(特徴ベクトル)
ナイーブな学習手法では重みを同様に更新する
WlikeWdull
CWでは重みごとに異なる更新を行う
18
18 / 66
19. ACM SIGMOD 日本支部第57回支部大会
CWの精度が何故よいか?
weight
weight
重みを更新する
重みと確信度を
更新する
0.6
0.8
0.6
0.8
0.6
At this confidence,
the weight is 0.5
共分散
(確信度)
0.5
19
19 / 66
24. ACM SIGMOD 日本支部第57回支部大会
How to use Hivemall
Machine
Learning
Training
Prediction
Prediction
Model
Label
Feature Vector
Feature Vector
Label
Data preparation 24
24 / 66
25. ACM SIGMOD 日本支部第57回支部大会
Create external table e2006tfidf_train (
rowidint,
labelfloat,
featuresARRAY<STRING>
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '¥t'
COLLECTION ITEMS TERMINATED BY ",“
STORED AS TEXTFILE LOCATION '/dataset/E2006- tfidf/train';
How to use Hivemall –データの準備
訓練とテストデータ用のテーブルを定義
HDFSに置いた(HiveのSERDEでパース可能な)任意フォー マットのデータを利用可能
25
25 / 66
26. ACM SIGMOD 日本支部第57回支部大会
How to use Hivemall
Machine
Learning
Training
Prediction
Prediction
Model
Label
Feature Vector
Feature Vector
Label
Feature Engineering
26
26 / 66
27. ACM SIGMOD 日本支部第57回支部大会
create viewe2006tfidf_train_scaled
as
select
rowid,
rescale(target,${min_label},${max_label})
as label,
features
from
e2006tfidf_train;
Min-Max正規化による特徴量の正規化
How to use Hivemall -Feature Engineering
Target値を0~1の範囲に変換
27
27 / 66
28. ACM SIGMOD 日本支部第57回支部大会
How to use Hivemall
Machine
Learning
Training
Prediction
Prediction
Model
Label
Feature Vector
Feature Vector
Label
Training
28
28 / 66
29. ACM SIGMOD 日本支部第57回支部大会
How to use Hivemall -Training
CREATE TABLE lr_modelAS
SELECT
feature,
avg(weight) as weight
FROM (
SELECT logress(features,label,..)
as (feature,weight)
FROM train
) t
GROUP BY feature
ロジスティック回帰による学習
予測モデルを学習するmap-onlyのtask
Featureの値によってmap出力結果をreducerに
Shuffle
特徴ごとに学習した重みの平均
を取る処理をreducer側で並列に処理
29
29 / 66
30. ACM SIGMOD 日本支部第57回支部大会
How to use Hivemall -Training
CREATE TABLE news20b_cw_model1 AS
SELECT
feature,
voted_avg(weight) as weight
FROM
(SELECT
train_cw(features,label)
as (feature,weight)
FROM
news20b_train
) t
GROUP BY feature
Confidence Weightedによる学習
投票に基づきPositiveor Negativeな
重みの平均
+0.7, +0.3, +0.2, -0.1, +0.7
CWクラス分類器による学習
30
30 / 66
31. ACM SIGMOD 日本支部第57回支部大会
create table news20mc_ensemble_model1 as
select
label,
cast(feature as int) as feature,
cast(voted_avg(weight) as float) as weight
from
(select
train_multiclass_cw(addBias(features),label)
as (label,feature,weight)
from
news20mc_train_x3
union all
select
train_multiclass_arow(addBias(features),label)
as (label,feature,weight)
from
news20mc_train_x3
union all
select
train_multiclass_scw(addBias(features),label)
as (label,feature,weight)
from
news20mc_train_x3
) t
group by label, feature;
アンサンブル学習for stable prediction performance
個別に学習した予測モデルを
Union allでまとめる
31
31 / 66
32. ACM SIGMOD 日本支部第57回支部大会
How to use Hivemall
Machine
Learning
Training
Prediction
Prediction
Model
Label
Feature Vector
Feature Vector
Label
Prediction
32
32 / 66
33. ACM SIGMOD 日本支部第57回支部大会
How to use Hivemall -Prediction
CREATE TABLE lr_predict
as
SELECT
t.rowid,
sigmoid(sum(m.weight)) as prob
FROM
testing_exploded t LEFT OUTER JOIN
lr_model m ON (t.feature = m.feature)
GROUP BY
t.rowid
予測はテスト事例と予測モデルの
LEFT OUTER JOINによって行う
予測モデル全体をメモリに載せる必要がない
33
33 / 66
34. 発表の構成
•What is Hivemall
•Why Hivemall
•What Hivemallcan do
•How to use Hivemall
•How Hivemallworks
•イテレーションへの対処方法(Sparkと比較)
•性能評価
•DEMO
•Hivemallについてのまとめ
•データベース屋から見た機械学習の研究課題
ACM SIGMOD 日本支部第57回支部大会 34
34 / 66
39. ACM SIGMOD 日本支部第57回支部大会
Spark Mllibでは実際どうなっている?
Val data = ..
for (i <-1 to numIterations) {
valsampled =
valgradient =
w -= gradient
}
サンプリングを利用したMini-batch勾配降下法
それぞれのイテレーションではデータの一部だけを
利用するため、反復処理は学習の収束に不可欠
GradientDescent.scala
bit.ly/spark-gd
データのサブセットをサンプリング
Spark MapReduceを利用してSampled[1..N]の勾配をN個のワー カで並列に計算してN個の予測モデルを構築し、N個のご予測モデルを マスターノードで(逐次的に)マージ
Wは次のイテレーションで各ワーカに送信される
39
39 / 66
40. Hivemallでどのように反復に対処?
Hivemallでは、複数のMapReduce Jobを利用した反復 処理なしに機械学習における反復学習の効果をエミュ レートするためにamplifyUDTFを提供
SET hivevar:xtimes=3;
CREATE VIEW training_x3
as
SELECT
*
FROM(
SELECT
amplify(${xtimes}, *) as (rowid, label, features)
FROM
training
) t
CLUSTER BY RANDOM
ACM SIGMOD 日本支部第57回支部大会
入データを増幅してshuffleする
40
40 / 66
41. Map-only shuffling and amplifying
rand_amplifyUDTFはmapタスク内で入力され た訓練事例を増幅&shuffleする
CREATE VIEWtraining_x3
as
SELECT
rand_amplify(${xtimes}, ${shufflebuffersize}, *)
as (rowid, label, features)
FROM
training;
ACM SIGMOD 日本支部第57回支部大会 41
41 / 66
49. Docid, wordからなるTable/Viewを用意する
ACM SIGMOD 日本支部第57回支部大会 49
TF-IDF vectorizer (2)
create external table wikipage (
docid int,
page string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '|'
STORED AS TEXTFILE;
create or replace view wikipage_exploded
as
select
docid,
word
from
wikipage LATERAL VIEW explode(tokenize(page,true)) t as word
where
not is_stopword(word);
49 / 66
自分で形態素解析して用意してももちろんよい
50. ACM SIGMOD 日本支部第57回支部大会 50
TF-IDF vectorizer (3)
create or replace view term_frequency
as
select
docid, word, freq
from (
select
docid,
tf(word) as word2freq
from
wikipage_exploded
group by
docid
) t
LATERAL VIEW explode(word2freq) t2
as word, freq;
create or replace view document_frequency
as
select
word,
count(distinct docid) docs
from
wikipage_exploded
group by
word;
TF, DFのビューを定義する
文書d内のある単語tの出現頻度
푡푓(푡,푑)
単語tの文書頻度
푑푓(푡)
50 / 66
51. ACM SIGMOD 日本支部第57回支部大会 51
TF-IDF vectorizer (4)
select
tf.docid,
tf.word,
tfidf(tf.freq, df.docs, ${n_docs}) as tfidf
from
term_frequency tf
JOIN document_frequency df ON (tf.word = df.word)
order by
tfidf desc;
docid/wordごとのTF-IDF値をTF-IDF値の降順に 表示する
51 / 66
61. ・・・・・・
Model updates
Asyncadd
AVG/ArgminKLD accumulator
hash(feature) % N
Non-blocking Channel
(single shared TCP connection w/ TCP keepalive)
classifiers
Mix serv.
Mix serv.
Computation/training
is not being blocked
61
MIX Serverの概要
ACM SIGMOD 日本支部第57回支部大会
61 / 66
62. Model
updates
Propagate every update
asynchronously
feature
weight[]
clock[]
min covar
total clock
Diff=|total clock –local clock|
total clock += lock clock
Average accumulator
feature
sum mean div covar
sum invcovar
min covar
total clock
argminKL-divergence
accumulator
feature
weight
Covariance
clock
Mix serv.
62
最新の値を保持する パラメタサーバと異な り、モデル平均化処理 のためのaccumulator
Global clockとlocal clockがズレてきたら
ローカルモデルに平 均化処理した結果を 反映
ACM SIGMOD 日本支部第57回支部大会
62 / 66
63. create table kdd10a_pa1_model1 as
select
feature,
cast(voted_avg(weight) as float) as weight
from
(select
train_pa1(addBias(features),label,"-mix host01,host02,host03") as (feature,weight)
from
kdd10a_train_x3
) t
group by feature;
ACM SIGMOD 日本支部第57回支部大会 63
MIX Serverの利用
このように学習器の呼び出しで
Mix serverをオプション指定する
63 / 66
64. Model Averaging Issues
Model
ServerA
Server B
ServerC
weight
10.0
50.0
30.0
clock
2
4
3
Avg=sum weight/count=(10+50+30)/3=30
WeightedAvg=(10*2/9)+(50*4/9)+(30*3/9)=34.44..
Problem:
AVG(μ) is argminEuclid distance,
not considering covariance
(a confidence parameter of weights)
64
Solution:
argminKL-distance
ACM SIGMOD 日本支部第57回支部大会
64 / 66
65. DBと機械学習で境界領域で活躍してい る注目の研究者(1)
スタンフォード大Christopher Ré教授
http://cs.stanford.edu/people/chrismre/
Hogwild: A lock-free approach to parallelizing stochastic gradient descent, Proc. NIPS, 2011.が有名.確率的勾配降下法の並列処 理を共有メモリ並列計算機上で効率的に行う手法
65
2014の発表:
DimmWitted: A Study of Main-Memory Statistical Analytics. Proc. PVLDB, 2015.
An Asynchronous Parallel Stochastic Coordinate Descent Algorithm. Proc. ICML 2014.
Beyond Worst-case Analysis for Joins using Minesweeper. Proc. PODS 2014.
Materialization Optimizations for Feature Selection. Proc. SIGMOD 2014. Best paper
ACM SIGMOD 日本支部第57回支部大会
65 / 66
66. DBと機械学習で境界領域で活躍してい る注目の研究者(2)
カリフォルニア大学バークレー校John Canny教授
http://www.cs.berkeley.edu/~jfc/
CHIコミュニティで有名な先生(らしい)だが,近年 BIDMACHプロジェクトでButterfly MixingやKylixなどGPU を利用した機械学習処理で興味深い成果を挙げている
66
Kylix: A Sparse AllReduce for Commodity Clusters. Proc. Int. Conf. on Parallel Processing (ICPP) 2014.
BIDMach: Large-scale Learning with Zero Memory Allocation. Proc. NIPS BigLearnWorkshop 2013.
A Multi-Teraflop Constituency Parser using GPUs. Proc. EMNLP 2013.
Big Data Analytics with Small Footprint: Squaring the Cloud. Proc. ACM KDD 2013.
Butterfly Mixing: Accelerating Incremental-Update Algorithms on Clusters. Proc. SIAM Data Mining 2013.
ACM SIGMOD 日本支部第57回支部大会
66 / 66