2016-10-30 6 views
5

मैं ध्रुवीय स्कोर प्राप्त करने के लिए वेदर सेंटीमेंट विश्लेषक का उपयोग कर रहा हूं। मैंने पहले सकारात्मक/नकारात्मक/तटस्थ के लिए संभाव्यता स्कोर का उपयोग किया, लेकिन मुझे अभी "कंपाउंड" स्कोर का एहसास हुआ, जो -1 (सबसे नकारात्मक) से 1 (अधिकांश pos) तक की ध्रुवीयता का एक उपाय प्रदान करेगा। मुझे आश्चर्य है कि कैसे "यौगिक" स्कोर गणना की। क्या यह [pos, neu, neg] वेक्टर से गणना की जाती है? भावनाओं केपाथर एनएलटीके में वडर 'कंपाउंड' ध्रुवीयता स्कोर की गणना कैसे की जाती है?

+0

कोड पर है nltk/भावना/vader.py – alvas

उत्तर

24
4 करने के लिए

VADER एल्गोरिथ्म आउटपुट भावना स्कोर कक्षाएं https://github.com/nltk/nltk/blob/develop/nltk/sentiment/vader.py#L441:

  • neg: नकारात्मक
  • neu: तटस्थ
  • pos: सकारात्मक
  • compound: यौगिक (यानी एकत्रित अंक)
compound = normalize(sum_s) 

normalize() समारोह https://github.com/nltk/nltk/blob/develop/nltk/sentiment/vader.py#L107 पर इस तरह के रूप में परिभाषित किया गया है::

def normalize(score, alpha=15): 
    """ 
    Normalize the score to be between -1 and 1 using an alpha that 
    approximates the max expected value 
    """ 
    norm_score = score/math.sqrt((score*score) + alpha) 
    return norm_score 

तो वहाँ एक हाइपर-पैरामीटर हैके कोड के माध्यम से चलना है, यौगिक का पहला उदाहरण https://github.com/nltk/nltk/blob/develop/nltk/sentiment/vader.py#L421, जहां यह गणना करता है alpha

sum_s का सवाल है, यह भावना तर्क score_valence() समारोह https://github.com/nltk/nltk/blob/develop/nltk/sentiment/vader.py#L413

के लिए पारित की राशि है और अगर हम वापस का पता लगाने के लिए इस sentiment तर्क है, हम देखते हैं कि यह जब https://github.com/nltk/nltk/blob/develop/nltk/sentiment/vader.py#L217 पर polarity_scores() फ़ंक्शन को कॉल की गणना की है:

def polarity_scores(self, text): 
    """ 
    Return a float for sentiment strength based on the input text. 
    Positive values are positive valence, negative value are negative 
    valence. 
    """ 
    sentitext = SentiText(text) 
    #text, words_and_emoticons, is_cap_diff = self.preprocess(text) 

    sentiments = [] 
    words_and_emoticons = sentitext.words_and_emoticons 
    for item in words_and_emoticons: 
     valence = 0 
     i = words_and_emoticons.index(item) 
     if (i < len(words_and_emoticons) - 1 and item.lower() == "kind" and \ 
      words_and_emoticons[i+1].lower() == "of") or \ 
      item.lower() in BOOSTER_DICT: 
      sentiments.append(valence) 
      continue 

     sentiments = self.sentiment_valence(valence, sentitext, item, i, sentiments) 

    sentiments = self._but_check(words_and_emoticons, sentiments) 

polarity_scores समारोह को देखते हुए, यह क्या कर रहा है पूरे SentiText शब्दकोश और नियम आधारित sentiment_valence() वें आवंटित करने के लिए समारोह के साथ चेक के माध्यम से पुनरावृति करने के लिए है भावना https://github.com/nltk/nltk/blob/develop/nltk/sentiment/vader.py#L243 के लिए ई संयोजक स्कोर, की धारा 2.1.1 देखने http://comp.social.gatech.edu/papers/icwsm14.vader.hutto.pdf

तो यौगिक स्कोर के लिए वापस जा, हम देखते हैं कि:

  • compound स्कोर sum_s की एक सामान्यीकृत स्कोर और
  • है sum_s कुछ ह्यूरिस्टिक्स और एक भावना लेक्सिकॉन (उर्फ) के आधार पर गणना की गई वैलेंस का योग है। भावना तीव्रता) और
  • सामान्यीकृत स्कोर केवल sum_s है जो इसके वर्ग प्लस अल्फा पैरामीटर से विभाजित है जो सामान्यीकरण फ़ंक्शन के संप्रदाय को बढ़ाता है।

गणना की है कि [स्थिति, neu, बातचीत और विवाद] वेक्टर से है?

वास्तव =)

अगर हम score_valence समारोह https://github.com/nltk/nltk/blob/develop/nltk/sentiment/vader.py#L411 पर एक नज़र डालें, हम देखते हैं कि यौगिक स्कोर sum_s स्थिति, बातचीत और विवाद और neu स्कोर से पहले के साथ की जाती है कि गणना करता _sift_sentiment_scores() का उपयोग कर की गणना योग के बिना sentiment_valence() से कच्चे स्कोर का उपयोग करके invidiual pos, neg और neu scores।


अगर हम इस alpha mathemagic पर एक नज़र डालें, ऐसा लगता है सामान्यीकरण की उत्पादन नहीं बल्कि अस्थिर है (यदि स्वेच्छापूर्ण छोड़ दिया), alpha के मूल्य के आधार:

alpha=0:

enter image description here

alpha=15:

enter image description here

alpha=50000:

enter image description here

alpha=0.001:

enter image description here

यह अजीब हो जाता है जब यह नकारात्मक है:

alpha=-10:

enter image description here

alpha=-1,000,000:

enter image description here

alpha=-1,000,000,000: https://github.com/nltk/nltk/blob/develop/:

enter image description here

+0

बहुत अच्छी स्पष्टीकरण, ऐसा लगता है कि आप ग्राफ और equatio में sqrt भाग खो रहे हैं एनएस –

संबंधित मुद्दे