def test_encode_texts():
""" Text encoding is stable.
"""
TEST_SENTENCES = [u'I love mom\'s cooking',
u'I love how you never reply back..',
u'I love cruising with my homies',
u'I love messing with yo mind!!',
u'I love you and now you\'re just gone..',
u'This is shit',
u'This is the shit']
maxlen = 30
batch_size = 32
with open(VOCAB_PATH, 'r') as f:
vocabulary = json.load(f)
st = SentenceTokenizer(vocabulary, maxlen)
tokenized, _, _ = st.tokenize_sentences(TEST_SENTENCES)
model = deepmoji_feature_encoding(maxlen, PRETRAINED_PATH)
encoding = model.predict(tokenized)
avg_across_sentences = np.around(np.mean(encoding, axis=0)[:5], 3)
assert np.allclose(avg_across_sentences, np.array([-0.023, 0.021, -0.037, -0.001, -0.005]))
评论列表
文章目录