def eqe1(E, query, vocabulary, priors):
"""
Arguments:
E - word embedding
Q - list of query terms
vocabulary -- list of relevant words
priors - precomputed priors with same indices as vocabulary
>>> E = dict()
>>> E['a'] = np.asarray([0.5,0.5])
>>> E['b'] = np.asarray([0.2,0.8])
>>> E['c'] = np.asarray([0.9,0.1])
>>> E['d'] = np.asarray([0.8,0.2])
>>> q = "a b".split()
>>> vocabulary = "a b c".split()
>>> priors = np.asarray([0.25,0.5,0.25])
>>> posterior = eqe1(E, q, vocabulary, priors)
>>> vocabulary[np.argmax(posterior)]
'c'
"""
posterior = [priors[i] *
np.product([delta(E[qi], E[w]) / priors[i] for qi in query])
for i, w in enumerate(vocabulary)]
return np.asarray(posterior)
评论列表
文章目录