to find out which of the synsets to takewe would have to really understand the meaning of the tweetswhich is beyond the scope of this the field of research that focuses on this challenge is called word sense disambiguation for our taskwe take the easy route and simply average the scores over all the synsets in which term is found for "fantasize"posscore would be and negscore would be the following functionload_sent_word_net()does all that for usand returns dictionary where the keys are strings of the form "word type/word"for example "nimplant"and the values are the positive and negative scoresimport csvcollections def load_sent_word_net()sent_scores collections defaultdict(listwith open(os path join(data_dirsentiwordnet__ txt")" "as csvfilereader csv reader(csvfiledelimiter='\ 'quotechar='"'for line in readerif line[ startswith("#")continue if len(line)== continue pos,id,posscore,negscore,synsetterms,gloss line if len(pos)== or len(id)== continue #print pos,posscore,negscore,synsetterms for term in synsetterms split(")drop number at the end of every term term term split("#")[ term term replace("-""replace(" ""key "% /% "%(pos,term split("#")[ ]sent_scores[keyappend((float(posscore)float(negscore))for keyvalue in sent_scores iteritems()sent_scores[keynp mean(valueaxis= return sent_scores