Skip to content

Instantly share code, notes, and snippets.

View robertfeldt's full-sized avatar

Robert Feldt robertfeldt

View GitHub Profile
@robertfeldt
robertfeldt / speeding_up_qgram_distances_with_precalculation_sorted_array_version_faster.jl
Created October 21, 2020 11:54
Optimized speeding up of StringDistances.jl qgram distances with precalculation of qgram counts (here in a sorted array of counts per qgram)
using StringDistances
function countdict(qgrams)
d = Dict{eltype(qgrams), Int32}()
for qg in qgrams
index = Base.ht_keyindex2!(d, qg)
if index > 0
d.age += 1
@inbounds d.keys[index] = qg
@inbounds d.vals[index] = d.vals[index][1] + 1
@robertfeldt
robertfeldt / boxes_puzzle.jl
Created July 6, 2022 03:14
Checking the "Boxes puzzle" solution strategy via stochastic simulation
# Checking the "Boxes puzzle" solution strategy via stochastic simulation.
# robert.feldt@gmail.com 2022
using Random # We need randperm below
# Fill N boxes by getting a random permutation of length N.
fillboxes(N) = randperm(N)
# Given a strategy, simulate its use by N people and return true iff strategy
# worked for them all.
@robertfeldt
robertfeldt / got_sw3_generate_text_example.jl
Created January 27, 2023 15:48
Example of generating text with GPT-SW3 from Julia
# Setup step 0: Build PyCall.jl for right Python binary
#
# Might be needed to ensure the right python is used, here for my homebrew
# installed python3 on a M1 MacBook Pro:
# ENV["PYTHON"] = "/opt/homebrew/bin/python3"
# using Pkg
# Pkg.build("PyCall")
# Setup step 1: Ensuring you have access to GPT-SW3 by setting up a token on Hugging Face
# a. login on HF: https://huggingface.co/login