MCPcopy Create free account
hub / github.com/DataArcTech/ToG / entity_score

Function entity_score

ToG/freebase_func.py:166–194  ·  view source on GitHub ↗
(question, entity_candidates_id, score, relation, args)

Source from the content-addressed store, hash-verified

164
165
166def entity_score(question, entity_candidates_id, score, relation, args):
167 entity_candidates = [id2entity_name_or_type(entity_id) for entity_id in entity_candidates_id]
168 if all_unknown_entity(entity_candidates):
169 return [1/len(entity_candidates) * score] * len(entity_candidates), entity_candidates, entity_candidates_id
170 entity_candidates = del_unknown_entity(entity_candidates)
171 if len(entity_candidates) == 1:
172 return [score], entity_candidates, entity_candidates_id
173 if len(entity_candidates) == 0:
174 return [0.0], entity_candidates, entity_candidates_id
175
176 # make sure the id and entity are in the same order
177 zipped_lists = sorted(zip(entity_candidates, entity_candidates_id))
178 entity_candidates, entity_candidates_id = zip(*zipped_lists)
179 entity_candidates = list(entity_candidates)
180 entity_candidates_id = list(entity_candidates_id)
181 if args.prune_tools == "llm":
182 prompt = construct_entity_score_prompt(question, relation, entity_candidates)
183
184 result = run_llm(prompt, args.temperature_exploration, args.max_length, args.opeani_api_keys, args.LLM_type)
185 return [float(x) * score for x in clean_scores(result, entity_candidates)], entity_candidates, entity_candidates_id
186
187 elif args.prune_tools == "bm25":
188 topn_entities, topn_scores = compute_bm25_similarity(question, entity_candidates, args.width)
189 else:
190 model = SentenceTransformer('sentence-transformers/msmarco-distilbert-base-tas-b')
191 topn_entities, topn_scores = retrieve_top_docs(question, entity_candidates, model, args.width)
192 if if_all_zero(topn_scores):
193 topn_scores = [float(1/len(topn_scores))] * len(topn_scores)
194 return [float(x) * score for x in topn_scores], topn_entities, entity_candidates_id
195
196
197def update_history(entity_candidates, entity, scores, entity_candidates_id, total_candidates, total_scores, total_relations, total_entities_id, total_topic_entities, total_head):

Callers

nothing calls this directly

Calls 9

id2entity_name_or_typeFunction · 0.85
all_unknown_entityFunction · 0.85
del_unknown_entityFunction · 0.85
clean_scoresFunction · 0.85
compute_bm25_similarityFunction · 0.85
retrieve_top_docsFunction · 0.85
run_llmFunction · 0.70
if_all_zeroFunction · 0.70

Tested by

no test coverage detected