Skip to content

Instantly share code, notes, and snippets.

import torch
import torch.nn as nn
import torch.nn.functional as F
class SoftMultiTokenEmbedding(nn.Module):
"""
A MultiToken embedding layer that performs soft merging of adjacent tokens
without requiring attention mask modifications.
"""
def __init__(self, vocab_size, embedding_dim, dropout_rate=0.1):
@mrorigo
mrorigo / cpu.c
Last active October 9, 2022 14:21
Cycle exact 6502 (2A03) emulator in <1k lines of C
/**
* Copyright (C) 2022 orIgo <[email protected]>
*
* Cycle exact 6502 (2A03) emulator.
*
* - To initialize the cpu, provide an initialized `cpu_bus_t *` with memory read/write primitives to `cpu_init()` .
* - For each tick/cycle, call `cpu_tick()` with the returned `cpu_t *`, checking the return value to detect HLT.
* - To cause an NMI request, call `cpu_nmi()`.
*/
#include "cpu.h"
@mrorigo
mrorigo / Log4Simple.java
Last active December 30, 2021 09:45
Log4Simple
import java.util.LinkedList;
import java.nio.charset.Charset;
import java.io.IOException;
import java.io.OutputStream;
import java.io.FileOutputStream;
public class Log4Simple
{
public enum Level {
@mrorigo
mrorigo / double_cola.erl
Created October 10, 2021 08:32
Double Cola problem in Erlang
%% Double Cola problem in Erlang
%% https://codeforces.com/problemset/problem/82/A
-module(main).
-export([start/1]).
start(N) ->
io:fwrite(
cola(N-1, [ {"Sheldon", 1},
{"Leonard", 1},