Skip to content

Instantly share code, notes, and snippets.

# Keras==1.0.6
import numpy as np
from keras.models import Sequential
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 sklearn.metrics import confusion_matrix, accuracy_score, precision_recall_fscore_support
"""
feature extraction for representing groups of items
the order of items in a group is irrelevant
==================================================
X = list of tokens: [t1,t2,t3,t4,t5]
Y = list of group tags: [S ,C ,C ,S ,C ]
F = list of features representing X:
--------------------------------------------------
X[0] = t1 Y[0] = S F[0] = {token=t1}
X[1] = t2 Y[1] = C F[1] = {token=t2, group_has__t1=1}