This guide has been updated for elementaryOS v5.0+.
sudo apt-get update
sudo apt-get -y install software-properties-common
from __future__ import print_function | |
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
from torch.autograd import Variable | |
def sample_gumbel(shape, eps=1e-20): | |
U = torch.rand(shape).cuda() | |
return -Variable(torch.log(-torch.log(U + eps) + eps)) |
# PyTorch code For implementing the mixture of softmaxes layer from | |
# "Breaking the Softmax Bottleneck: A High-Rank RNN Language Model" | |
# https://arxiv.org/abs/1711.03953 | |
context = self.fc(out) | |
# Non-log version | |
priors = F.softmax(context[:,-self.n_components:]) | |
mixtures = torch.stack([priors[:,i].unsqueeze(1) * F.softmax(context[:, i * self.nClasses : (i + 1) * self.nClasses]) for i in range(self.n_components)],1) | |
out = torch.log(mixtures.sum(1)) |
/* Binarized neural network inference example. | |
This shows a simple C++ program for doing inference on | |
binarized neural networks. To do this efficiently, the code | |
below makes use of the "bitset" class, which uses the "popcnt" | |
instruction to count the number of 1's that show up in the | |
matrix product, in constant time. This means that a matrix | |
multiplication between a (A, B) and (B, C) matrix takes | |
O(A * C) time; in other words, each value in the output matrix | |
is computed in constant time. | |
*/ |
#!/usr/bin/env bash | |
# The following assumes you have a pyenv virtualenv named faiss. Tested on | |
# Ubuntu 16.04. | |
set -eox pipefail | |
# shellcheck disable=SC1090 | |
source "${HOME}/.pyenv.sh" |
""" | |
Simple example of manually performing "automatic" differentiation | |
""" | |
import numpy as np | |
from numpy import exp, sin, cos | |
def f(x, with_grad=False): | |
# Need to cache intermediates from forward pass (might not use all of them). | |
a = exp(x) |
#!/bin/bash | |
# usage: | |
# first make the file executable | |
# ./word2vec-download300model.sh output-file | |
OUTPUT=$( wget --save-cookies cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=0B7XkCwpI5KDYNlNUTTlSS21pQmM' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/Code: \1\n/p' ) | |
CODE=${OUTPUT##*Code: } | |
echo $CODE |
# http://www.nvidia.com/download/driverResults.aspx/117079/en-us | |
wget http://us.download.nvidia.com/tesla/375.51/nvidia-driver-local-repo-ubuntu1604_375.51-1_amd64.deb | |
sudo dpkg -i nvidia-driver-local-repo-ubuntu1604_375.51-1_amd64.deb | |
sudo apt-get update | |
sudo apt-get -y install cuda-drivers | |
echo "Reboot required." |