{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "6cfd2a8c-fdfc-4233-abd1-ece097069522", "metadata": {}, "source": [ "# __텍스트 분류 모델 만들기__" ] }, { "attachments": {}, "cell_type": "markdown", "id": "a8e34895-b8e4-417f-b992-6e47dd854748", "metadata": {}, "source": [ "- 튜토리얼 난이도: ★☆☆☆☆\n", "- 읽는데 걸리는 시간: 10분\n", "- 사용 언어: [SQL](https://ko.wikipedia.org/wiki/SQL) (100%)\n", "- 실행 파일 위치: tutorial/thanosql_ml/classification/text_classification.ipynb\n", "- 참고 문서: [(캐글) IMDB Movie Reviews](https://www.kaggle.com/code/lakshmi25npathi/sentiment-analysis-of-imdb-movie-reviews/data), [ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators](https://arxiv.org/abs/2003.10555)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "ac7823c2-8b90-4d7f-bbb8-2939f57583bd", "metadata": {}, "source": [ "## 튜토리얼 소개\n", "\n", "
분류 작업은 목푯값(Target)이 속한 범주(Category 또는 Class)를 예측하기 위해 사용하는 머신러닝(기계학습/Machine Learning)의 한 형태입니다. 예를 들어, 남성 또는 여성을 분류하는 이진 분류와 동물의 종(개, 고양이, 토끼 등)을 예측하는 다중 분류 모두 분류 작업에 포함됩니다.
\n", "NLP는 작업의 목적에 따라 자연어 이해(NLU, Natural Language Understanding)와 자연어 생성(NLG, Natural Language Generation)으로 분류할 수 있습니다. 자연어 이해는 사람이 이해하는 자연어를 컴퓨터가 이해할 수 있는 값으로 바꾸는 처리를 의미합니다. 반면에 자연어 생성은 더 나아가 컴퓨터가 이해할 수 있는 값을 사람이 이해하도록 자연어로 바꾸는 과정을 의미합니다.
\n", "즉, 대량의 데이터 세트에 대한 데이터 라벨링 작업을 최소화 함으로써 더욱 많은 데이터를 효율적으로 활용할 수 있습니다.
\n", "👉 대표적인 머신러닝 경진대회 플랫폼인 캐글의 IMDB Movie Reviews 데이터 세트를 사용하여 영화 리뷰의 감정을 분류하는 모델을 만듭니다. 이 데이터 세트는 50,000 개의 영화 리뷰 텍스트와 긍정 또는 부정 감정에 대한 목푯값(Target)으로 구성되어 있습니다. 영화 평점을 기준으로 5보다 작은 값을 부정, 7보다 큰 값을 긍정으로 표현하였으며 각 개별 영화는 30 개 이상의 리뷰 결과를 갖지 않습니다.
\n", "\n", " | review | \n", "sentiment | \n", "
---|---|---|
0 | \n", "This is the kind of movie that BEGS to be show... | \n", "negative | \n", "
1 | \n", "Bulletproof is quite clearly a disposable film... | \n", "negative | \n", "
2 | \n", "A beautiful shopgirl in London is swept off he... | \n", "positive | \n", "
3 | \n", "VERY dull, obvious, tedious Exorcist rip-off f... | \n", "negative | \n", "
4 | \n", "Do we really need any more narcissistic garbag... | \n", "negative | \n", "
movie_review_train 테이블은 아래와 같은 정보를 담고 있습니다.
\n", "\n", " | review | \n", "sentiment | \n", "predict_result | \n", "
---|---|---|---|
0 | \n", "I read the book before seeing the movie, and t... | \n", "positive | \n", "positive | \n", "
1 | \n", "\"9/11,\" hosted by Robert DeNiro, presents foot... | \n", "positive | \n", "positive | \n", "
2 | \n", "Yesterday I attended the world premiere of \"De... | \n", "positive | \n", "positive | \n", "
3 | \n", "Moonwalker is a Fantasy Music film staring Mic... | \n", "positive | \n", "positive | \n", "
4 | \n", "Welcome to Oakland, where the dead come out to... | \n", "positive | \n", "positive | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
995 | \n", "I remember catching this movie on one of the S... | \n", "negative | \n", "negative | \n", "
996 | \n", "CyberTracker is set in Los Angeles sometime in... | \n", "negative | \n", "negative | \n", "
997 | \n", "There is so much that is wrong with this film,... | \n", "negative | \n", "negative | \n", "
998 | \n", "I am a firm believer that a film, TV serial or... | \n", "positive | \n", "positive | \n", "
999 | \n", "I think vampire movies (usually) are wicked. E... | \n", "negative | \n", "negative | \n", "
1000 rows × 3 columns
\n", "여기서는 빠르게 학습하기 위해 \"max_epochs\"를 1로 지정했습니다. 일반적으로 숫자가 클수록 많은 계산 시간이 소요되지만 학습이 진행됨에 따라 예측 성능이 올라갑니다.
\n", "\n", " | review | \n", "sentiment | \n", "predict_result | \n", "
---|---|---|---|
0 | \n", "I read the book before seeing the movie, and t... | \n", "positive | \n", "positive | \n", "
1 | \n", "\"9/11,\" hosted by Robert DeNiro, presents foot... | \n", "positive | \n", "positive | \n", "
2 | \n", "Yesterday I attended the world premiere of \"De... | \n", "positive | \n", "positive | \n", "
3 | \n", "Moonwalker is a Fantasy Music film staring Mic... | \n", "positive | \n", "positive | \n", "
4 | \n", "Welcome to Oakland, where the dead come out to... | \n", "positive | \n", "negative | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "
995 | \n", "I remember catching this movie on one of the S... | \n", "negative | \n", "negative | \n", "
996 | \n", "CyberTracker is set in Los Angeles sometime in... | \n", "negative | \n", "negative | \n", "
997 | \n", "There is so much that is wrong with this film,... | \n", "negative | \n", "negative | \n", "
998 | \n", "I am a firm believer that a film, TV serial or... | \n", "positive | \n", "positive | \n", "
999 | \n", "I think vampire movies (usually) are wicked. E... | \n", "negative | \n", "negative | \n", "
1000 rows × 3 columns
\n", "ThanoSQL을 활용해 나만의 모델을 만들거나, 나의 서비스에 적용하는데 어려움이 있다면 언제든 아래로 문의주세요😊
\n", "텍스트 분류 모델 구축 관련 문의: contact@smartmind.team
\n", "