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
import torch | |
import pytorch_lightning as pl | |
class MyTransformer(pl.LightningModule): | |
def __init__( | |
self, | |
learning_rate=0.001, | |
warmup=4000, | |
): | |
self.learning_rate = learning_rate |
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
import faiss | |
import numpy as np | |
class FaissKMeans: | |
def __init__(self, n_clusters=8, n_init=10, max_iter=300): | |
self.n_clusters = n_clusters | |
self.n_init = n_init | |
self.max_iter = max_iter | |
self.kmeans = None |
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
import torch | |
from torch.utils.data import Dataset, DataLoader | |
import numpy as np | |
class MyDataset(Dataset): | |
def __init__(self): | |
x = np.random.rand(1000, 3) # 1000 3-dim samples | |
self.x = [x[i].tolist() for i in range(1000)] | |
y = np.random.randint(low=0, high=2, size=(1000,)) |
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
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 | |
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
"""Hack to add per-session state to Streamlit. | |
Usage | |
----- | |
>>> import SessionState | |
>>> | |
>>> session_state = SessionState.get(user_name='', favorite_color='black') | |
>>> session_state.user_name | |
'' |
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 tensorflow.contrib.tensorboard.plugins import projector | |
import tensorflow as tf | |
import numpy as np | |
import os | |
meta_file = "g2x_metadata.tsv" | |
output_path = "./projections" | |
# read embedding file into list and get the size | |
with open('./ft_model.vec', 'r') as embedding_file: |
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 bs4 import BeautifulSoup | |
from markdown import markdown | |
import re | |
def markdown_to_text(markdown_string): | |
""" Converts a markdown string to plaintext """ | |
# md -> html -> text since BeautifulSoup can extract text cleanly | |
html = markdown(markdown_string) |
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
# Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208 | |
# Configuration name server-1 generated for Luke at 2014-10-22 09:47:40 | |
[mysql] | |
# CLIENT # | |
port = 3306 | |
socket = /var/lib/mysql/mysql.sock | |
[mysqld] |
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
#!/usr/bin/env python | |
from __future__ import print_function, division | |
import argparse | |
import json | |
import sys | |
from gzip import GzipFile | |
def concat_claims(claims): | |
for rel_id, rel_claims in claims.iteritems(): |
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
>>> import itertools | |
>>> import string | |
>>> from elasticsearch import Elasticsearch,helpers | |
es = Elasticsearch() | |
>>> # k is a generator expression that produces | |
... # a series of dictionaries containing test data. | |
... # The test data are just letter permutations | |
... # created with itertools.permutations. | |
... # | |
... # We then reference k as the iterator that's |
NewerOlder