fixed wrong number of bits for binary encoding
This commit is contained in:
+5
-5
@@ -13,7 +13,7 @@ class Label:
|
|||||||
class Fitter(Model):
|
class Fitter(Model):
|
||||||
def __init__(self, dim: tuple[int,int], work_dir: str = '.'):
|
def __init__(self, dim: tuple[int,int], work_dir: str = '.'):
|
||||||
super().__init__(f"label-{dim[0]}x{dim[1]}", work_dir)
|
super().__init__(f"label-{dim[0]}x{dim[1]}", work_dir)
|
||||||
self.unit1 = Entity(dim, EntityParams(), TrainingParams(num_epochs=5000, do_rao_blackwell=False, momentum=0.9))
|
self.unit1 = Entity(dim, EntityParams(), TrainingParams(num_epochs=5000, do_rao_blackwell=True, momentum=0.9))
|
||||||
|
|
||||||
def forward(self, x: Mat) -> Mat:
|
def forward(self, x: Mat) -> Mat:
|
||||||
return self.unit1.forward(x)
|
return self.unit1.forward(x)
|
||||||
@@ -26,7 +26,7 @@ class Label:
|
|||||||
if encoding == Label.EncodingType.Binary:
|
if encoding == Label.EncodingType.Binary:
|
||||||
self.label2vec = self.label2vec_binary
|
self.label2vec = self.label2vec_binary
|
||||||
self.vec2label = self.vec2label_binary
|
self.vec2label = self.vec2label_binary
|
||||||
self.fitter = Label.Fitter((round(math.log(voc_size,2)), num_dim), work_dir)
|
self.fitter = Label.Fitter((math.ceil(math.log(voc_size,2)), num_dim), work_dir)
|
||||||
elif encoding == Label.EncodingType.OneHot:
|
elif encoding == Label.EncodingType.OneHot:
|
||||||
self.label2vec = self.label2vec_onehot
|
self.label2vec = self.label2vec_onehot
|
||||||
self.vec2label = self.vec2label_onehot
|
self.vec2label = self.vec2label_onehot
|
||||||
@@ -46,7 +46,7 @@ class Label:
|
|||||||
return dec_data
|
return dec_data
|
||||||
|
|
||||||
def label2vec_binary(self, list_of_labels: np.array):
|
def label2vec_binary(self, list_of_labels: np.array):
|
||||||
num_bits = round(math.log(self.voc_size,2))
|
num_bits = math.ceil(math.log(self.voc_size,2))
|
||||||
batch = np.zeros((len(list_of_labels), num_bits))
|
batch = np.zeros((len(list_of_labels), num_bits))
|
||||||
for index, label in enumerate(list_of_labels):
|
for index, label in enumerate(list_of_labels):
|
||||||
b = self._enc_binary(label, num_bits)
|
b = self._enc_binary(label, num_bits)
|
||||||
@@ -87,10 +87,10 @@ class Label:
|
|||||||
return np.argmax(label_vecs, axis=-1)
|
return np.argmax(label_vecs, axis=-1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
voc_size = 100
|
voc_size = 10000
|
||||||
|
|
||||||
# Create Labeler
|
# Create Labeler
|
||||||
enc = Label(voc_size, 16, work_dir="../../results", encoding=Label.EncodingType.OneHot)
|
enc = Label(voc_size, 16, work_dir="../../results", encoding=Label.EncodingType.Binary)
|
||||||
|
|
||||||
# Load
|
# Load
|
||||||
enc.fitter.init(0.1)
|
enc.fitter.init(0.1)
|
||||||
|
|||||||
Reference in New Issue
Block a user