Search code examples
pythoncntk

How do I evaluate a CNTK model trained using sample SequenceClassification code


I used the code given at https://github.com/Microsoft/CNTK/blob/v2.0/Examples/SequenceClassification/SimpleExample/Python/SequenceClassification.py to train a model. How do I evaluate it?


Solution

  • I got it by following way:

    import cntk as C
    from cntk.ops.functions import load_model # Note this
    ...
    ...
    # saved the model after epochs
    for i in range(500):
        mb = reader.next_minibatch(minibatch_size, input_map=input_map)
        trainer.train_minibatch(mb)
        classifier_output.save("model.dnn") # Note this
    ...
    ...
    # loading the model
    model = load_model("model.dnn") # Note this
    
    # converted sentence to numbers and given as sequence
    predScores = model(C.Value.one_hot([[1,238,4,4990,7223,1357,2]], 50466)) # Note this
    predClass = np.argmax(predScores)
    print(predClass)
    

    where [[1,238,4,4990,7223,1357,2]] is the sequence of index of words in vocabs (basically the kind of sequence on which training had happened, and 50466 is the size of vocab.