Skip to content

Instantly share code, notes, and snippets.

View JGalego's full-sized avatar
:fishsticks:
dependable.critical-ai.dev

João Galego JGalego

:fishsticks:
dependable.critical-ai.dev
View GitHub Profile
@JGalego
JGalego / integer_tokenization_is_insane.ipynb
Last active September 17, 2024 14:13
Replicating Beren Millidge's Integer Tokenization is Insane 🤯
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JGalego
JGalego / contrastive_learning.py
Last active September 24, 2024 02:21
Train an image embedding model from scratch using contrastive learning
# pylint: disable=import-error,invalid-name
"""
Train image embeddings model from scratch using contrastive learning.
Adapted from Hadsell, Chopra & LeCun (2005)
https://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf
and Underfitted's 'Training a model to generate image embeddings'
https://underfitted.svpino.com/p/training-a-model-to-generate-image
"""
@JGalego
JGalego / alphafold_explorer.py
Last active October 9, 2024 22:05
AlphaFold Protein Structure Database Explorer 🧬🔍
# pylint: disable=line-too-long
"""
A simple Streamlit app for exploring the AlphaFold Protein Structure Database 🧬🔍
Want to learn more? Check out the 'AlphaFold: A Practical Guide' online tutorial
https://www.ebi.ac.uk/training/online/courses/alphafold/
"""
from urllib.request import urlretrieve
@JGalego
JGalego / gpt_dev.ipynb
Last active October 11, 2024 14:21
Companion notebook for Andrej Karpathy's ' Let's build GPT: from scratch, in code, spelled out'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JGalego
JGalego / language_gap_explorer.py
Created October 11, 2024 16:54
Dash app to explore the languagegap 💬🧭
# pylint: disable=redefined-outer-name
r"""
Explore the language gap with Amazon Bedrock 💬🧭⛰️
_ . , . .
* / \_ * / \_ _ * * /\'__ *
/ \ / \, (( . _/ / \ *'.
. /\/\ /\/ :' __ \_ ` _^/ ^/ `--.
/ \/ \ _/ \-'\ * /.' ^_ \_ .'\ *
/\ .- `. \/ \ /==~=-=~=-=-;. _/ \ -. `_/ \
/ `-.__ ^ / .-'.--\ =-=~_=-=~=^/ _ `--./ .-' `-
@JGalego
JGalego / eça.txt
Created October 18, 2024 17:31
Dataset containing all works from the portuguese writer Eça de Queirós 🪶 http://figaro.fis.uc.pt/queiros/lista_obras.html
This file has been truncated, but you can view the full file.
CENAS PORTUGUESAS
I
A Capital!
(começos de uma carreira)
Eça de Queirós
@JGalego
JGalego / fractan.py
Created October 19, 2024 21:46
Yet another FRACTAN interpreter
# pylint: disable=invalid-name,line-too-long
r"""
______ _____ _____ _______ _____ _ _
| ____| __ \ /\ / ____|__ __| __ \ /\ | \ | |
| |__ | |__) | / \ | | | | | |__) | / \ | \| |
| __| | _ / / /\ \| | | | | _ / / /\ \ | . ` |
| | | | \ \ / ____ \ |____ | | | | \ \ / ____ \| |\ |
|_| |_| \_\/_/ \_\_____| |_| |_| \_\/_/ \_\_| \_|
FRACTRAN is a Turing-complete programming language invented by the mathematican John Conway.
@JGalego
JGalego / mame.rb
Created October 21, 2024 09:41
Adapted from Yusuke Endoh's (AKA mame) talk at RubyConf ♦️ 'Esoteric, Obfuscated, Artistic Programming in Ruby'
# Adapted from Yusuke Endoh's (AKA mame) talk at RubyConf ♦️
# 'Esoteric, Obfuscated, Artistic Programming in Ruby'
# https://www.youtube.com/watch?v=6K7EmeptEHo
# Numbers with symbols
puts "@"=~/$/ # => 1
puts "@@"=~/$/ # => 2
# Letters with numbers
puts "" << 72 << 101 << 108 \
@JGalego
JGalego / p_adic.py
Last active November 1, 2024 14:58
1 Billion is Tiny in an Alternate Universe: Introduction to p-adic Numbers 🤯
"""
Playing around with p-adic numbers and modular arithmetic.
Inspired by the '1 Billion is Tiny in an Alternate Universe' video
https://www.youtube.com/watch?v=j5s0h42GfvM
"""
import matplotlib.pyplot as plt
# How high a power do we want to go
@JGalego
JGalego / hopfield.py
Last active September 15, 2025 14:47
Implementation of a traditional Hopfield network in Python 🧠
# pylint: disable=invalid-name,non-ascii-name,line-too-long
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "numpy",
# "matplotlib",
# "Pillow",
# ]
# ///