I have been working on my project Deep Learning Language Detection which is a network with these layers to recognise from 16 programming languages:
And this is the code to produce the network:
# Setting up the model
graph_in = Input(shape=(sequence_length, number_of_quantised_characters))
convs = []
for i in range(0, len(filter_sizes)):
conv = Conv1D(filters=num_filters,
kernel_size=filter_sizes[i],
padding='valid',
activation='relu',
strides=1)(graph_in)
pool = MaxPooling1D(pool_size=pooling_sizes[i])(conv)
flatten = Flatten()(pool)
convs.append(flatten)
if len(filter_sizes)>1:
out = Concatenate()(convs)
else:
out = convs[0]
graph = Model(inputs=graph_in, outputs=out)
# main sequential model
model = Sequential()
model.add(Dropout(dropout_prob[0], input_shape=(sequence_length, number_of_quantised_characters)))
model.add(graph)
model.add(Dense(hidden_dims))
model.add(Dropout(dropout_prob[1]))
model.add(Dense(number_of_classes))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])
So my last language class is SQL and in the test phase, it can never predict SQL correctly and it scores 0% on them. I thought this was due to poor quality of SQL samples (and indeed they were poor) so I removed this class and started training on 15 classes. To my surprise, now F# files had 0% detection and F# was the last class after removing SQL (i.e. the one-hot-vector where the last position is 1 and the rest is 0). Now if a network that was trained on 16 used against 15, it would achieve a very high success rate of 98.5%.
The code that I am using is pretty simple and available mainly in defs.py and data_helper.py
Here is the result of network trained with 16 classes tested against 16 classes:
Final result: 14827/16016 (0.925761738262)
xml: 995/1001 (0.994005994006)
fsharp: 974/1001 (0.973026973027)
clojure: 993/1001 (0.992007992008)
java: 996/1001 (0.995004995005)
scala: 990/1001 (0.989010989011)
python: 983/1001 (0.982017982018)
sql: 0/1001 (0.0)
js: 991/1001 (0.99000999001)
cpp: 988/1001 (0.987012987013)
css: 987/1001 (0.986013986014)
csharp: 994/1001 (0.993006993007)
go: 989/1001 (0.988011988012)
php: 998/1001 (0.997002997003)
ruby: 995/1001 (0.994005994006)
powershell: 992/1001 (0.991008991009)
bash: 962/1001 (0.961038961039)
And this is the result of the same network (trained against 16) ran against 15 classes:
Final result: 14827/15015 (0.987479187479)
xml: 995/1001 (0.994005994006)
fsharp: 974/1001 (0.973026973027)
clojure: 993/1001 (0.992007992008)
java: 996/1001 (0.995004995005)
scala: 990/1001 (0.989010989011)
python: 983/1001 (0.982017982018)
js: 991/1001 (0.99000999001)
cpp: 988/1001 (0.987012987013)
css: 987/1001 (0.986013986014)
csharp: 994/1001 (0.993006993007)
go: 989/1001 (0.988011988012)
php: 998/1001 (0.997002997003)
ruby: 995/1001 (0.994005994006)
powershell: 992/1001 (0.991008991009)
bash: 962/1001 (0.961038961039)
Has anyone else seen this? How can I get around it?