You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Limit to top 20 triples to avoid overwhelming the prompt
457
-
relevant_triples=relevant_triples
458
447
459
-
# Format the relevant triples for display
460
-
triples_context=""
461
-
ifrelevant_triples:
462
-
triples_context="Here are some known facts about the source entity that might be relevant:\n"
463
-
fors, p, oinrelevant_triples:
464
-
triples_context+=f"- {s}{p}{o}\n"
465
-
triples_context+="\n"
448
+
assertlen(relevant_triples) >0
449
+
# @TODO:CD:Potential improvement by trade offing the test runtime:
450
+
# @TODO: Finding an some triples from relevant_triples while the prediction is being invariant to it
451
+
# @TODO: Prediction does not change but the input size decreases
452
+
# @TODO: The removed triples can be seen as noise
453
+
triples_context="Here are some known facts about the source entity that might be relevant:\n"
454
+
fors, p, oinsorted(relevant_triples):
455
+
triples_context+=f"- {s}{p}{o}\n"
456
+
triples_context+="\n"
466
457
467
458
# Important: Grouping relations is important to reach MRR 1.0
468
459
similar_relations= []
469
460
fors, p, oinrelevant_triples:
470
461
ifp==relationands!=source:
471
462
similar_relations.append((s, p, o))
472
-
similar_relations_context=""
473
-
ifsimilar_relations:
474
-
similar_relations_context="Here are examples of similar relations in the knowledge base:\n"
475
-
fors, p, oinsimilar_relations:
476
-
similar_relations_context+=f"- {s}{p}{o}\n"
477
-
similar_relations_context+="\n"
463
+
464
+
similar_relations_context="Here are examples of similar relations in the knowledge base:\n"
465
+
fors, p, oinsimilar_relations:
466
+
similar_relations_context+=f"- {s}{p}{o}\n"
467
+
similar_relations_context+="\n"
468
+
478
469
479
470
base_prompt=f"""
480
471
I'm trying to predict the most likely target entities for the following query:
481
472
Source entity: {source}
482
473
Relation: {relation}
483
474
Query: ({source}, {relation}, ?)
484
475
476
+
Subgraph Graph:
485
477
{triples_context}
486
478
{similar_relations_context}
487
479
488
-
Please provide a ranked list of the 10 most likely target entities from the following list, along with likelihoods for each: {self.target_entities}
480
+
Please provide a ranked list of at most{min(len(self.target_entities),15)} likely target entities from the following list, along with likelihoods for each: {self.target_entities}
489
481
490
482
Provide your answer in the following JSON format: {{"predictions": [{{"entity": "entity_name", "score": float_number}}]}}
491
483
492
484
Notes:
485
+
1. Use the provided knowledge about the source entity and similar relations to inform your predictions.
493
486
1. Only include entities that are plausible targets for this relation.
494
487
2. For geographic entities, consider geographic location, regional classifications, and political associations.
495
488
3. Rank the entities by likelihood of being the correct target.
496
-
4. Only include entities from the provided list in your predictions.
489
+
4. ONLY INCLUDE entities from the provided list in your predictions.
497
490
5. If certain entities are not suitable for this relation, don't include them.
498
491
6. Return a valid JSON output.
499
492
7. Make sure scores are floating point numbers between 0 and 1, not strings.
500
-
8. Use the provided knowledge about the source entity and similar relations to inform your predictions.
0 commit comments