Skip to content

Instantly share code, notes, and snippets.

View rasbt's full-sized avatar

Sebastian Raschka rasbt

View GitHub Profile
@rasbt
rasbt / reasoning-inference-scaling-gh-models-examples.ipynb
Created April 3, 2025 17:23
Reasoning Model Inference Scaling Example with DeepSeek and GitHub Models
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rasbt
rasbt / llama-vs-gemma.py
Created March 13, 2025 15:51
Compute memory usage for various LLMs like Gemma, Llama, etc.
# Sebastian Raschka 2025
#
#
# Usage:
# python llama-vs-gemma.py \
# --auth_token hf_... \
# --model_name meta-llama/Llama-3.2-1B \
# --prompt medium
import argparse
@rasbt
rasbt / transformer-outline.py
Created January 21, 2024 00:01
Transformer PyTorch Pseudo Code
import torch.nn as nn
class Transformer(nn.Module):
def __init__(self, ...):
super().__init__()
...
self.encoder_layers = nn.ModuleList(...)
self.decoder_layers = nn.ModuleList(...)
...
@rasbt
rasbt / chatgpt-summarize.py
Created May 6, 2023 13:02
Script using the ChatGPT API to summarize text
# pip install openai
import openai
import os
# export API key environment variable before
# running this script (see https://platform.openai.com/account/api-keys)
# E.g.,
#
# export OPENAI_API_KEY=copy_paste_key_from_your_account
@rasbt
rasbt / whisper-audio-to-text.py
Created January 26, 2023 17:46
Transcribes audio files using OpenAI Whisper
# Setup:
# conda create -n whisper python=3.9
# conda activate whisper
# https://github.com/openai/whisper
# pip install git+https://github.com/openai/whisper.git
# Usage:
# python whisper-audio-to-text.py --audio_dir my_files --out_dir texts
import argparse
@rasbt
rasbt / video-subtitles-via-whisper.py
Last active March 20, 2025 13:55
Script that creates subtitles (closed captions) for all MP4 video files in your current directory
# Sebastian Raschka 09/24/2022
# Create a new conda environment and packages
# conda create -n whisper python=3.9
# conda activate whisper
# conda install mlxtend -c conda-forge
# Install ffmpeg
# macOS & homebrew
# brew install ffmpeg
# Ubuntu
@rasbt
rasbt / onehot-numeric-mixed-data.csv
Last active July 7, 2022 16:44
A 3-class sample dataset with numeric and categorical features
categorical measurement1 measurement2 label measurement3
F 1.428571429 2.721312902 0 2.089
R 0.685939167 0.982976329 0 0.637
P 1.055817143 0.624210021 0 0.226
S 0.995956364 0.321101265 0 0.138
R 1.376773333 1.578308527 0 0.478
R 0.837229167 1.549647481 0 0.169
Q 1.552222941 2.641907404 0 1.599
E 1.492519333 2.634558656 0 1.052
W 0.816596667 1.168353374 0 0.432
@rasbt
rasbt / classifier-calibration.py
Created April 13, 2022 16:36
Classifier Calibration -- A Minimal Example
import numpy as np
from sklearn.datasets import make_classification
from sklearn.model_selection import cross_val_score
from sklearn.tree import DecisionTreeClassifier
from sklearn.calibration import CalibratedClassifierCV
X, y = make_classification(
n_samples=1000, n_features=5, n_redundant=2,
n_clusters_per_class=1, random_state=123)
@rasbt
rasbt / .zshrc
Created February 10, 2022 18:37
Minimal zshell config
### EYECANDY ###
autoload -U colors && colors
PS1="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% "
export CLICOLOR=1
#export LSCOLORS=ExFxBxDxCxegedabagacad
#alias ls='ls -GFh'
### END
@rasbt
rasbt / miniforge-m1-pytorch-env.yml
Created February 6, 2022 16:12
Relatively Minimal Miniforge environment for M1 Mac
name: base
channels:
- conda-forge
dependencies:
- absl-py=1.0.0=pyhd8ed1ab_0
- aiohttp=3.8.1=py39h5161555_0
- aiosignal=1.2.0=pyhd8ed1ab_0
- anyio=3.5.0=py39h2804cbe_0
- appnope=0.1.2=py39h2804cbe_2
- argh=0.26.2=pyh9f0ad1d_1002