Giter Site home page Giter Site logo

klue-level2-nlp-04's Introduction

KLUE_Relation Extraction

image

๐Ÿ”ฅ Getting Started

Dependencies

torch==1.7.1
transformers==4.10.0
pandas==1.1.5
scikit-learn==0.24.1
matplotlib==3.3.4
tqdm==4.51.0
numpy==1.19.2
glob2==0.7

Install Requirements

  • pip install -r requirements.txt

Contents

  • hyperparameter_search.py
  • inference.py
  • load_data.py
  • loss.py
  • model.py
  • new_mlm.py : MLM ์ ์šฉ
  • train.py
  • utils.py
  • train_v1.csv : 40% of no_relation data

Training

  • SM_CHANNEL_TRAIN=[train csv data dir] SM_MODEL_DIR=[model saving dir] python train.py

Inference

  • SM_CHANNEL_EVAL=[test csv dir] SM_CHANNEL_MODEL=[model saved dir] SM_OUTPUT_DATA_DIR=[inference output dir] python inference.py

๐Ÿ” Overview

Background

๊ด€๊ณ„ ์ถ”์ถœ(Relation Extraction)์ด๋ž€ ๋ฌธ์žฅ์˜ ๋‹จ์–ด(Entity)์— ๋Œ€ํ•œ ์†์„ฑ๊ณผ ๊ด€๊ณ„๋ฅผ ์˜ˆ์ธกํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.
๋ฌธ์žฅ ์†์—์„œ ๋‹จ์–ด๊ฐ„์— ๊ด€๊ณ„์„ฑ์„ ํŒŒ์•…ํ•˜๋Š” ๊ด€๊ณ„ ์ถ”์ถœ(Relation Extraction)์€ ์ง€์‹ ๊ทธ๋ž˜ํ”„ ๊ตฌ์ถ•์„ ์œ„ํ•œ ํ•ต์‹ฌ ๊ตฌ์„ฑ ์š”์†Œ๋กœ, ๊ตฌ์กฐํ™”๋œ ๊ฒ€์ƒ‰, ๊ฐ์ • ๋ถ„์„, ์งˆ๋ฌธ ๋‹ต๋ณ€ํ•˜๊ธฐ, ์š”์•ฝ๊ณผ ๊ฐ™์€ ์ž์—ฐ์–ด์ฒ˜๋ฆฌ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์—์„œ ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. ๋น„๊ตฌ์กฐ์ ์ธ ์ž์—ฐ์–ด ๋ฌธ์žฅ์—์„œ ๊ตฌ์กฐ์ ์ธ triple์„ ์ถ”์ถœํ•ด ์ •๋ณด๋ฅผ ์š”์•ฝํ•˜๊ณ , ์ค‘์š”ํ•œ ์„ฑ๋ถ„์„ ํ•ต์‹ฌ์ ์œผ๋กœ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Problem definition

์ฃผ์–ด์ง„ ๋ฌธ์žฅ๊ณผ ๋ฌธ์žฅ์˜ ๋‹จ์–ด(subject entity, object entity)๋ฅผ ์ด์šฉํ•˜์—ฌ,
subject entity์™€ object entity๊ฐ€ ์–ด๋–ค ๊ด€๊ณ„๊ฐ€ ์žˆ๋Š”์ง€ ์˜ˆ์ธกํ•˜๋Š” ์‹œ์Šคํ…œ or ๋ชจ๋ธ ๊ตฌ์ถ•ํ•˜๊ธฐ

Development environment

  • GPU V100 ์›๊ฒฉ ์„œ๋ฒ„
  • PyCharm ๋˜๋Š” Visual Studio Code | Python 3.7(or over)

Evaluation

image

Dataset Preparation

Prepare Images

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-10-08 แ„‹แ…ฉแ„’แ…ฎ 3 27 35

  • train.csv: ์ด 32470๊ฐœ
  • test_data.csv: ์ด 7765๊ฐœ (์ •๋‹ต ๋ผ๋ฒจ์€ blind = 100์œผ๋กœ ์ž„์˜ ํ‘œํ˜„)
  • Input: ๋ฌธ์žฅ๊ณผ ๋‘ Entity์˜ ์œ„์น˜(start_idx, end_idx)
  • Target: ์นดํ…Œ๊ณ ๋ฆฌ 30๊ฐœ ์ค‘ 1๊ฐœ

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-10-08 แ„‹แ…ฉแ„’แ…ฎ 3 29 58

Data Labeling

  • ํฌ๊ฒŒ no-relation, org, per๊ธฐ์ค€ 30๊ฐœ์˜ ํด๋ž˜์Šค๋กœ ๋ถ„๋ฅ˜

๐Ÿƒ Training

# ๋‹จ์ผ ๋ชจ๋ธ train ์‹œ
$ python new_mlm.py 

Train Models

# ๋‹จ์ผ ๋ชจ๋ธ train ์‹œ
$ python train.py 

Stratified K-fold

from sklearn.model_selection import StratifiedKFold
# cross_validation ์‚ฌ์šฉํ•ด train ์‹œ
$ python train.py --cv True

train.py cross_validation ํ•จ์ˆ˜

๐Ÿ’ญ Inference

# cross_validation ์„ ์‚ฌ์šฉ์•ˆํ• ์‹œ
$ python inference.py \
  --model_name={kinds of models} \
  --model_dir={model_filepath} \
  --output_name={output_filename} \
  --inference_type=default \
  --run_name = exp\
  --cv = False\
  --tem = (typed entitiy ์‚ฌ์šฉ์‹œ True, ์•„๋‹ˆ๋ฉด False)
# cross_validation ์„ ์‚ฌ์šฉํ•ด ๋‚˜์˜จ model 5๊ฐœ๋ฅผ ํ†ตํ•ด inference ์‹œ
$ python inference.py \
  --model_name={kinds of models} \
  --model_dir={model_filepath} \
  --output_name={output_filename} \
  --inference_type = cv\
  --run_name = exp\
  --cv = True\
  --tem = (if typed entity: True, else: False)

klue-level2-nlp-04's People

Contributors

raki-1203 avatar singonkim avatar whatchang avatar sangjun-leee avatar kimziont avatar pseeej avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.