MCPcopy Create free account
hub / github.com/brightmart/text_classification / transform_multilabel_as_multihot

Function transform_multilabel_as_multihot

a02_TextCNN/data_util.py:52–62  ·  view source on GitHub ↗

convert to multi-hot style :param label_list: e.g.[0,1,4], here 4 means in the 4th position it is true value(as indicate by'1') :param label_size: e.g.199 :return:e.g.[1,1,0,1,0,0,........]

(label_list,label_size)

Source from the content-addressed store, hash-verified

50
51
52def transform_multilabel_as_multihot(label_list,label_size):
53 """
54 convert to multi-hot style
55 :param label_list: e.g.[0,1,4], here 4 means in the 4th position it is true value(as indicate by'1')
56 :param label_size: e.g.199
57 :return:e.g.[1,1,0,1,0,0,........]
58 """
59 result=np.zeros(label_size)
60 #set those location as 1, all else place as 0.
61 result[label_list] = 1
62 return result
63
64#use pretrained word embedding to get word vocabulary and labels, and its relationship with index
65def create_vocabulary(training_data_path,vocab_size,name_scope='cnn'):

Callers 1

load_data_multilabelFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected