본문 바로가기
  • 데이터에 가치를 더하다, 서영석입니다.
도전 : 더 나은 사람으로/텍스트 산업 분류 공모전

[2022 통계청 공모전] 2. remove stopwords (불용어 처리)

by 꿀먹은데이터 2022. 5. 8.

check bigword split

큰 단어들을 일일이 쪼개준 뒤, 잘 쪼개져있는지 확인 후 불용어 처리를 하였다.

bigword = {key: value for key, value in count.items() if len(key)>=5 and value <50}
bigword

불용어란 ?

문장을 분석하는데 큰 의미가 없는 문자열을 의미한다. 다시 말해서 문장을 구성하는데 필수요소인 문자들이 분석에는 도움이 되지 않는 문자들을 의미한다. 이런 문자열을 추가해서 분석을 하면 분류가 잘못되는 경우가 생기므로 사전에 제거해주는 작업을 해야 한다.

Remove stopwords

import pandas as pd
stop_words = pd.read_csv('/content/drive/MyDrive/통계청_AI경진대회/한국어불용어100.txt',header=None, encoding ='utf-8',sep='\t')
stop_words = stop_words[0]
stop_words

https://wikidocs.net/77135 에 등록된 한국어 불용어 리스트를 stop_words로 받아, 이를 split된 리스트에서 처리해주는 작업을 하였다.

for i in range(len(stop_words)):
  for j in range(len(a)):
    for item in a[j]:
      if item ==stop_words[i]:
          a[j].remove(stop_words[i])

stop_words를 반복문으로 돌고, split된 리스트(a)에 stop_words와 일치하는 단어가 있을 시 , 제거하는 형식으로 진행된다.    ......... for 문이 3개나 있으니 좀 오래걸리려나...?

자체 불용어 처리

count가 많이 된 순서로 나열한 뒤, 산업 분류에 필요없을 법한 한글자나 대상 등을 불용어 처리를 해주고 임베딩을 해줘야겠다고 생각했다.

이 또한 ..  코드를 보자.

불용어 처리 코드

search=[''] #불용어 추가하면 됨.
for i in range(len(search)):
  for j in range(len(a)):
    for item in a[j]:
      if item ==search[i]:
          a[j].remove(search[i])

 search 부분에 위 코드처럼 넣고 불용어 제거를 해주면 된다.

 

관련 github code

https://github.com/rootofdata/NLP_AI_Industry_classification.git

 

GitHub - rootofdata/NLP_AI_Industry_classification

Contribute to rootofdata/NLP_AI_Industry_classification development by creating an account on GitHub.

github.com