예제 #1
0
 word_vectors = nlp.read_word_vectors(VECTOR_DIR + VECTOR_NAME)
 word_pairs = nlp.read_csv(CSV_DIR + CSV_NAME)
 print "CSV", CSV_NAME
 vocab = []
 for p in word_pairs:
     vocab.append(p[0].lower())
     vocab.append(p[1].lower())
 vocab = list(set(vocab))
 for w in vocab:
     word_hypernyms[w] = nlp.read_hypernyms(w)
     word_hyponyms[w] = nlp.read_hyponyms(w)
     word_synonyms[w] = nlp.read_synonyms(w)
     senses[w] = nlp.read_senses(w)
     for s in senses[w]:
         sense_vectors[s] = np.zeros(VECTOR_DIM)
         sense_hypernyms[s] = nlp.read_hypernyms_by_sense(s)
         sense_hyponyms[s] = nlp.read_hyponyms_by_sense(s)
         sense_synonyms[s] = nlp.read_synonyms_by_sense(s)
         sense_pool[s] = nlp.get_pooling(s, sense_hypernyms, sense_synonyms,
                                         sense_hyponyms, word_vectors,
                                         VECTOR_DIM)
         if (word_vectors.has_key(w)):
             sense_pool[s] = sense_pool[s] + word_vectors[w]
         sense_vectors[s] = sense_pool[s]
         for l in s.lemmas():
             word = str(l.name())
             word_hypernyms[word] = nlp.read_hypernyms(word)
             word_hyponyms[word] = nlp.read_hyponyms(word)
             word_synonyms[word] = nlp.read_synonyms(word)
             word_pool[word] = nlp.get_pooling(word, word_hypernyms,
                                               word_synonyms, word_hyponyms,
예제 #2
0
        else:
            continue
        if ( m_score > 0.0 ):
            machine_score.append(m_score)
            human_score.append(float(p[2]))
    p_val, p_rel = sci.stats.spearmanr(human_score, machine_score)
    print "Simple Linear Approach", p_val
if __name__ == "__main__":
    word_vectors = nlp.read_word_vectors(VECTOR_DIR + VECTOR_NAME)
    word_pairs = nlp.read_csv(CSV_DIR + CSV_NAME)
    vocab = []
    for p in word_pairs:
        vocab.append(p[0].lower())
        vocab.append(p[1].lower())
    vocab = list(set(vocab))
    for w in vocab:
        word_hypernyms[w] = nlp.read_hypernyms(w)
        word_hyponyms[w] = nlp.read_hyponyms(w)
        word_synonyms[w] = nlp.read_synonyms(w)
        senses[w] = nlp.read_senses(w)
        for s in senses[w]:
            sense_vectors[s] = np.zeros(VECTOR_DIM)
            sense_hypernyms[s] = nlp.read_hypernyms_by_sense(s)
            sense_hyponyms[s] = nlp.read_hyponyms_by_sense(s)
            sense_synonyms[s] = nlp.read_synonyms_by_sense(s)
            sense_vectors[s] = nlp.get_pooling(s, sense_hypernyms,sense_synonyms,sense_hyponyms, word_vectors, VECTOR_DIM)
            if ( word_vectors.has_key(w)):
                sense_vectors[s] = sense_vectors[s] + word_vectors[w]
        word_pool[w] = nlp.get_pooling(w, word_hypernyms, word_synonyms, word_hyponyms, word_vectors, VECTOR_DIM)
    test_sense_vectors()
예제 #3
0
파일: cnn_sense.py 프로젝트: xu94-nlp/nlp
if __name__ == "__main__":
    word_pairs = nlp_lib.read_csv( CSV_DIR + CSV_NAME )
    for w_pair in word_pairs:
        vocab.append( w_pair[0].lower() )
        vocab.append( w_pair[1].lower() )
    #remove duplicated words in csv file
    vocab = list(set(vocab))
    word_vectors = nlp_lib.read_word_vectors(VECTOR_DIR + VECTOR_NAME)
    #read word senses
    for w in vocab:
        word_senses[w] = nlp_lib.read_senses(w)
    #read word senses' hyponyms
    for w in vocab:
        for s in word_senses[w]:
            word_sense_hyponyms[s] = nlp_lib.read_hyponyms_by_sense(s)
            word_sense_hypernyms[s] = nlp_lib.read_hypernyms_by_sense(s)
            word_sense_synonyms[s] = nlp_lib.read_synonyms_by_sense(s)
            word_sense_full_pooling[s] = get_full_pooling_sense(s, w)
    #read for retrofitting
    for w in vocab:
        word_hyponyms[w] = nlp_lib.read_hyponyms(w)
        word_hypernyms[w] = nlp_lib.read_hypernyms(w)
        word_synonyms[w] = nlp_lib.read_synonyms(w)

    for w in vocab:
        print "word",w
        if ( word_vectors.has_key(w) ):
            print "has a vector"
        else:
            print "no vector for it"