def test_hmm_weights():
    simple_weights = viterbi.get_HMM_weights('tests/hmm_simple.dat')
    assert_almost_equals(1.0, np.exp(simple_weights[('D', START_TAG, TRANS)]), places=3)
    assert_almost_equals(1.0, np.exp(simple_weights[('N', 'D', TRANS)]), places=3)
    assert_almost_equals(1.0, np.exp(simple_weights[('V', 'N', TRANS)]), places=3)
    assert_almost_equals(1.0, np.exp(simple_weights[('JJ', 'V', TRANS)]), places=3)
    assert_almost_equals(1.0, np.exp(simple_weights[(END_TAG, 'JJ', TRANS)]), places=3)
def setup_module ():
    global defined_weights
    global alltags
    global hmm_weights
    start_tag = constants.START_TAG
    trans = constants.TRANS
    end_tag = constants.END_TAG
    emit = constants.EMIT
    hmm_weights = viterbi.get_HMM_weights(TRAIN_FILE)
    defined_weights = {('N','they',emit):-1,('N','can',emit):-3,('N','fish',emit):-3,\
        ('V','they',emit):-10,('V','can',emit):-2,('V','fish',emit):-3,\
            ('N','N',trans):-5,('V','N',trans):-2,(end_tag,'N',trans):-3,\
                ('N','V',trans):-1,('V','V',trans):-4,(end_tag,'V',trans):-3,\
                    ('N',start_tag,trans):-1,('V',start_tag,trans):-1}
    alltags = preproc.getAllTags(TRAIN_FILE)
Exemple #3
0
def setup_module():
    global defined_weights
    global alltags
    global hmm_weights
    start_tag = constants.START_TAG
    trans = constants.TRANS
    end_tag = constants.END_TAG
    emit = constants.EMIT
    hmm_weights = viterbi.get_HMM_weights(TRAIN_FILE)
    defined_weights = {('N','they',emit):-1,('N','can',emit):-3,('N','fish',emit):-3,\
        ('V','they',emit):-10,('V','can',emit):-2,('V','fish',emit):-3,\
            ('N','N',trans):-5,('V','N',trans):-2,(end_tag,'N',trans):-3,\
                ('N','V',trans):-1,('V','V',trans):-4,(end_tag,'V',trans):-3,\
                    ('N',start_tag,trans):-1,('V',start_tag,trans):-1}
    alltags = preproc.getAllTags(TRAIN_FILE)
Exemple #4
0
def test_hmm_weights():
    simple_weights = viterbi.get_HMM_weights('tests/hmm_simple.dat')
    assert_almost_equals(1.0,
                         np.exp(simple_weights[('D', START_TAG, TRANS)]),
                         places=3)
    assert_almost_equals(1.0,
                         np.exp(simple_weights[('N', 'D', TRANS)]),
                         places=3)
    assert_almost_equals(1.0,
                         np.exp(simple_weights[('V', 'N', TRANS)]),
                         places=3)
    assert_almost_equals(1.0,
                         np.exp(simple_weights[('JJ', 'V', TRANS)]),
                         places=3)
    assert_almost_equals(1.0,
                         np.exp(simple_weights[(END_TAG, 'JJ', TRANS)]),
                         places=3)