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
# activate the conda environment to use | |
conda activate tutorial | |
# go to the work dir, or do "git clone" to download the dir from scratch. | |
cd AMIA19_W22_large_scale_nlp/scripts/ | |
# run script | |
python cnn_separate_sense.py |
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
######################################## | |
MS | |
######################################## | |
_________________________________________________________________ | |
Layer (type) Output Shape Param # | |
================================================================= | |
embedding_1 (Embedding) (None, 100, 50) 268350 | |
_________________________________________________________________ | |
dropout_1 (Dropout) (None, 100, 50) 0 | |
_________________________________________________________________ |
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
######################################## | |
MS | |
######################################## | |
/Users/m142167/anaconda3/lib/python3.7/site-packages/sklearn/metrics/classification.py:1437: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. | |
'precision', 'predicted', average, warn_for) | |
precision recall f1-score support | |
UNSURED SENSE 0.00 0.00 0.00 1 | |
morphine sulfate 0.97 0.97 0.97 30 | |
multiple sclerosis 0.85 0.94 0.89 18 | |
musculoskeletal 0.00 0.00 0.00 1 |
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 dot_product(x, kernel): | |
""" | |
Wrapper for dot product operation, in order to be compatible with both | |
Theano and Tensorflow | |
Args: | |
x (): input | |
kernel (): weights | |
Returns: | |
""" | |
if K.backend() == 'tensorflow': |
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
# Keras==1.0.6 | |
from keras.models import Sequential | |
import numpy as np | |
from keras.layers.recurrent import LSTM | |
from keras.layers.core import TimeDistributedDense, Activation | |
from keras.preprocessing.sequence import pad_sequences | |
from keras.layers.embeddings import Embedding | |
from sklearn.cross_validation import train_test_split | |
from keras.layers import Merge | |
from keras.backend import tf |
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
class Lambda(Layer): | |
'''Used for evaluating an arbitrary Theano / TensorFlow expression | |
on the output of the previous layer. | |
# Examples | |
```python | |
# add a x -> x^2 layer | |
model.add(Lambda(lambda x: x ** 2)) | |
``` |
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
# Keras==2.0.2 | |
import numpy as np | |
from keras.models import Sequential | |
from keras.layers.recurrent import LSTM | |
from keras.layers.core import Activation, Dense | |
from keras.layers.wrappers import TimeDistributed | |
from keras.preprocessing.sequence import pad_sequences | |
from keras.layers.embeddings import Embedding | |
from sklearn.cross_validation import train_test_split | |
from sklearn.metrics import confusion_matrix, accuracy_score, precision_recall_fscore_support |