Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Run and manage Google Colab notebooks for Python and ML research
.claude/skills/brycewang-stanford-google-colab-guide/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-03 | ✗→✓ | ▲ Improved | 108% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 150% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 94% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 111% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 198% | 0% |
Run Python code, train machine learning models, and perform data analysis using Google Colab's free cloud-hosted Jupyter notebooks with GPU and TPU access. This skill covers setup, resource management, persistent storage, and best practices for reproducible research computing.
Google Colab (Colaboratory) provides free access to GPU-accelerated Jupyter notebooks running on Google's cloud infrastructure. For academic researchers, Colab eliminates the barrier of expensive hardware for machine learning experiments, large-scale data processing, and computationally intensive statistical analyses. The free tier includes NVIDIA T4 GPUs, and paid tiers (Colab Pro, Pro+) offer A100 GPUs and extended runtime.
Colab notebooks run in ephemeral virtual machines that are recycled after inactivity or maximum runtime. This creates unique challenges for research: managing persistent data, saving checkpoints, reproducing results, and working with large datasets. This skill addresses these challenges with proven patterns used by ML researchers worldwide.
Colab integrates natively with Google Drive for storage, GitHub for version control, and supports the full Python scientific computing ecosystem (NumPy, pandas, scikit-learn, PyTorch, TensorFlow, JAX). Each notebook runs in an isolated environment with root access, allowing installation of any Linux package or Python library.
python# Check current runtime type import subprocess result = subprocess.run(['nvidia-smi'], capture_output=True, text=True) print(result.stdout) # Shows GPU info if GPU runtime is selected # Check available resources import psutil print(f"RAM: {psutil.virtual_memory().total / 1e9:.1f} GB") print(f"CPU cores: {psutil.cpu_count()}") print(f"Disk: {psutil.disk_usage('/').total / 1e9:.1f} GB")
| Runtime | GPU | RAM | Use Case | |---------|-----|-----|----------| | CPU | None | ~12 GB | Data cleaning, text processing, small models | | T4 GPU (free) | 16 GB VRAM | ~12 GB | Training medium models, inference | | A100 GPU (Pro) | 40 GB VRAM | ~50 GB | Large model training, LLM fine-tuning | | TPU v2 (free) | 8 cores | ~12 GB | JAX/TensorFlow distributed training |
pythonfrom google.colab import drive drive.mount('/content/drive') # Access files in Drive import pandas as pd df = pd.read_csv('/content/drive/MyDrive/research/dataset.csv')
python# From URL !wget -q https://example.com/dataset.zip -O /content/dataset.zip !unzip -q /content/dataset.zip -d /content/data/ # From Kaggle !pip install -q kaggle !mkdir -p ~/.kaggle # Upload kaggle.json API key first !kaggle datasets download -d user/dataset-name -p /content/data/ # From Hugging Face !pip install -q datasets from datasets import load_dataset dataset = load_dataset("scientific_papers", "arxiv")
Since Colab VMs are ephemeral, always save important outputs to Google Drive:
pythonimport shutil from pathlib import Path DRIVE_BASE = Path("/content/drive/MyDrive/research/experiment_001") DRIVE_BASE.mkdir(parents=True, exist_ok=True) def save_checkpoint(model, optimizer, epoch, loss): """Save training checkpoint to Google Drive.""" checkpoint = { 'epoch': epoch, 'model_state_dict': model.state_dict(), 'optimizer_state_dict': optimizer.state_dict(), 'loss': loss } path = DRIVE_BASE / f"checkpoint_epoch_{epoch}.pt" torch.save(checkpoint, path) print(f"Checkpoint saved to {path}") def save_results(df, name): """Save results DataFrame to Drive.""" path = DRIVE_BASE / f"{name}.csv" df.to_csv(path, index=False) print(f"Results saved to {path}")
python!pip install -q torch torchvision import torch import torch.nn as nn from torch.utils.data import DataLoader # Automatic device selection device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') print(f"Using device: {device}") model = MyModel().to(device) optimizer = torch.optim.AdamW(model.parameters(), lr=1e-4) criterion = nn.CrossEntropyLoss() for epoch in range(num_epochs): model.train() total_loss = 0 for batch in train_loader: inputs, labels = batch[0].to(device), batch[1].to(device) optimizer.zero_grad() outputs = model(inputs) loss = criterion(outputs, labels) loss.backward() optimizer.step() total_loss += loss.item() avg_loss = total_loss / len(train_loader) print(f"Epoch {epoch+1}/{num_epochs}, Loss: {avg_loss:.4f}") # Save checkpoint every 5 epochs if (epoch + 1) % 5 == 0: save_checkpoint(model, optimizer, epoch + 1, avg_loss)
python!pip install -q transformers accelerate from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer model_name = "allenai/scibert_scivocab_uncased" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForSequenceClassification.from_pretrained( model_name, num_labels=5 ) trainer = Trainer( model=model, args=training_args, train_dataset=train_dataset, eval_dataset=eval_dataset, tokenizer=tokenizer ) trainer.train() # Save to Drive model.save_pretrained(str(DRIVE_BASE / "fine_tuned_scibert"))
python# Install specific versions for reproducibility !pip install -q transformers==4.40.0 datasets==2.18.0 evaluate==0.4.1 # Install from GitHub !pip install -q git+https://github.com/huggingface/peft.git # Install system packages !apt-get -qq install -y graphviz texlive-latex-base
pythonimport random import numpy as np import torch def set_seed(seed=42): """Set all random seeds for reproducibility.""" random.seed(seed) np.random.seed(seed) torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False set_seed(42)
python# Generate requirements for reproducibility !pip freeze > /content/drive/MyDrive/research/requirements.txt # Restore environment in new session !pip install -q -r /content/drive/MyDrive/research/requirements.txt
python# Monitor GPU memory !nvidia-smi # Clear GPU cache torch.cuda.empty_cache() # Use mixed precision training for 2x speedup from torch.cuda.amp import autocast, GradScaler scaler = GradScaler() for batch in train_loader: optimizer.zero_grad() with autocast(): outputs = model(inputs) loss = criterion(outputs, labels) scaler.scale(loss).backward() scaler.step(optimizer) scaler.update()
Colab disconnects after 90 minutes of inactivity (free tier). Strategies:
tqdm progress bars to show activitypython# Clone a research repository !git clone https://github.com/user/research-repo.git /content/repo # Push results back %cd /content/repo !git config user.email "researcher@university.edu" !git config user.name "Researcher" !git add results/ !git commit -m "Add experiment results from Colab" !git push
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→fail | 21,803 | 20,749 | -5% | 1 | 1 | 0% | 4,234 | 5,399 | +28% | 0 | 0 | — |
case-02 | pass→pass | 13,637 | 13,882 | +2% | 1 | 1 | 0% | 2,389 | 4,633 | +94% | 0 | 0 | — |
case-03 | fail→pass | 8,329 | 6,001 | -28% | 1 | 1 | 0% | 1,415 | 2,947 | +108% | 0 | 0 | — |
case-04 | pass→pass | 9,027 | 3,495 | -61% | 1 | 1 | 0% | 1,314 | 2,778 | +111% | 0 | 0 | — |
case-05 | pass→pass | 5,510 | 3,788 | -31% | 1 | 1 | 0% | 904 | 2,695 | +198% | 0 | 0 | — |
case-06 | fail→fail | 10,960 | 13,338 | +22% | 1 | 1 | 0% | 2,061 | 4,343 | +111% | 0 | 0 | — |
case-07 | pass→pass | 11,391 | 9,416 | -17% | 1 | 1 | 0% | 2,052 | 3,896 | +90% | 0 | 0 | — |
case-08 | pass→pass | 10,003 | 7,703 | -23% | 1 | 1 | 0% | 1,590 | 3,667 | +131% | 0 | 0 | — |
case-09 | fail→pass | 10,086 | 11,821 | +17% | 1 | 1 | 0% | 1,730 | 4,326 | +150% | 0 | 0 | — |
case-10 | pass→pass | 6,028 | 2,948 | -51% | 1 | 1 | 0% | 972 | 2,586 | +166% | 0 | 0 | — |
case-11 | pass→pass | 12,391 | 9,033 | -27% | 1 | 1 | 0% | 2,003 | 3,914 | +95% | 0 | 0 | — |
case-12 | pass→pass | 8,619 | 2,048 | -76% | 1 | 1 | 0% | 1,641 | 2,531 | +54% | 0 | 0 | — |
case-13 | fail→fail | 16,412 | 19,796 | +21% | 1 | 1 | 0% | 2,253 | 5,101 | +126% | 0 | 0 | — |
case-14 | pass→pass | 10,657 | 7,485 | -30% | 1 | 1 | 0% | 1,912 | 3,532 | +85% | 0 | 0 | — |
case-20 | pass→pass | 14,541 | 11,631 | -20% | 1 | 1 | 0% | 2,617 | 4,244 | +62% | 0 | 0 | — |
case-15 | pass→pass | 4,490 | 3,234 | -28% | 1 | 1 | 0% | 782 | 2,545 | +225% | 0 | 0 | — |
case-16 | pass→pass | 8,163 | 5,912 | -28% | 1 | 1 | 0% | 1,322 | 3,355 | +154% | 0 | 0 | — |
case-17 | pass→pass | 10,820 | 8,731 | -19% | 1 | 1 | 0% | 2,132 | 3,472 | +63% | 0 | 0 | — |
case-18 | pass→pass | 7,733 | 2,161 | -72% | 1 | 1 | 0% | 1,147 | 2,422 | +111% | 0 | 0 | — |
case-19 | pass→pass | 6,105 | 2,222 | -64% | 1 | 1 | 0% | 900 | 2,482 | +176% | 0 | 0 | — |
case-21 | pass→pass | 9,508 | 10,226 | +8% | 1 | 1 | 0% | 1,831 | 3,865 | +111% | 0 | 0 | — |
case-22 | pass→pass | 14,687 | 14,437 | -2% | 1 | 1 | 0% | 2,398 | 4,754 | +98% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +9 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.