In [1]:
from process_data import DataHandler


Using TensorFlow backend.

In [19]:
s = DataHandler("../data/CoNLL-2003/eng.testa")

In [3]:
s.get_data()[0].shape


Out[3]:
(3466, 109, 60)

In [4]:
from NER_model import NER

In [5]:
m = NER(s)

In [6]:
m.make_and_compile()


____________________________________________________________________________________________________
Layer (type)                     Output Shape          Param #     Connected to                     
====================================================================================================
bidirectional_1 (Bidirectional)  (None, 109, 300)      253200      bidirectional_input_1[0][0]      
____________________________________________________________________________________________________
timedistributed_1 (TimeDistribut (None, 109, 5)        1505        bidirectional_1[0][0]            
____________________________________________________________________________________________________
dropout_1 (Dropout)              (None, 109, 5)        0           timedistributed_1[0][0]          
====================================================================================================
Total params: 254,705
Trainable params: 254,705
Non-trainable params: 0
____________________________________________________________________________________________________
None

In [ ]:
# m.train()
m.train(epochs=10)

In [12]:
m.evaluate()


             precision    recall  f1-score   support

        LOC       0.91      0.71      0.80       471
       MISC       0.77      0.47      0.59       276
          O       0.00      0.00      0.00         0
        ORG       0.80      0.49      0.61       362
        PER       0.92      0.81      0.86       635

avg / total       0.87      0.66      0.75      1744

Out[12]:
LOC MISC O ORG PER
LOC 334 23 81 26 7
MISC 15 130 117 9 5
O 0 0 0 0 0
ORG 17 13 124 177 31
PER 0 2 113 8 512

In [17]:
# m.predict_tags("The strongest man on Earth is Mark Henry")
m.predict_tags("The strongest rain ever recorded in India shut down the financial hub of Mumbai, snapped communication lines, closed airports and forced thousands of people to sleep in their offices or walk home during the night, officials said today.")


(1, 109, 60)
The/O
strongest/O
rain/O
ever/O
recorded/O
in/O
India/LOC
shut/O
down/O
the/O
financial/O
hub/O
of/O
Mumbai,/LOC
snapped/O
communication/O
lines,/O
closed/O
airports/O
and/O
forced/O
thousands/O
of/O
people/O
to/O
sleep/O
in/O
their/O
offices/O
or/O
walk/O
home/O
during/O
the/O
night,/O
officials/O
said/O
today./O

In [ ]:
m.model.save("./first_model")

In [8]:
from keras.models import load_model
m.model = load_model("./first_model")