Skip to content

Instantly share code, notes, and snippets.

View tlkahn's full-sized avatar
πŸ₯«

JG tlkahn

πŸ₯«
View GitHub Profile
@tlkahn
tlkahn / askgpt.el
Created April 7, 2025 05:52
My emacs copilot
(defun insert-json-entries (json-str)
(let ((json-object-type 'hash-table))
(cl-loop for entry across (json-read-from-string json-str) do
(maphash (lambda (key value)
(insert (format (if (string= key "role") "## %s:\n\n" "%s\n\n")
(string-trim value "[ \t\n\r.]+"))))
entry))))
(defun ask-for-input ()
"Prompt the user for input using the minibuffer."
set nocompatible
syntax on
set number
set relativenumber
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set hlsearch
set incsearch
@tlkahn
tlkahn / toy_word2vec.py
Created February 2, 2025 03:16
toyword2vec
# -*- coding: utf-8 -*-
"""toy-word2vec.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1Lk3Td9MXzndT0ld1iaCF6FbggKCzBa2Z
"""
import jax
@tlkahn
tlkahn / a.md
Created January 31, 2025 12:53
dealing with bad code

user:

found the source code of many AI papers hard to read, partially because the authors are not in the mindset of software engineers, therefore the code is not aligned to software engineering best practices. How to solve this problem? I want to understand the code so that I can master the concetps in the papers more thourougly through code reading

assistant:

Reading and fully understanding research code can be challenging, especially when code bases don’t follow traditional software engineering (SE) best practices. Here are some suggestions for getting more out of (often messy) AI research code:

  1. Organize the Context Before Diving In β€’ Read the paper thoroughly. Make note of the key steps in the algorithm, the architectural components, and the logic flow. Then map these steps to the filenames, modules, and functions you see in the code.
@tlkahn
tlkahn / a.md
Created January 30, 2025 04:08
line breaks in minibuffer of emacs

In Emacs, the minibuffer is typically used for single-line input, so pressing RET (Enter) usually submits the input. However, if you need to input a line break (newline) in the minibuffer, you can do so by using the following methods: Method 1: Use C-q C-j

Press C-q (quoted-insert), followed by C-j (newline).

This inserts a literal newline character into the minibuffer.

Method 2: Use C-o

Press C-o (open-line), which inserts a newline and moves the cursor to the new line.

@tlkahn
tlkahn / a.md
Last active January 30, 2025 01:57
reward model equation

The reward model equation represents the negative log-likelihood loss for training the reward model $r_{\phi}$:

  1. $r_{\phi}(x, y)$ is the reward model with parameters $\phi$.

  2. $(x, y_w, y_l)$ is a tuple from the dataset $\mathcal{D}$, where:

    • $x$ is the input
    • $y_w$ is the preferred output
    • $y_l$ is the less preferred output
  3. $\sigma(z) = \frac{1}{1+e^{-z}}$ is the logistic function.

@tlkahn
tlkahn / gist:b721e20b525bfb1c5971266bda3a81b8
Last active January 30, 2025 01:11
some deep RL papers
@tlkahn
tlkahn / a.md
Created January 29, 2025 21:45
RLHF prototype
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F

# Mock dataset
def create_mock_dataset(vocab_size, seq_len, num_pairs):
    preferred = torch.randint(0, vocab_size, (num_pairs, seq_len))
    non_preferred = torch.randint(0, vocab_size, (num_pairs, seq_len))
@tlkahn
tlkahn / a.md
Created January 28, 2025 02:20
skimpdf link creation

Below is a working example of how to create (1) a simple AppleScript application that registers a custom URL scheme, and (2) links that open a given PDF at a given page in Skim.

────────────────────────────────────────────────────────

  1. Create the AppleScript ────────────────────────────────────────────────────────
  2. Open β€œScript Editor” (in /Applications/Utilities).
  3. Create a new document and paste this script:

-- This handler is called when a URL with the scheme "skimpdf://" is opened.

@tlkahn
tlkahn / main.py
Created January 18, 2025 02:08
CMU-advanced-nlp-schedule.py
from icalendar import Calendar, Event
from datetime import datetime, timedelta
cal = Calendar()
cal.add("prodid", "-//My Calendar//mxm.dk//")
cal.add("version", "2.0")
classes = [
(
1,