데이터과학 삼학년

PMI(Pointwise Mutual Information); 점별 상호 정보량 본문

Natural Language Processing

PMI(Pointwise Mutual Information); 점별 상호 정보량

Dan-k 2022. 11. 27. 22:16
반응형

점별 상호 정보량 (Poinstwise Mutual Information)

- NLP에서 각 단어간 상관성을 확인하기위한 단위로 쓸 수 있는 개념

- 두 확률변수 사이의 상관성을 계량화하는 단위

- 두 확률 변수가 완전한 독립, 예를 들면 단어 A의 등장이 단어 B에 등장에 전혀 영향을 주지 않는 경우에 PMI값은 0이 됨

- 해당 수치는 두단어가 얼마나 자주 같이 등장하는지에 관한 정보를 수치화한 개념

 

- PMI 수치는 음수로 나올 수 있다. log(0)는 -inf 이기 때문 따라서 negative PMI를 핸들링하기 위해 아래식 처럼 capping해 줄 수 있음

- PMI를 구할때 주의할 점은 stopwords를 삭제할 필요가 있다는 것!!!

from nltk.collocations import BigramCollocationFinder, BigramAssocMeasures
from nltk.tokenize import word_tokenize
import nltk
nltk.download('punkt')

text = "this is a foo bar bar black sheep  foo bar bar black sheep foo bar bar black sheep shep bar bar black sentence"

bigram_measures = BigramAssocMeasures()
finder = BigramCollocationFinder.from_words(word_tokenize(text))
for i in finder.score_ngrams(bigram_measures.pmi):
    print(i)

 

참조

https://www.listendata.com/2022/06/pointwise-mutual-information-pmi.html

 

Pointwise mutual information (PMI) in NLP

This tutorial describes interpretation and calculation of Pointwise mutual information (PMI) in NLP. It also includes how to run PMI in Python and R.

www.listendata.com

 

728x90
반응형
LIST
Comments