%pip install "whatlies[sentence_tfm]" # quotes for my fellow zsh users
import numpy as np
from whatlies.language import SentenceTFMLanguage
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression
pipe = Pipeline([
("embed", SentenceTFMLanguage('distilbert-base-nli-stsb-mean-tokens')),
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""View remote jobs in a 3 day interval.""" | |
BASE_URL = "https://www.linkedin.com/jobs/search/" | |
def get_linkedin_jobs(search, n_days=3, remote=True): | |
# time | |
seconds_in_day = 86400 | |
n_seconds = n_days * seconds_in_day | |
query = BASE_URL + "?f_TPR=r" + str(n_seconds) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Union | |
import numpy as np | |
import pandas as pd | |
def create_sample_weights( | |
y_train: np.ndarray, | |
X_train: Union[np.ndarray, pd.DataFrame] | |
) -> pd.Series: | |
y_series = pd.DataFrame({"y": y_train})["y"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy import log, exp | |
from scipy.special import betaln as logbeta | |
def probability_B_beats_A(α_A, β_A, α_B, β_B): | |
total = 0.0 | |
for i in range(α_B): | |
total += exp( | |
logbeta(α_A + i, β_B + β_A) | |
- log(β_B + i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# venv | |
# usage: | |
# $ venv .recsys | |
function venv { | |
default_envdir=".env" | |
envdir=${1:-$default_envdir} | |
if [ ! -d $envdir ]; then | |
python3.7 -m virtualenv -p python3.7 $envdir | |
echo -e "\x1b[38;5;2m✔ Created virtualenv $envdir\x1b[0m" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
flag=$1 | |
if [[ $flag == 'DL' ]]; then | |
# ------------- | |
# Deep Learning | |
# ------------- | |
echo "Configuring GPU for Deep Learning..." | |
sudo apt-get install -y libnvidia-common-440 | |
sudo apt-get install -y cuda | |
sudo apt-get install -y cuda-drivers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <algorithm> | |
#include <functional> | |
#include <future> | |
#include <thread> | |
#include <vector> | |
// adapted from https://stackoverflow.com/a/49188371/2055486 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
theme_set(theme_classic()) | |
# Visualizing entropy --------------------------------------------------------- | |
entropy <- function(p) -sum(p * log(p)) | |
n <- 1e6 | |
p <- runif(n) | |
q <- 1 - p | |
z <- matrix(c(p, q), ncol = 2) | |
ent <- apply(z, 1, entropy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
li(ggplot2) | |
theme_set(theme_classic()) | |
entropy <- function(p) -sum(p * log(p)) | |
n <- 1e6 | |
p <- runif(n) | |
q <- 1 - p | |
z <- matrix(c(p, q), ncol = 2) | |
ent <- apply(z, 1, entropy) | |
qplot(q, ent, geom = "line") + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
li(ggplot2) | |
theme_set(theme_classic()) | |
kld <- function(p, q) sum(p * log(p / q)) | |
n <- 1e6 | |
p <- c(0.6, 0.4) | |
q1 <- runif(n) | |
q2 <- 1 - q1 | |
z <- matrix(c(q1, q2), ncol = 2) | |
kl <- apply(z, 1, kld, p = p) |
NewerOlder