def test_predict_proba(dataset): color_seqs, word_seqs, vocab = dataset mod = ContextualColorDescriber(vocab, max_iter=1) mod.fit(color_seqs, word_seqs) probs = mod.predict_proba(color_seqs, word_seqs) assert all(np.round(t.sum(), 6) == 1.0 for seq in probs for t in seq)
# You can get the perplexities for test examles with `perpelexities`: # In[36]: toy_perp = toy_mod.perplexities(toy_color_seqs_test, toy_word_seqs_test) # In[37]: toy_perp[0] # You can use `predict_proba` to see the full probability distributions assigned to test examples: # In[38]: toy_proba = toy_mod.predict_proba(toy_color_seqs_test, toy_word_seqs_test) # In[39]: toy_proba[0].shape # In[40]: for timestep in toy_proba[0]: print(dict(zip(toy_vocab, timestep))) # ### Cross-validation # You can use `utils.fit_classifier_with_crossvalidation` to cross-validate these models. Just be sure to set `scoring=None` so that the sklearn model selection methods use the `score` method of `ContextualColorDescriber`, which is an alias for `listener_accuracy`: # In[41]: