Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View yuchenlin's full-sized avatar
:octocat:

(Bill) Yuchen Lin yuchenlin

:octocat:
View GitHub Profile
@peterjc123
peterjc123 / build.ps1
Last active November 12, 2018 16:29
Setup script for Windows PyTorch
# Prerequisites
# 1. MSVC 2017 C++ Build Tools
# 2. CMAKE 3.0 or up
# 3. 64 bits of Windows
# 4. Anaconda / MiniConda 64 bits
# Prerequisites for CUDA
# 1. CUDA 8.0 or up
# 2. NVTX( in CUDA as Visual Studio Integration. if fail to install, you can extract
# the CUDA installer exe and found the NVTX installer under the CUDAVisualStudioIntegration)
@lucaswiman
lucaswiman / foo.dot
Created May 31, 2016 06:21
networkx / graphviz example
digraph {
0 -> "*" [key=0,
label="[b]"];
1 -> "*" [key=0,
label="[d]"];
enter -> "*" [key=0,
label=ε];
"*" -> 0 [key=0,
label="[a]"];
"*" -> 1 [key=0,
@tmdavid
tmdavid / word_embedding_vis.py
Last active September 20, 2019 01:32
Visualize word embeddings, using tsne.
"""
Visualize word embeddings, using tsne.
First computes cosine distance of the 100 closests words, and then shows a clustering graph
of the first 11 closest words (the first one is always the word)
IT REQUIRES GLOVE MODEL.txt
line 31: glove_file = '../TBIR/glove.840B.300d.txt' MODIFY with the appropiate path
To Use it, you can just type: python word_embedding_vis.py <list of words space separated>
e.g: python word_embedding_vis.py cake word embedding music
"""
from transformers import GPT2Tokenizer, GPT2LMHeadModel
import torch
from torch.nn import CrossEntropyLoss
from tqdm import trange
max_length = 24
batch_size = 200
@thousandlemons
thousandlemons / how-to-setup-shadowsocks-on-your-ubuntu-server.md
Last active November 20, 2021 00:14
How to setup Shadowsocks on your Ubuntu server
@WeiTang114
WeiTang114 / nvv.sh
Created March 13, 2017 06:43
Show username after each process in nvidia-smi.
#!/bin/bash
# Show username after each process in nvidia-smi
# like:
# ...
# +------------------------------------------------------+
# | Processes: GPU Memory |
# | GPU PID Type Process name Usage |
# |======================================================|
# | 0 150752 C python 830MiB | User: user1
# | 1 2185 C /usr/bin/python 1090MiB | User: user2
@abhishekcs10
abhishekcs10 / install-gcc-5.4.0.sh
Last active June 14, 2022 03:09 — forked from jtilly/install-gcc-4.9.3.sh
Install GCC 5.4.0
#!/bin/bash
# this script installs GCC 5.4.0
# to use it navigate to your home directory and type:
# sh install-gcc-5.4.0.sh
# download and install gcc 4.9.3
wget https://github.com/gcc-mirror/gcc/archive/gcc-5_4_0-release.tar.gz
tar xzf gcc-5_4_0-release.tar.gz
cd gcc-5_4_0-release
@Tushar-N
Tushar-N / pad_packed_demo.py
Last active December 27, 2022 06:35
How to use pad_packed_sequence in pytorch<1.1.0
import torch
import torch.nn as nn
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
seqs = ['gigantic_string','tiny_str','medium_str']
# make <pad> idx 0
vocab = ['<pad>'] + sorted(set(''.join(seqs)))
# make model
@yuchenlin
yuchenlin / gpt_sent_prob.py
Last active May 21, 2023 17:12
Compute sentence probability using GPT-2 with huggingface transformers
import torch
from transformers import OpenAIGPTTokenizer, OpenAIGPTLMHeadModel
from transformers import GPT2Tokenizer, GPT2LMHeadModel
import numpy as np
from scipy.special import softmax
def model_init(model_string, cuda):
if model_string.startswith("gpt2"):
tokenizer = GPT2Tokenizer.from_pretrained(model_string)
model = GPT2LMHeadModel.from_pretrained(model_string)
@misberner
misberner / .gitignore-latex
Created January 8, 2014 13:39
.gitignore rules for LaTeX projects
# LaTeX temporary files
*.aux
*.log
*.toc
# PDF output - usually a bad idea to keep this in Git
*.pdf
# Latexmk
*.fdb_latexmk