Oct 11, 2018

Compile tensorflow and opencv from source

Tensorflow

sudo apt install python3-dev python3-pip
pip install -U pip six numpy wheel mock
pip install -U keras_applications==1.0.5 keras_preprocessing==1.0.3 --no-deps

./configure  # see 'View sample configuration session' here https://www.tensorflow.org/install/source
bazel build --config=opt --config=cuda --config=mkl --config=monolithic //tensorflow/tools/pip_package:build_pip_package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
pip install /tmp/tensorflow_pkg/tensorflow-1.12.0-cp36-cp36m-linux_x86_64.whl

cuDNN

Instructions here: https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html

Bazel

Follow instructions: https://docs.bazel.build/versions/master/install-ubuntu.html#using-bazel-custom-apt-repository
Download from https://github.com/bazelbuild/bazel/releases
Be sure Java installed

# Bazel 18.1 for TF r1.12 
# Details why so: https://github.com/tensorflow/tensorflow/issues/23401

chmod +x bazel--installer-linux-x86_64.sh
./bazel--installer-linux-x86_64.sh --user

# add:
# export PATH="$PATH:$HOME/bin"
# to ~/.bashrc

git clone https://github.com/tensorflow/tensorflow
git checkout r1.12
https://www.tensorflow.org/install/source

Opencv

https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/

ln -s /usr/local/lib/python3.6/site-packages/cv2.so cv2.so
cp -r ~/anaconda3/envs/opencv_build/lib/python3.6/site-packages/cv2/ ~/anaconda3/envs/tf_build/lib/python3.6/site-packages/

Feb 26, 2018

Extract lemmas

Docs
# conda install spacy
# python -m spacy download en

In[1]: import spacy
In[2]: nlp = spacy.load('en')

In[3]: doc = nlp("Hello, my cruel world. I'm leaving you tonight.")

In[4]: list(doc.sents)
Out[4]: [Hello, my cruel world., I'm leaving you tonight.]

In[5]: list(doc)
Out[5]: [Hello,, , my, cruel, world,., I, 'm, leaving, you, tonight, .]

In[6]: doc[8]
Out[6]: leaving
In[7]: doc[8].lemma
Out[7]: 9707179535890930240
In[8]: doc[8].lemma_
Out[8]: 'leave'

In[9]: doc[8].pos_
Out[9]: 'VERB'

In[10]: from spacy import displacy
In[11]: displacy.serve(doc, style='dep')