Skip to content

Instantly share code, notes, and snippets.

@ksopyla
ksopyla / polish_sentence_nltk_tokenizer.py
Last active September 19, 2022 07:29
A curated list of Polish abbreviations for NLTK sentence tokenizer based on Wikipedia text
import nltk
# interactive download
# nltk.download()
nltk.download('punkt')
extra_abbreviations = [
"ps",
"inc",
"corp",
@thomwolf
thomwolf / gradient_accumulation.py
Last active January 16, 2024 02:38
PyTorch gradient accumulation training loop
model.zero_grad() # Reset gradients tensors
for i, (inputs, labels) in enumerate(training_set):
predictions = model(inputs) # Forward pass
loss = loss_function(predictions, labels) # Compute loss function
loss = loss / accumulation_steps # Normalize our loss (if averaged)
loss.backward() # Backward pass
if (i+1) % accumulation_steps == 0: # Wait for several backward steps
optimizer.step() # Now we can do an optimizer step
model.zero_grad() # Reset gradients tensors
if (i+1) % evaluation_steps == 0: # Evaluate the model when we...
@mordr
mordr / note.md
Last active March 18, 2024 20:58
Set Visual Studio Code as default editor for kubectl

Set KUBE_EDITOR to Visual Studio Code, assumes 'code' is in PATH

export KUBE_EDITOR='code --wait'

Running k edit ... will open up the yaml using Visual Studio Code.

LWin & WheelUp::
; Previous Desktop
Send {LWin down}{Ctrl down}{Left down}{LWin up}{Ctrl up}{Left up}
return
LWin & WheelDown::
; Next Desktop
Send {LWin down}{Ctrl down}{Right down}{LWin up}{Ctrl up}{Right up}
return
@zaus
zaus / DelayedRenderExtensions.cs
Created September 27, 2013 18:06
RenderSections in PartialViews -- delayed rendering of any HTML content. See SO answer: http://stackoverflow.com/a/18790222/1037948
public static class HtmlRenderExtensions {
/// <summary>
/// Delegate script/resource/etc injection until the end of the page
/// <para>@via http://stackoverflow.com/a/14127332/1037948 and http://jadnb.wordpress.com/2011/02/16/rendering-scripts-from-partial-views-at-the-end-in-mvc/ </para>
/// </summary>
private class DelayedInjectionBlock : IDisposable {
/// <summary>
/// Unique internal storage key
/// </summary>
@schlamar
schlamar / processify.py
Last active April 17, 2024 19:19
processify
import os
import sys
import traceback
from functools import wraps
from multiprocessing import Process, Queue
def processify(func):
'''Decorator to run a function as a process.
Be sure that every argument and the return value

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name: