These instructions are based on Mistobaan's gist but expanded and updated to work with the latest tensorflow OSX CUDA PR.
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 numpy as np | |
# vectors is an array of vectors of any length | |
vectors = np.array(vectors, dtype=np.float32) | |
print('normalize %s vectors' % len(vectors)) | |
vectors = vectors / np.linalg.norm(vectors, ord=2, axis=1, keepdims=True) |
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 pickle as pk | |
with open('filename.pk', 'rb') as filehandler: | |
obj = pk.load(filehandler) | |
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 knn_cosine_search(x, D, K): | |
""" find K nearest neighbours of data among D """ | |
ndata = len(D) | |
K = K if K < ndata else ndata | |
# euclidean distances from the other points | |
x = x.reshape(1, -1) | |
cos = cdist(D, x, 'cosine').reshape(-1) | |
idx = np.argsort(cos) # sorting | |
# return the indexes of K nearest neighbours |
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 knn_euclidean_search(x, D, K): | |
""" find K nearest neighbours of data among D """ | |
ndata = len(D) | |
K = K if K < ndata else ndata | |
# euclidean distances from the other points | |
sqd = np.sqrt(((D - x)**2).sum(axis=1)) | |
idx = np.argsort(sqd) # sorting | |
# return the indexes of K nearest neighbours | |
idx = idx[:K] | |
d = sqd[idx] |
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
x#! /bin/bash | |
# use XCode 8.2.1 | |
export TF_TYPE=”cpu” | |
export TF_NEED_GCP=0 | |
export TF_NEED_HDFS=0 | |
export TF_NEED_AWS=0 | |
export TF_NEED_KAFKA=0 | |
export TF_ENABLE_XLA=1 | |
export TF_NEED_GDR=0 | |
export TF_NEED_VERBS=0 |
How to compile TensorFlow 1.6-rc1 on macOS High Sierra 10.13.3 with GPU acceleration and optionally eGPU support.
source: https://byai.io/howto-tensorflow-1-6-on-mac-with-gpu-acceleration/
Caution - you have to disable SIP (System Integrity Protection)
- NVIDIA Web-Drivers
- CUDA-Drivers
I hereby claim:
- I am vseledkin on github.
- I am apfelson (https://keybase.io/apfelson) on keybase.
- I have a public key ASDIO3bGsJnLc8uayvwOjez7HcHNdbVDjDRGKhmGdbTKrgo
To claim this, I am signing this object:
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
func substitute(text, before, after string, positions [][]int) string { | |
// flatten | |
flatten_positions := make([]int, 2*len(positions)) | |
for i, pos := range positions { | |
flatten_positions[2*i] = pos[0] | |
flatten_positions[2*i+1] = pos[1] | |
} | |
sort.Ints(flatten_positions) | |
var count int |
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
func SplitToNGrams(s string, n []int) []string { | |
words := strings.Fields(s) | |
var tokens []string | |
for cursor, _ := range words { | |
for _, ni := range n { | |
// get suffix of length ni in words back from ni position in words array | |
if cursor+ni <= len(words) { | |
tokens = append(tokens, strings.Join(words[cursor:cursor+ni], "•")) | |
} | |
} |
NewerOlder