Skip to content

Instantly share code, notes, and snippets.

View davidlowjw's full-sized avatar

David Low davidlowjw

View GitHub Profile
@SuperShinyEyes
SuperShinyEyes / f1_score.py
Created October 15, 2019 10:16
F1 score in PyTorch
def f1_loss(y_true:torch.Tensor, y_pred:torch.Tensor, is_training=False) -> torch.Tensor:
'''Calculate F1 score. Can work with gpu tensors
The original implmentation is written by Michal Haltuf on Kaggle.
Returns
-------
torch.Tensor
`ndim` == 1. 0 <= val <= 1
@bittlingmayer
bittlingmayer / ft_wiki_preproc.py
Last active March 4, 2019 22:56
fastText pre-trained vectors preprocessing [moved to ftio.wiki.preproc - pip install ftio / https://github.com/SignalN/ftio]
# See https://github.com/facebookresearch/fastText/blob/master/get-wikimedia.sh
#
# From https://github.com/facebookresearch/fastText/issues/161:
#
# We now have a script called 'get-wikimedia.sh', that you can use to download and
# process a recent wikipedia dump of any language. This script applies the preprocessing
# we used to create the published word vectors.
#
# The parameters we used to build the word vectors are the default skip-gram settings,
# except with a dimensionality of 300 as indicated on the top of the list of word
@bittlingmayer
bittlingmayer / fasttext_similarity.py
Created June 10, 2017 12:50
Similarity for two files output by fastText print-word-vectors or print-sentence-vectors
"""
Takes two files produced by fastText's print-word-vectors or print-sentence-vectors and compares the vectors by similarity.
(See https://github.com/facebookresearch/fastText.)
This can be useful for benchmarking output or even generating benchmark data.
For example:
@MihailJP
MihailJP / gpufan.bash
Created November 5, 2013 13:02
Script to control the fan speed automatically (works only for NVIDIA graphic cards)
#!/bin/bash
# Script to control the fan speed automatically
setFanSpeed() {
eval "nvidia-settings -a GPUFanControlState=1 -a [fan:0]/GPUCurrentFanSpeed=$1 > /dev/null"
}
cleanup() {
eval "nvidia-settings -a GPUFanControlState=0"