Implementing Cosine in C from Scratch

web.archive.org
implementing-cosine-in-c-from-scratch

Implementing cosine in C from scratch 7/19/2020 Update 7/20: See the discussion of this post on Reddit. TL;DR: I explored how to implement cosine using a few different approaches. One of the implementations is nearly 3x faster than math.h if … Read more

Implementing Value Speculation in OCaml

lortex.org
implementing-value-speculation-in-ocaml

CPUs are very good at doing things in parallel, even in a single core context. Indeed, speculative execution of code and instruction reordering helps the CPU ensure that the pipeline is always full. However, data dependencies in the sequence of … Read more

Implementing Gradient Explanations for a HuggingFace Text Classification Model

victordibia.com
implementing-gradient-explanations-for-a-huggingface-text-classification-model

def get_gradients(text, model, tokenizer): def get_correct_span_mask(correct_index, token_size): span_mask = np.zeros((1, token_size)) span_mask[0, correct_index] = 1 span_mask = tf.constant(span_mask, dtype=‘float32’) return span_mask embedding_matrix = model.bert.embeddings.weights[0] encoded_tokens = tokenizer(text, return_tensors=“tf”) token_ids = list(encoded_tokens[“input_ids”].numpy()[0]) vocab_size = embedding_matrix.get_shape()[0] token_ids_tensor = tf.constant([token_ids], dtype=‘int32’) token_ids_tensor_one_hot = … Read more