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

Function entity_score

ToG/wiki_func.py:127–146  ·  view source on GitHub ↗
(question, entity_candidates_id, entity_candidates, score, relation, args)

Source from the content-addressed store, hash-verified

125
126
127def entity_score(question, entity_candidates_id, entity_candidates, score, relation, args):
128 if len(entity_candidates) == 1:
129 return [score], entity_candidates, entity_candidates_id
130 if len(entity_candidates) == 0:
131 return [0.0], entity_candidates, entity_candidates_id
132
133 # make sure the id and entity are in the same order
134 zipped_lists = sorted(zip(entity_candidates, entity_candidates_id))
135 entity_candidates, entity_candidates_id = zip(*zipped_lists)
136 entity_candidates = list(entity_candidates)
137 entity_candidates_id = list(entity_candidates_id)
138
139 prompt = construct_entity_score_prompt(question, relation, entity_candidates)
140
141 result = run_llm(prompt, args.temperature_exploration, args.max_length, args.opeani_api_keys, args.LLM_type)
142 entity_scores = clean_scores(result, entity_candidates)
143 if all_zero(entity_scores):
144 return [1/len(entity_candidates) * score] * len(entity_candidates), entity_candidates, entity_candidates_id
145 else:
146 return [float(x) * score for x in entity_scores], entity_candidates, entity_candidates_id
147
148
149def update_history(entity_candidates, entity, scores, entity_candidates_id, total_candidates, total_scores, total_relations, total_entities_id, total_topic_entities, total_head, value_flag):

Callers 2

main_freebase.pyFile · 0.70
main_wiki.pyFile · 0.70

Calls 4

clean_scoresFunction · 0.85
all_zeroFunction · 0.85
run_llmFunction · 0.70

Tested by

no test coverage detected