BERT MEETS RELATIONAL DB: LEARNING DEEP CONTEXTUAL REPRESENTATIONS OF RELATIONAL DATABASES - Songwooseok123/Study_Space GitHub Wiki
๋ ผ๋ฌธ๋งํฌ :BERT MEETS RELATIONAL DB: LEARNING DEEP CONTEXTUAL REPRESENTATIONS OF RELATIONAL DATABASES (arXiv 2021)
1. RDB & Downstream Tasks
In this paper, we address the problem of learning embeddings of entities on relational databases consisting of multiple tables
[RDB Downstream Task]
- Auto-completion of tables
- Missing value prediction
- Query processing of relational joins queries
- Data integration
- Join predictions
- ๋ฑ๋ฑ
โ Quality of embedding โ Downstream tasks
-> RDB Entity๋ค์ low dimension representation(Embedding) ์ ์ ํด์ผํจ. [RDB ๊ตฌ์กฐ์ Embedding์ ์ด๋ ค์]
- RDB๋ schema๋ฅผ ๊ฐ์ง๊ณ ์๊ณ ์ด๋ฅผ ํตํด ์ ๊ทํ๋๊ธฐ ๋๋ฌธ์ ํ ํ
์ด๋ธ์์ Entity๋ค์ ๋ํ ๊ด๊ณ๊ฐ ์ ๋ํ๋์ง ์์.
- ํ ์ด๋ธ ๊ฐ์ semantic๊ด๊ณ๋ฅผ ๊ณ ๋ คํด์ผ๋จ.
- Column ๊ฐ์ ๊ด๊ณ๋ฅผ ํ์ตํ๊ธฐ ์ฝ์ง ์์.
- e.g. l_name: ์ง, f_name: ์ค์
๊ฑฐ๋ ๋ง๋ญ์น๋ก ํ์ต๋ ๊ธฐ์กด NLP ๋ฅ๋ฌ๋ ๋ชจ๋ธ๋ค์ ํ ์ด๋ธ์ ๋ค๋ฃจ๋ RDB์์๋ ํจ๊ณผ์ ์ผ๋ก ์ฐ์ผ ์๊ฐ ์์
2. Related works
Table2Vec
: ํ ์ด๋ธ๋ค์ rows๋ฅผ ๋ฌธ์ฅ์ผ๋ก ๋ค๋ฃจ๊ณword2vec
์ผ๋ก ํ์ต์ํค๋ ๋ฐฉ๋ฒ- ๊ฐ์ entity๋ฉด ์ด๋ column์์๋ ๊ฐ์ ์๋ฒ ๋ฉ-> ๋ค๋ฅธ column์ ์์ผ๋ฉด ์๋ฏธ๋ ๋ฌ๋ผ์ผ ๋๋๋ฐ ๊ณ ๋ ค๋์ง์์.
- e.g. ๊ฐ๋ ๊ฒธ ๋ฐฐ์ฐ์ธ ์ด์ ์ฌ
- ๊ฐ์ entity๋ฉด ์ด๋ column์์๋ ๊ฐ์ ์๋ฒ ๋ฉ-> ๋ค๋ฅธ column์ ์์ผ๋ฉด ์๋ฏธ๋ ๋ฌ๋ผ์ผ ๋๋๋ฐ ๊ณ ๋ ค๋์ง์์.
Embdi
(SOTA ๋ชจ๋ธ) : ๊ทธ๋ํ ์๋ฐฐ๋ฉ ๋ฐฉ์์ random walks๋ฅผ ์ฌ์ฉํด์ column ์ฌ์ด์ ๊ด๊ณ๋ฅผ ํ์ ํจ.- FK-PK(ํ ์ด๋ธ๊ฐ์ semantic ๊ด๊ณ) ํ์ ์ ๋ชป ํจ
3. In this work
RELBERT
๋ชจ๋ธ ์ ์]
["BERT
์คํ์ผ์ ๋ชจ๋ธ์ ์ด์ฉํด์ Column๊ฐ์ semantic ๊ด๊ณ์ ํ
์ด๋ธ๋ค๊ฐ์ semantic ๊ด๊ณ๋ฅผ ํ์ตํ๋๋ฐ ์ง์คํ๋ค."
(2๊ฐ์ง Task์ ๋ํด์ ๊ฐ๊ฐ ๋ณํ๋ ๋ชจ๋ธ์ ์ ์ํจ)
1. RELBERT-A
- Table Autocompletion(or missing value imputation)
2. RELBERT-J
- Join Prediction
4. Problem Description
[๋ฐ์ดํฐ ํ๊ธฐ๋ฒ]
- RDB : $D$
- Set of tables : $T_({\alpha},{\beta},{\dots})\in D$
- For each table $T_{โข}$
- Table attributes(column) : $T_{โข}^{(A,B\dots)}$
- and each tuple(row) is addressed via its primary key.
- Number of columns in a table : $C_{T_โข}$
- Joined version of two tables $T_{\alpha}$ and $T_{\beta}$
- $T_\alpha\Join_{\tau_i,\tau_j} T_\beta$
- primary-key : $\tau_i\in T_\alpha$
- foreign-key : $\tau_j\in T_\beta$
4.1 Autocompletion
๋ชฉํ : Get a ranked list of most probable candidates for the masked entity.
4.2 Join Prediction
๋ชฉํ: (๋ ํ ์ด๋ธ $T_\alpha$, $T_\beta$๊ฐ $\tau_i(\in T_\alpha)$ ์ $\tau_j(\in T_\beta)$๋ก join ๊ฐ๋ฅํ ์ํฉ์์) $T_\alpha$ ์ tuple์ด ์ฃผ์ด์ก์ ๋, join๋ ์ ์๋ tuples of $T_\beta$ ์ ์์ธกํ๋ ๊ฒ
5. Proposed Model
5.1 Entity Embedding
- Initialization : pre-train๋
word2vec
์ผ๋ก table์ entity ๋ชจ๋ Embedding - Column Embedding : Entity๋ค์ column๋ณ๋ก ๋ฐ๋ก Embeddingํ๋ค
$$P_i^k=\Phi^k(T_i^k),\quad\forall k,i\in T$$
- Table Encoding :
self-attention
๋ชจ๋ธ๋ก ์ธํ row์ entity๋ค์ ์๋ฒ ๋ฉ ๋ฒกํฐ๋ฅผ ์ถ๋ ฅ
$$o_i^k=TableEncoder(P_i^k)$$
- k : k-th column , i : the row(sentence) index
5.2 MLM
- ๋ชฉํ : Column ๊ฐ์ ๊ด๊ณ๋ฅผ ํ์ตํ๋ค.
Since each column k has a different embedding space, computed by $ฮฆ_k$, we determine the candidate entities for the masked entity in the sentence using an output-softmax over the entities in the column of the masked entity .We learn the parameters for the horizontal transformer by optimizing the cross entropy loss function for each sentence in the table T as:
$$\mathcal{L_mlm} = \displaystyle\sum_{i=1}^{|T|}{CrossEntropy(O_i^m,P_i^{mask})}$$
- $O_i$ = TEncoder( $P_i$ )
- $O_i^m$ : output embeddings corresponding to the masked index
- $P^{mask}$ : column entities
5.3 NSP
-
๋ชฉํ : ํ ์ด๋ธ ๊ฐ์ ๊ด๊ณ๋ฅผ ํ์ตํ๋ค.
-
Join ๋ ์ ์๋ ํ ์ด๋ธ $T_\alpha$ , $T_\beta$ ๊ฐ ์๋ค.
- primary-key column: $T_\alpha^A$ , foreign-key column: $T_\beta^\hat{A}$
-
$\tau_i\in T_\alpha^A$ ๊ฐ $\tau_j\in T_\beta^{\hat{A}}$์ ์ฐ๊ฒฐ๋์ด ์๋ค๋ฉด ํ์์ row๊ฐ next sentence
-
[CLS]ํ ํฐ์ output embedding์ ์ฌ์ฉ
- The loss for NSP
$$\mathcal{L_nsp} = - \displaystyle\sum_{i=1}^{|T_\alpha|}\displaystyle\sum_{\tau_i\in T_\alpha^A}[log(\sigma(v_{\tau_i,\tau_j}))+log(1-\sigma(v_{\tau_i,\tau_j^{'}}))]$$
- $v_{\tau_i,\tau_j}$ : output embedding at the [cls] token
- $\tau_j^{'}โT_\beta^\hat{A}$ : negative sampled row
- $\tau_jโT_\beta^\hat{A}$ : true sampled row
- $\sigma$ : sigmoid function
- negative sampling objective function
5.4 RELBERT-A
๋ชฉํ : Missing entity๋ฅผ ์์ธกํ๋ค.
-
Missing entity์ ํ๋ณด๋ค์ ๊ตฌํ๊ธฐ ์ํด์ ๋ชจ๋ ํ ์ด๋ธ์ ๋ํ ์ ๋ณด๊ฐ ํ์ํ๋ค.
-
๋ชจ๋ ํ ์ด๋ธ๋ค์ ๋ํ ์ ๋ณด๋ฅผ ์ป๊ธฐ ์ํด์ Full denormalization์ด ํ์ํ๋ค.
- ํ์ง๋ง ํ ์ด๋ธ๋ค ๊ฐ์ ๋ชจ๋ fk-pk๋ฅผ ๊ณ์ฐํ๋ ๊ฒ์ cost๊ฐ ๋๋ฌด ํผ.
- ์๊ด์๋ Column์ ๋ฌถ์ ์๋ ์๊ณ table ์ฌ์ด์ฆ๋ฅผ ํฌ๊ฒ ํ ์๋ ์์.
-
์ด๋ฌํ ๋ณ๋ชฉํ์์ ์์ ๊ธฐ ์ํด table์ ์ค์ ๋ก join ํ๋ ๋์ NSP task๋ฅผ ํตํด ํ ์ด๋ธ๊ฐ ๊ด๊ณ๋ฅผ ํ์ตํ๋๋ก ํ๋ค.
-
- Pre-training
- ๋ ํ ์ด๋ธ์ joinํ์ง ์์ ์ํ์์ ๊ฐ ํ ์ด๋ธ์์ ๋์จ row๋ฅผ sentence ์์ผ๋ก ๋ง๋ค์ด์ MLM task ์ํ.
-
- Fine-tuning
- pre-training ๋๋๊ณ ๋์ $\mathcal{L_A}$ ๋ฅผ optimizingํ๋ฉด์ masked entity๋ฅผ ์์ธกํ๋๋ก fine tuning $$\mathcal{L_A} = \mathcal{L_mlm}+\mathcal{L_nsp}$$
5.5 RELBERT-J
๋ชฉํ : $T_\alpha$ ์ tuple์ด ์ฃผ์ด์ก์ ๋, join๋ ์ ์๋ tuples of $T_\beta$ ์ ์์ธกํ๋ ๊ฒ
-
Pre-training: we run independent masked-language models on each table in the database.
- related columns์ ๊ฐ์ง๋ ํ ์ด๋ธ๋ค $T_\alpha^A$ , $T_\beta^{\hat{A}}$ ์ ๋ํด์, Entity embedding์ ํ์ตํ๋ค. $$P_\alpha=MLM(T_\alpha), P_\beta=MLM(T_\beta)$$
-
Fine-tuning ํ ์ด๋ธ ๊ฐ์ ๊ด๊ณ๋ฅผ ํ์ ํ๊ธฐ ์ํด, NSP loss๋ฅผ ๊ณ์ฐํ๋ค.( relational join์ ๊ฐ์ง๋ ํ ์ด๋ธ ๊ฐ์ ๊ด๊ณ๋ฅผ ํ์ ํ๊ธฐ ์ํด.)
$$\mathcal{L_J}=NSP(P_\alpha,P_\beta,T_\alpha^A,T_\beta^{\hat{A}})$$
6. Experiments
6.1 Setup
- Dataset : IMDB, MIMIC
- Baseline Model :
Table2Vec
,EmbDi
- Task
- Auto-completion or Missing value prediction
- IMDB๋ฐ์ดํฐ์ ์์ ๊ฐ๊ฐ์ ์ํ์ ๋ํ ๊ฐ๋ ์์ธก
- MIMIC๋ฐ์ดํฐ์ ์์ ๊ฐ๊ฐ์ ํ์์ ๋ํ DRGCODE๋ฅผ ์์ธก
- train:validation:test = 70:15:15
- join-prediction
- IMDB๋ฐ์ดํฐ์ ์์ Movies ํ ์ด๋ธ๊ณผ Movies_Directors ํ ์ด๋ธ ๊ฐ์ ๊ด๊ณ(movie_id๋ก join ๊ฐ๋ฅ)์ ๋ํด ์ํ
- Auto-completion or Missing value prediction
- Metric
- Hitrate@10, MR(Mean Rank), MRR(Mean Reciprocal Rank)
6.2 Auto-completion
- missing entitiy์ ๋ํ ํ๋ณด๋ค์ ์์๋๋ก ์์ธก
RELBERT-A
๊ฐTable2Vec
์ ํจ์ฌ ์ํํ๋ ์ฑ๋ฅ์ ๊ฐ์ง- Column๋ณ๋ก ์๋ฒ ๋ฉ ํ๋ ๋ฐฉ์์ด ํ row๋ฅผ ์๋ฒ ๋ฉ ํ๋ ๋ฐฉ์๋ณด๋ค ๋ ์ข๊ฒ ์์ฉ
- IMDB๋ฐ์ดํฐ์
์์๋
RELBERT-A
๊ฐEmbDi
์ ๋นํด ์ด์ง ๋ค์ณ์ง๋ ์ฑ๋ฅ์ ๊ฐ์ง- IMDB๋ฐ์ดํฐ์
์ด ๋ ๋ง์ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ์์ด์
EmbDi
๋ฐฉ์์ random walk๊ฐ ๋ ์ข๊ฒ ์์ฉ - ํ์ง๋ง random walk ๋ฐฉ์์ RELBERT์ ๋นํด ๊ณ์ฐ ํจ์จ์ฑ์ด ๋จ์ด์ง
- IMDB๋ฐ์ดํฐ์
์ด ๋ ๋ง์ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ์์ด์
- [0~10] -> [movie_id, movies_name, movies_year, movies_rank, actors_last_name, movies_genre, actor_id, role, actors_first_name, directors_id, directors_genre]
self-attention
ํํธ๋งต์์ ๋จ์ํ ๊ฐ์ ํ ์ด๋ธ์ ์๋ ์ ๋ณด๋ง์ด ์๋ ๋ค๋ฅธ ํ ์ด๋ธ์ column์ ์ฃผ๋ชฉํ๊ณ ์๋ ๊ฒฝํฅ์ ๋ฐ๊ฒฌ- ๋ํ ์๋ก๋ค๋ฅธ ํค๋๋ ์๋ก ๋ค๋ฅธ ์ ๋ณด์ ์ฃผ๋ชฉํ๊ณ ์์์ ํ์ธ
6.3 Join Prediction
- ์ด ์์ ์ ๋น๊ตํ ์ฐ๊ตฌ๊ฐ ์์ด์ DB์ standard join๊ณผ ๋น๊ตํ ์ ๋ฐ์ ์๋ค
- ์ ๊ฒฝ๋ง์ ๊ธฐ๋ฐ์ผ๋ก ํ ์ด๋ธ ๊ฐ ์กฐ์ธ ์์ธก์ด ๊ฝค ํจ๊ณผ์ ์ผ๋ก ์ํ๋จ
- ํนํ negative sample ์๋ฅผ ๋๋ฆฌ๋ฉด ๋ ์ ์์ธกํจ
7. Conclusion & ๋๋์
- ๋จ์ํ
word2vec
์ผ๋ก ์๋ฒ ๋ฉ ํ๋ ๊ธฐ์กด ์ฐ๊ตฌ์๋ ๋ฌ๋ฆฌBERT
๊ธฐ๋ฐ์ ๋ชจ๋ธ์ ๋์ - Column๋ณ ์๋ฒ ๋ฉ์ ๋์ ํ์ฌ row๊ฐ input์ผ๋ก ๋ค์ด๊ฐ ๋ ๊ฐ ์ปฌ๋ผ๋ณ information์ ์์ง ์์
- ์ค์
BERT
์ฒ๋ผ pre-train๋ ๋ชจ๋ธ์ ๋ถ๋ฌ์์ ์ฌ์ฉํ๋๊ฒ์ด ์๋๋ผ,Transformer
์ Encoder Architecture๋ฅผ ์ฌ์ฉํ์ ๋ฟ์ด๋ผ์ RDB๋ฐ์ดํฐ๋ฅผ ์ดํดํ๋๋ฐ๋ ๋ถ์กฑํ๋ค๊ณ ์๊ฐ๋จ - ์คํ๊ฒฐ๊ณผ๊ฐ ํฌ๊ฒ ์ข์ง ์์์ ํํ ์ฐ๊ตฌ๊ฐ ๊ณ์ ์งํ๋์ด์ผ ํ ๊ฒ์ผ๋ก ์๊ฐ๋จ
[Future work]
- column ๋ฐ์ดํฐ ๋ด๋ถ์ ๊ด๊ณ๋ฅผ ํ์
ํ๊ธฐ ์ํด
vertical Transformer Encoder
๋ฅผ ์ฌ์ฉํ์ฌ ํ์ต - ์ค์ DB์์ ์คํ๋๋ SQL์ ์๋ฒ ๋ฉ ํ์ฌ query-sensitive semantic join์ ๋ํด ํ์ต