Agent skill · research science · aradotso
llm-internals-learning
llm-internals-learning — an agent skill for coding agents.
Why this skill is useful
Includes executable implementations of core LLM concepts like tokenization and attention mechanisms that extend the AI's capabilities.
What it needs
About 9k tokens when loaded. Last updated 2026-07-09. 70 stars on the source repository.
What this skill does
python from collections import defaultdict def getvocab(text: str) -> dict: """Build initial character-level vocabulary with end-of-word marker.""" vocab = defaultdict(int) for word in text.strip().split(): chars = " ".join(list(word)) + " </w>" vocab[chars] += 1 return dict(vocab) def getpairs(vocab: dict) -> dict: """Count all adjacent symbol pairs in the vocabulary.""" pairs = defaultdict(int) for word, freq in vocab.items(): symbols = word.split() for i in range(len(symbols) - 1): pairs[(symbols[i], symbols[i + 1])] += freq return dict(pairs) def mergevocab(pair: tuple, vocab: dict) -> dict: """Merge the most frequent pair throughout the vocabulary.""" newvocab = {} bigram = " ".join(pair) replacement = "".join(pair) for word in vocab: newword = word.replace(bigram, replacement) newvocab[newword] = vocab[word] return newvocab def runbpe(text: str, nummerges: int = 10) -> list: """Run BPE algorithm for nummerges iterations.""" vocab = getvocab(text) merges = [] for in range(nummerges): pairs = getpairs(vocab) if not pairs: break bestpair = max(pairs, key=pairs.get) vocab = mergevocab(bestpair, vocab) merges.append(bestpair) print(f"Merged: {bestpair} -> {''.join(bestpair)}") return merges Example usage text = "low lower lowest newer newest" merges = runbpe(text, nummerges=8) python import numpy as np def scaleddotproductattention(Q: np.ndarray, K: np.ndarray, V: np.ndarray, mask: np.ndarray = None) -> tuple: """ Compute scaled dot-product attention. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills aradotso/llm-internals-learning