Skip to content

Instantly share code, notes, and snippets.

@HarshTrivedi
HarshTrivedi / pad_packed_demo.py
Last active July 5, 2024 22:47 — forked from Tushar-N/pad_packed_demo.py
Minimal tutorial on packing (pack_padded_sequence) and unpacking (pad_packed_sequence) sequences in pytorch.
import torch
from torch import LongTensor
from torch.nn import Embedding, LSTM
from torch.autograd import Variable
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
## We want to run LSTM on a batch of 3 character sequences ['long_str', 'tiny', 'medium']
#
# Step 1: Construct Vocabulary
# Step 2: Load indexed data (list of instances, where each instance is list of character indices)
@bowbowbow
bowbowbow / hashtag_baseline.py
Last active June 16, 2018 17:16
TOP K=10, Mean Average Precision : 0.87821
import json
import random
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn import preprocessing
json_data = open('./dataset.json').read()
tweets = json.loads(json_data)
tweets_train, tweets_test = [], []
@ihsgnef
ihsgnef / colorize_text.py
Last active May 22, 2024 09:56
Visualize attention over text with background colors
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
def colorize(words, color_array):
# words is a list of words
# color_array is an array of numbers between 0 and 1 of length equal to words
cmap = matplotlib.cm.get_cmap('RdBu')
template = '<span class="barcode"; style="color: black; background-color: {}">{}</span>'
colored_string = ''
@seanbehan
seanbehan / app.py
Last active March 13, 2023 04:55
Flask with Django ORM
'''
Run the following commands (bc. gists don't allow directories)
pip install flask django dj-database-url psycopg2
mkdir -p app/migrations
touch app/__init__.py app/migrations/__init__.py
mv models.py app/
python manage.py makemigrations
python manage.py migrate
sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev -y
sudo apt-get install libfreetype6 libfreetype6-dev -y
sudo apt-get install libfontconfig1 libfontconfig1-dev -y
cd ~
export PHANTOM_JS="phantomjs-2.1.1-linux-x86_64"
wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/$PHANTOM_JS.tar.bz2
sudo tar xvjf $PHANTOM_JS.tar.bz2
sudo mv $PHANTOM_JS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
// iconv-lite 를 이용하여 한글이 깨져서 출력될때 수정하는 방법
var request = require("request");
var cheerio = require('cheerio');
var iconv = require('iconv-lite');
var requestOptions = { method: "GET"
,uri: "http://news.naver.com/main/list.nhn?mode=LS2D&mid=shm&sid1=105&sid2=731"
,headers: { "User-Agent": "Mozilla/5.0" }
,encoding: null
};
@moeseth
moeseth / waveform.py
Created October 12, 2015 08:19
Create Soundcloud style waveform from Audio in Python
from pydub import AudioSegment
from matplotlib import pyplot as plot
from PIL import Image, ImageDraw
import numpy as np
import os
src = "./test.mp3"
audio = AudioSegment.from_file(src)
data = np.fromstring(audio._data, np.int16)
@pleaseshutup
pleaseshutup / getCAbundle.js
Created October 10, 2012 15:49
node.js certificate issues with https.createServer and nodejitsu's http-proxy
//Thanks to:
//http://www.benjiegillam.com/2012/06/node-dot-js-ssl-certificate-chain/
//For the code to pass a CA bundle (multiple certs in one file) as an array
//which fixes certificate errors on some browsers when doing https.createServer(options
//This is how you can fix that with nodejitsu's http-proxy when using SNI
// to have a server listening and returning multiple ssl certs