MCPcopy Create free account
hub / github.com/OpenBMB/BMTools / dense

Function dense

bmtools/tools/meta_analysis/api.py:33–53  ·  view source on GitHub ↗
(topic, docs)

Source from the content-addressed store, hash-verified

31 stan_emb.append(np.array(get_embedding(item)))
32
33def dense(topic, docs):
34 try:
35 top_emb = np.array(get_embedding(topic))
36 except Exception as e:
37 return [-1]
38 nm = norm(top_emb)
39 doc_sim = []
40 for ky in docs.keys():
41 try:
42 if docs[ky] is None:
43 tmp = [0]*len(top_emb)
44 elif len(docs[ky].split(' '))>100:
45 tmp = get_embedding(docs[ky][0])
46 else:
47 tmp = [0]*len(top_emb)
48 except Exception as e:
49 tmp = [0]*len(top_emb)
50 sim = dot(top_emb, np.array(tmp))/(nm*norm(np.array(tmp))+1e-5)
51 doc_sim.append(sim)
52 doc_sim = np.array(doc_sim)
53 return doc_sim
54
55def semantic_query(term, retmax=100):
56 if retmax>100:

Callers 1

initialFunction · 0.85

Calls 1

get_embeddingFunction · 0.85

Tested by

no test coverage detected