Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def softmax_loss(vectors): | |
anc, pos, neg = vectors | |
c = 0.5 | |
anc = c * anc | |
pos = c * pos | |
neg = c * neg | |
pos_sim = tf.reduce_sum((anc * pos), axis=-1, keepdims=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrainingConfig: | |
def __init__(self, **kwargs): | |
self.model_name = "sbert_tuned" | |
self.data_dir = "/content/drive/MyDrive/" | |
self.module_path = "/content/bert_module/" | |
self.pretrained_ckpt = None | |
self.generation = "sbert" | |
self.ctx_len = 24 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TagCallback(Callback): | |
def __init__(self, dataset, call_model=None, name="NER_ACC"): | |
self.call_model = call_model | |
self.dataset = dataset | |
self.best = 0 | |
self.name = name | |
super(TagCallback, self).__init__() | |
def on_epoch_end(self, epoch, logs=None): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AucCallback(Callback): | |
def __init__(self, dataset, call_model=None, savepath=None, name="AUC"): | |
self.call_model = call_model | |
self.dataset = dataset | |
self.best = 0 | |
self.name = name | |
self.savepath = savepath | |
super(AucCallback, self).__init__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SBERT: | |
def __init__(self, config): | |
self.loss = 0 | |
self.metrics = [] | |
self.inputs = [] | |
self.config = config | |
self.build() | |
def build(self): | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def softmax_loss(vectors): | |
anc, pos, neg = vectors | |
c = 0.5 | |
anc = c * anc | |
pos = c * pos | |
neg = c * neg | |
pos_sim = tf.reduce_sum((anc * pos), axis=-1, keepdims=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MultitaskDataGenerator: | |
def __init__(self, generators): | |
self.generators = generators | |
self.generator = self.generate_batch() | |
def generate_batch(self, batch_size=None): | |
while True: | |
batch = self.__next__() | |
yield batch | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MulticlassGenerator: | |
def __init__(self, data_tuple, batch_size=256): | |
self._data = data_tuple | |
self._idx = np.arange(len(data_tuple[-1])) | |
self.generator = self.generate_batch(batch_size) | |
def generate_batch(self, size): | |
while True: | |
px_ids = np.random.choice(self._idx, size, replace=False) | |
samples = [p[px_ids] for p in self._data[:-1]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TripletGenerator: | |
def __init__(self, datadict, hard_frac = 0.5, batch_size=256): | |
self.datadict = datadict | |
self._anchor_idx = np.array(list(self.datadict.keys())) | |
self._hard_frac = hard_frac | |
self.generator = self.generate_batch(batch_size) | |
def generate_batch(self, size): | |
while True: |
NewerOlder