コード例 #1
0
ファイル: yehova-4.py プロジェクト: Chan01Ge/fnc-1-yehova
def generate_features(stances, dataset, name, bow_vectorizer, tfreq_vectorizer,
                      tfidf_vectorizer):
    h, b, y = [], [], []

    for stance in stances:
        y.append(LABELS.index(stance['Stance']))
        h.append(stance['Headline'])
        b.append(dataset.articles[stance['Body ID']])

    X_overlap = gen_or_load_feats(word_overlap_features, h, b,
                                  "features/overlap." + name + ".npy")

    # X_refuting_body: I add a new refuting feature about the existence of refuting words in the body
    X_refuting_head, X_refuting_body = refuting_features(h, b)

    X_polarity = gen_or_load_feats(polarity_features, h, b,
                                   "features/polarity." + name + ".npy")
    X_hand = gen_or_load_feats(hand_features, h, b,
                               "features/hand." + name + ".npy")

    # X_senti_head: The sentiment vector of the headline;
    # X_senti_body:  The sentiment vector of the body;
    # X_senti_cos : The cosine similarity between the sentiment vectors of the headline and body.

    X_senti_head, X_senti_body, X_senti_cos = sentiment_features(h, b)

    # X_tf_cos : The cosine similarity between the TF vectors of the headline and body
    # X_tf_idf_cos : The cosine similarity between the TF-IDF vectors of the headline and body.
    X_tf_cos, X_tf_idf_cos = gen_tf_idf_feats(stances, dataset.articles,
                                              bow_vectorizer, tfreq_vectorizer,
                                              tfidf_vectorizer)

    X = np.c_[X_hand, X_polarity, X_refuting_head, X_overlap, X_tf_cos]
    return X, y
コード例 #2
0
def classify(headline, body, clf):
    h = [headline]
    b = [body]

    X_overlap = word_overlap_features(h, b)
    X_refuting = refuting_features(h, b)
    X_polarity = polarity_features(h, b)
    X_hand = hand_features(h, b)

    X = np.c_[X_hand, X_polarity, X_refuting, X_overlap]

    predicted = [LABELS[int(a)] for a in clf.predict(X)]

    return predicted
コード例 #3
0
    def get_feature(self):
        dataset = DataSet(path=self.path, name=self.name)
        h, b = [], []
        stances = dataset.stances
        for stance in stances:
            h.append(stance['Headline'])
            b.append(dataset.articles[stance['Body ID']])

        X_overlap = word_overlap_features(h, b)
        X_refuting = refuting_features(h, b)
        X_polarity = polarity_features(h, b)
        X_hand = hand_features(h, b)

        X = np.c_[X_hand, X_polarity, X_refuting, X_overlap]
        return X