A BERT-based reverse-dictionary of Korean proverbs

Overview

Wisdomify

A BERT-based reverse-dictionary of Korean proverbs.

  • 김유빈 : 모델링 / 데이터 수집 / 프로젝트 설계 / back-end
  • 김종윤 : 데이터 수집 / 프로젝트 설계 / front-end

Quick Start

Check the dependencies:

pytorch-lightning==1.3.7.post0
transformers==4.8.1

Clone the project and set up a virtualenv for the project:

git clone https://github.com/eubinecto/wisdomify.git
virtualenv wisdomifyenv
source wisdomify/bin/activate  # activate the virtualenv
pip3 install -r ./requirements.txt  # install the required libraries onto the virtualenv

Download a pre-trained wisdomify:

link description
version_0.zip (1.5GB) the first minimal-viable-product of Wisdomify
version_1.zip to be added...

Unzip the model package under wisdomify/data/lightning_logs:

cd data/lightning_logs
unzip version_0.zip

Make sure you have a directory structure like the following:

data
├── lightning_logs
│   ├── readme.md
│   └── version_0
│       ├── checkpoints
│       │   └── wisdomify_def_epoch=19_train_loss=0.00.ckpt
│       ├── events.out.tfevents.1624691069.eubinCloud.57195.0
│       └── hparams.yaml
├── wisdom2def.tsv
└── wisdom2eg.tsv

Wisdomify a sentence:

python3 -m wisdomify.main.infer --ver="version_0" --desc="까불지말고 침착하여라"
### desc: 까불지말고 침착하여라 ###
0: (원숭이도 나무에서 떨어진다, 0.3917)
1: (산넘어 산, 0.2828)
2: (등잔 밑이 어둡다, 0.2192)
3: (가는 날이 장날, 0.0351)
4: (고래 싸움에 새우 등 터진다, 0.0264)
5: (꿩 대신 닭, 0.0241)
6: (갈수록 태산, 0.0197)
7: (핑계 없는 무덤 없다, 0.0009)
8: (서당개 삼 년이면 풍월을 읊는다, 0.0001)
9: (소문난 잔치에 먹을 것 없다, 0.0000)

Related Work

  • 기반이 되는 모델은 사전훈련된 BERT (Devlin et al., 2018)
  • 정확히는 한국어 구어체를 사전학습한 KcBERT를 사용함 (Junbum, 2020)
  • 사전훈련된 KcBERT를 reverse-dictionary task에 맞게 fine-tune함 (Yan et al., 2020)

How did I end up with Wisdomify?:

  1. Word2Vec: King = Queen - woman, 이런게 된다는게 너무 재미있고 신기하다. 이걸로 게임을 만들어볼 수 있지 않을까? - Toy 프로젝트: word-chemist
  2. 생각보다 잘 되는데? 그럼 Word2Vec로 reverse-dictionary도 구현할 수 있지 않을까? - 학사 졸업 프로젝트 - Idiomify
  3. Sum of Word2Vectors로 reverse-dictionary를 구현하기에는 분명한 한계가 보인다. 문장의 맥락을 이해하는 Language Model은 없는가? - 논문 리뷰: Attention is All you Need
  4. Attention의 목적이 Contextualised embedding을 얻기 위함임은 알겠다. 그런데 왜 각 파라미터를 Q, K, V라고 이름지었는가? 무엇에 비유를 하는 것인가?- What is Q, K, V? - Information Retrieval analogy
  5. Contextualised embedding을 활용한 사례에는 무엇이 있는가? - 논문 리뷰: Vokenization: Improving Language Understanding with Contextualized, Visual-Grounded Supervision
  6. Vokenisation 논문을 보니 BERT를 적극 활용하더라. BERT란 어떤 모델인가? - 집현전 중급 2조 BERT 논문리뷰
  7. 아, 혹시 사전훈련된 BERT를 활용한다면 적은 데이터를 가지고도 reverse-dictionary task를 구현할 수 있지 않을까? 누군가 이미 시도를 해보았을 것 같은데? - 논문리뷰: BERT for Monolingual and Cross-Lingual Reverse Dictionary
  8. 로스함수를 이해했다. 한번 BERT로 간단한 reverse-dictionary를 구현해보자 - Toy 프로젝트: fruitify - a reverse-dictionary of fruits!
  9. fruitify: 성공적인 첫 데모!
  10. BERT로 reverse-dictionary를 구현하는 방법을 이해했고, 실재로 구현도 해보았다. 이제 생각해보아야 하는 것은 reverse-dictionary로 풀만한 가치가 있는 문제를 찾는 것 - Wisdomify: 자기주도적으로 우리말 속담을 학습하는 것을 도와주는 reverse-dictionary.

Methods

The loss function

앞서 언급한 논문 (Yan et al., 2020)에서 제시한 reverse-dictionary task를 위한 loss:

BERT for monolingual reverse-dictionary

Hyper parameters

The hyper parameters used for version_0:

{
  "bert_model": "beomi/kcbert-base",
  "versions": {
    "version_0": {
      "desc": "The first minimal-viable-product of wisdomify",
      "data": "wisdom2def",
      "k": 11,
      "lr": 0.00001,
      "max_epochs": 20,
      "batch_size": 40,
      "repeat": 20,
      "num_workers": 4,
      "shuffle": true
    }
  }
}

Training

wisdomify_def_epoch=19_train_loss=0.00.ckpt
  • 훈련셋에서 로스가 0에 수렴할 때 까지 훈련을 진행함. 가능한 빠른 시일 내에 프로토타입을 만들어보는것이 목표였으므로, 일단 validation/test set 구축을 스킵, 오버피팅이 되더라도 훈련 셋에만 핏을 함.
  • 사이즈가 상당히 크므로, 나중에 knowledge distilation (Hinton, 2015)으로 경량화하는 것도 고려해봐야할 것.

Dataset

  • 10개의 속담 별로 5개의 서로다른 정의를 구글링으로 손수 수집. 사이즈가 작으므로 그냥 repo에 업로드 함: wisdom2def
  • 추후 데이터를 더 수집하게 되면 kaggle이나 dropbox에 업로드 해서 접근하는 편이 나을 것.

Examples

Positive examples

  • 갈수록 어렵다
### desc: 갈수록 어렵다 ###
0: ('산넘어 산', 0.9999836683273315)
1: ('갈수록 태산', 1.6340261936420575e-05)
2: ('꿩 대신 닭', 4.177704404639826e-09)
3: ('핑계 없는 무덤 없다', 4.246608897862103e-10)
4: ('원숭이도 나무에서 떨어진다', 4.91051192763603e-11)
5: ('가는 날이 장날', 3.620301280982119e-11)
6: ('등잔 밑이 어둡다', 3.410518395474682e-12)
7: ('고래 싸움에 새우 등 터진다', 2.889838230366905e-14)
8: ('소문난 잔치에 먹을 것 없다', 2.270246673757772e-14)
9: ('서당개 삼 년이면 풍월을 읊는다', 2.424753148985129e-15)
  • 근처에 있을 것이라고는 전혀 예상하지 못했다
### desc: 근처에 있을 것이라고는 전혀 예상하지 못했다 ###
0: ('등잔 밑이 어둡다', 0.934296190738678)
1: ('원숭이도 나무에서 떨어진다', 0.04902056232094765)
2: ('산넘어 산', 0.010009311139583588)
3: ('가는 날이 장날', 0.005946608260273933)
4: ('소문난 잔치에 먹을 것 없다', 0.0002701274352148175)
5: ('고래 싸움에 새우 등 터진다', 0.0002532936632633209)
6: ('갈수록 태산', 0.00010314056999050081)
7: ('핑계 없는 무덤 없다', 9.196436440106481e-05)
8: ('꿩 대신 닭', 8.55061716720229e-06)
9: ('서당개 삼 년이면 풍월을 읊는다', 3.365390739418217e-07)
  • 너 때문에 관계없는 내가 피해봤잖아
### desc: 너 때문에 관계없는 내가 피해봤잖아 ###
0: ('고래 싸움에 새우 등 터진다', 0.9243378043174744)
1: ('가는 날이 장날', 0.028463557362556458)
2: ('핑계 없는 무덤 없다', 0.026872390881180763)
3: ('등잔 밑이 어둡다', 0.012348096817731857)
4: ('소문난 잔치에 먹을 것 없다', 0.003390798345208168)
5: ('산넘어 산', 0.0026215193793177605)
6: ('갈수록 태산', 0.0010220635449513793)
7: ('원숭이도 나무에서 떨어진다', 0.0004960462101735175)
8: ('꿩 대신 닭', 0.00044754118425771594)
9: ('서당개 삼 년이면 풍월을 읊는다', 6.364324889318596e-08)
  • 쓸데없는 변명은 그만 둬
### desc: 쓸데없는 변명은 그만둬 ###
0: ('핑계 없는 무덤 없다', 0.6701037287712097)
1: ('꿩 대신 닭', 0.17732197046279907)
2: ('산넘어 산', 0.1395266205072403)
3: ('갈수록 태산', 0.01272804755717516)
4: ('가는 날이 장날', 0.00020182589651085436)
5: ('원숭이도 나무에서 떨어진다', 0.0001034122469718568)
6: ('고래 싸움에 새우 등 터진다', 1.2503404832386877e-05)
7: ('등잔 밑이 어둡다', 1.5657816447856021e-06)
8: ('소문난 잔치에 먹을 것 없다', 2.735970952016942e-07)
9: ('서당개 삼 년이면 풍월을 읊는다', 3.986170074576911e-11)

속담의 용례를 입력으로 주어도 용례에 맞는 속담을 예측할 수 있을까? 각 속담의 사전적 정의만 훈련에 사용되었다는 것을 고려해보았을 때, 만약 이것이 가능하다면 사전학습된 weight를 십분활용하고 있다는 것의 방증이 될 것.

  • 커피가 없으니 홍차라도 마시자
### desc: 커피가 없으니 홍차라도 마시자 ###
0: ('꿩 대신 닭', 0.5670634508132935)
1: ('가는 날이 장날', 0.15952838957309723)
2: ('산넘어 산', 0.14466965198516846)
3: ('등잔 밑이 어둡다', 0.10353685170412064)
4: ('소문난 잔치에 먹을 것 없다', 0.006912065204232931)
5: ('갈수록 태산', 0.00646367808803916)
6: ('서당개 삼 년이면 풍월을 읊는다', 0.006029943469911814)
7: ('원숭이도 나무에서 떨어진다', 0.004639457445591688)
8: ('핑계 없는 무덤 없다', 0.0011017059441655874)
9: ('고래 싸움에 새우 등 터진다', 5.46958799532149e-05)
  • 그 애가 도망쳐 버렸으면 아무나 대신 잡아넣어 숫자를 채워야 할 게 아니냐?
### desc: 그 애가 도망쳐 버렸으면 아무나 대신 잡아넣어 숫자를 채워야 할 게 아니냐? ###
0: ('꿩 대신 닭', 0.6022371649742126)
1: ('등잔 밑이 어둡다', 0.3207240402698517)
2: ('서당개 삼 년이면 풍월을 읊는다', 0.03545517101883888)
3: ('가는 날이 장날', 0.012123783119022846)
4: ('갈수록 태산', 0.011005728505551815)
5: ('원숭이도 나무에서 떨어진다', 0.010867268778383732)
6: ('핑계 없는 무덤 없다', 0.004052910953760147)
7: ('산넘어 산', 0.002024132991209626)
8: ('고래 싸움에 새우 등 터진다', 0.0013805769849568605)
9: ('소문난 잔치에 먹을 것 없다', 0.00012919674918521196)

  • 나는 어릴 적부터 카센터에서 잡일을 도맡아 하다 보니 이젠 혼자서 자동차 수리도 할수 있다.
### desc: 나는 어릴 적부터 카센터에서 잡일을 도맡아 하다 보니 이젠 혼자서 자동차 수리도 할수 있다. ###
0: ('서당개 삼 년이면 풍월을 읊는다', 0.5147183537483215)
1: ('등잔 밑이 어둡다', 0.34899067878723145)
2: ('가는 날이 장날', 0.12019266188144684)
3: ('원숭이도 나무에서 떨어진다', 0.011380248703062534)
4: ('산넘어 산', 0.002991838613525033)
5: ('갈수록 태산', 0.0007551977760158479)
6: ('꿩 대신 닭', 0.0004372508847154677)
7: ('소문난 잔치에 먹을 것 없다', 0.00040235655615106225)
8: ('고래 싸움에 새우 등 터진다', 7.436128362314776e-05)
9: ('핑계 없는 무덤 없다', 5.710194818675518e-05)
  • 맛집이라길래 일부러 먼길을 달려왔는데 막상 먹어보니 맛이 없더라
### desc: 맛집이라길래 일부러 먼길을 달려왔는데 막상 먹어보니 맛이 없더라 ###
0: ('소문난 잔치에 먹을 것 없다', 0.5269527435302734)
1: ('서당개 삼 년이면 풍월을 읊는다', 0.2070106714963913)
2: ('가는 날이 장날', 0.15454722940921783)
3: ('등잔 밑이 어둡다', 0.11061225831508636)
4: ('꿩 대신 닭', 0.0006726137944497168)
5: ('원숭이도 나무에서 떨어진다', 0.0001451421994715929)
6: ('산넘어 산', 3.2266420021187514e-05)
7: ('핑계 없는 무덤 없다', 1.288024850509828e-05)
8: ('갈수록 태산', 1.0781625860545319e-05)
9: ('고래 싸움에 새우 등 터진다', 3.4537756619101856e-06)

Negative examples

검색할 수 있는 속담이 모두 부정적인 속담이라서 그런지, 긍정적인 문장이 입력으로 들어오면 제대로 예측을 하지 못한다:

  • 결과가 좋아서 기쁘다
0: ('산넘어 산', 0.9329468011856079)
1: ('갈수록 태산', 0.05804209038615227)
2: ('꿩 대신 닭', 0.006065088324248791)
3: ('가는 날이 장날', 0.002668046159669757)
4: ('원숭이도 나무에서 떨어진다', 0.00024604308418929577)
5: ('핑계 없는 무덤 없다', 3.138219108222984e-05)
6: ('등잔 밑이 어둡다', 4.152606720708718e-07)
7: ('소문난 잔치에 먹을 것 없다', 2.1668449790013256e-07)
8: ('고래 싸움에 새우 등 터진다', 2.008734867331441e-08)
9: ('서당개 삼 년이면 풍월을 읊는다', 1.0531459260221254e-08)

"소문난 잔치에 먹을 것 없다"와 동일한 의미를 지님에도 불구하고, "실제로는 별거 없네"를 입력으로 받으면 "산 넘어 산"이 1등으로 출력. 하지만 훈련 셋에 포함된 샘플인 "소문과 실제가 일치하지 않는다"를 입력으로 받으면 정확하게 예측함. 즉 모델이 훈련셋에 오버피팅이 된 상태임을 확인할 수 있다:

  • 실제로는 별거없네 (훈련 셋에 포함되지 않은 정의)
### desc: 실제로는 별거없네 ###
0: ('산넘어 산', 0.9976289868354797)
1: ('갈수록 태산', 0.002168289152905345)
2: ('꿩 대신 닭', 0.00020149812917225063)
3: ('핑계 없는 무덤 없다', 9.218800869348343e-07)
4: ('등잔 밑이 어둡다', 1.6546708536679944e-07)
5: ('가는 날이 장날', 1.0126942839860931e-07)
6: ('원숭이도 나무에서 떨어진다', 9.898108288552976e-08)
7: ('소문난 잔치에 먹을 것 없다', 6.846833322526891e-09)
8: ('고래 싸움에 새우 등 터진다', 4.417973487047533e-10)
9: ('서당개 삼 년이면 풍월을 읊는다', 8.048845877989264e-14)
  • 소문과 실제가 일치하지 않는다 (훈련 셋에 포함된 정의)
### desc: 소문과 실제가 일치하지 않는다. ###
0: ('소문난 잔치에 먹을 것 없다', 0.999997615814209)
1: ('등잔 밑이 어둡다', 1.7779053678168566e-06)
2: ('가는 날이 장날', 5.957719508842274e-07)
3: ('갈수록 태산', 9.973800452200976e-09)
4: ('핑계 없는 무덤 없다', 2.4250623731347787e-09)
5: ('고래 싸움에 새우 등 터진다', 5.40873457133273e-10)
6: ('산넘어 산', 4.573414147390764e-10)
7: ('원숭이도 나무에서 떨어진다', 2.8081562075676914e-10)
8: ('꿩 대신 닭', 2.690336287081152e-10)
9: ('서당개 삼 년이면 풍월을 읊는다', 3.8126671958460534e-11)
  • 소문이랑 다르네 ("소문"이라는 단어에는 민감하게 반응한다.)
### desc: 소문이랑 다르네 ###
0: ('산넘어 산', 0.9770968556404114)
1: ('소문난 잔치에 먹을 것 없다', 0.01917330175638199)
2: ('갈수록 태산', 0.0035712094977498055)
3: ('꿩 대신 닭', 8.989872731035575e-05)
4: ('가는 날이 장날', 6.370477785822004e-05)
5: ('핑계 없는 무덤 없다', 1.7765859183782595e-06)
6: ('원숭이도 나무에서 떨어진다', 1.6799665445432765e-06)
7: ('등잔 밑이 어둡다', 1.6705245116099832e-06)
8: ('고래 싸움에 새우 등 터진다', 3.0059517541758396e-08)
9: ('서당개 삼 년이면 풍월을 읊는다', 4.33282611178587e-11)

Future Work

References

  • Devlin, J. Cheng, M. Lee, K. Toutanova, K. (2018). : Pre-training of Deep Bidirectional Transformers for Language Understanding.
  • Gururangan, S. Marasović, A. Swayamdipta, S. Lo, K. Beltagy, I. Downey, D. Smith, N. (2020). Don't Stop Pretraining: Adapt Language Models to Domains and Tasks
  • Hinton, G. Vinyals, O. Dean, J. (2015). Distilling the Knowledge in a Neural Network
  • Junbum, L. (2020). KcBERT: Korean Comments BERT
  • Yan, H. Li, X. Qiu, X. Deng, B. (2020). BERT for Monolingual and Cross-Lingual Reverse Dictionary
Owner
Eu-Bin KIM
NLP & Search for language acquisition
Eu-Bin KIM
[EMNLP 2021] Mirror-BERT: Converting Pretrained Language Models to universal text encoders without labels.

[EMNLP 2021] Mirror-BERT: Converting Pretrained Language Models to universal text encoders without labels.

Cambridge Language Technology Lab 61 Dec 10, 2022
A minimal Conformer ASR implementation adapted from ESPnet.

Conformer ASR A minimal Conformer ASR implementation adapted from ESPnet. Introduction I want to use the pre-trained English ASR model provided by ESP

Niu Zhe 3 Jan 24, 2022
Optimal Transport Tools (OTT), A toolbox for all things Wasserstein.

Optimal Transport Tools (OTT), A toolbox for all things Wasserstein. See full documentation for detailed info on the toolbox. The goal of OTT is to pr

OTT-JAX 255 Dec 26, 2022
A Python package implementing a new model for text classification with visualization tools for Explainable AI :octocat:

A Python package implementing a new model for text classification with visualization tools for Explainable AI 🍣 Online live demos: http://tworld.io/s

Sergio Burdisso 285 Jan 02, 2023
🍊 PAUSE (Positive and Annealed Unlabeled Sentence Embedding), accepted by EMNLP'2021 🌴

PAUSE: Positive and Annealed Unlabeled Sentence Embedding Sentence embedding refers to a set of effective and versatile techniques for converting raw

EQT 21 Dec 15, 2022
End-to-End Speech Processing Toolkit

ESPnet: end-to-end speech processing toolkit system/pytorch ver. 1.0.1 1.1.0 1.2.0 1.3.1 1.4.0 1.5.1 1.6.0 1.7.1 1.8.1 ubuntu18/python3.8/pip ubuntu18

ESPnet 5.9k Jan 03, 2023
Codes to pre-train Japanese T5 models

t5-japanese Codes to pre-train a T5 (Text-to-Text Transfer Transformer) model pre-trained on Japanese web texts. The model is available at https://hug

Megagon Labs 37 Dec 25, 2022
A calibre plugin that generates Word Wise and X-Ray files then sends them to Kindle. Supports KFX, AZW3 and MOBI eBooks. X-Ray supports 18 languages.

WordDumb A calibre plugin that generates Word Wise and X-Ray files then sends them to Kindle. Supports KFX, AZW3 and MOBI eBooks. Languages X-Ray supp

172 Dec 29, 2022
Nmt - TensorFlow Neural Machine Translation Tutorial

Neural Machine Translation (seq2seq) Tutorial Authors: Thang Luong, Eugene Brevdo, Rui Zhao (Google Research Blogpost, Github) This version of the tut

6.1k Dec 29, 2022
A machine learning model for analyzing text for user sentiment and determine whether its a positive, neutral, or negative review.

Sentiment Analysis on Yelp's Dataset Author: Roberto Sanchez, Talent Path: D1 Group Docker Deployment: Deployment of this application can be found her

Roberto Sanchez 0 Aug 04, 2021
Signature remover is a NLP based solution which removes email signatures from the rest of the text.

Signature Remover Signature remover is a NLP based solution which removes email signatures from the rest of the text. It helps to enchance data conten

Forges Alterway 8 Jan 06, 2023
中文問句產生器;使用台達電閱讀理解資料集(DRCD)

Transformer QG on DRCD The inputs of the model refers to we integrate C and A into a new C' in the following form. C' = [c1, c2, ..., [HL], a1, ..., a

Philip 1 Oct 22, 2021
Finally, some decent sample sentences

tts-dataset-prompts This repository aims to be a decent set of sentences for people looking to clone their own voices (e.g. using Tacotron 2). Each se

hecko 19 Dec 13, 2022
Auto translate textbox from Japanese to English or Indonesia

priconne-auto-translate Auto translate textbox from Japanese to English or Indonesia How to use Install python first, Anaconda is recommended Install

Aji Priyo Wibowo 5 Aug 25, 2022
Large-scale Self-supervised Pre-training Across Tasks, Languages, and Modalities

Hiring We are hiring at all levels (including FTE researchers and interns)! If you are interested in working with us on NLP and large-scale pre-traine

Microsoft 7.8k Jan 09, 2023
End-2-end speech synthesis with recurrent neural networks

Introduction New: Interactive demo using Google Colaboratory can be found here TTS-Cube is an end-2-end speech synthesis system that provides a full p

Tiberiu Boros 214 Dec 07, 2022
This is the main repository of open-sourced speech technology by Huawei Noah's Ark Lab.

Speech-Backbones This is the main repository of open-sourced speech technology by Huawei Noah's Ark Lab. Grad-TTS Official implementation of the Grad-

HUAWEI Noah's Ark Lab 295 Jan 07, 2023
Code for the paper "Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer"

T5: Text-To-Text Transfer Transformer The t5 library serves primarily as code for reproducing the experiments in Exploring the Limits of Transfer Lear

Google Research 4.6k Jan 01, 2023
Text classification on IMDB dataset using Keras and Bi-LSTM network

Text classification on IMDB dataset using Keras and Bi-LSTM Text classification on IMDB dataset using Keras and Bi-LSTM network. Usage python3 main.py

Hamza Rashid 2 Sep 27, 2022
Collection of useful (to me) python scripts for interacting with napari

Napari scripts A collection of napari related tools in various state of disrepair/functionality. Browse_LIF_widget.py This module can be imported, for

5 Aug 15, 2022