자연어 처리 중 연관단어를 확인하기 위한 방법으로 n-gram을 사용합니다.

 

가장 보편적으로 사용되는 2개의 연속된 단어를 확인하는 bigram 사용해봤습니다. 

 

nltk 패키지 bigrams 사용했습니다.

 

from nltk import bigrams #nltk에 bigrams 패키지 사용

#전처리
noun = df['content'].apply(lambda x : [item for item in x if item not in stop_words]) #불용어 제거
noun = df['content'].apply(lambda x : [word for word in if len(word) > 1]) #글자 수가 1개보다 적은 단어는 제거

bgrams = [bigrams(word) for word in noun] #bgrams라는 변수에 전처리된 단어들을 적용

token = []
for i in bgrams:
    token += ([x for x in i])

 

 

 

 

 

 

 

 

+ Recent posts