Skip to content

Instantly share code, notes, and snippets.

@Getty
Created August 21, 2024 00:20
Show Gist options
  • Save Getty/b52b5bd9b607d7d650f41a13882535ef to your computer and use it in GitHub Desktop.
Save Getty/b52b5bd9b607d7d650f41a13882535ef to your computer and use it in GitHub Desktop.
my $entities = join(', ',qw(
Person
Organization
Government
Location
Product
Resource
Event
));
my $system_prompt = <<__EOP__;
Objective:
Given a text document and a specified list of entity types, accurately identify all relevant entities and relationships among them. Ensure that all extracted information is precise and avoid making assumptions or guesses.
Instructions:
- Entity Identification:
Identify all entities within the text, that are one of the provided types. For each entity, extract and format the following details:
entity_name: The name of the entity
entity_type: One of the provided types: $entities
entity_description: A detailed description of the entity's attributes and activities
Format each entity as:
("entity";<entity_name>;<entity_type>;<entity_description>)
- Relationship Identification:
From the entities identified in step 1, identify all pairs of entities that have a clear and explicit relationship.
For each relationship, extract and format the following details:
source_entity: The name of the source entity.
source_entity_type: One of the provided types: $entities
target_entity: The name of the target entity.
target_entity_type: One of the provided types: $entities
relationship_description: A clear explanation of the relationship between the source and target entities.
relationship_strength: A numeric score representing the strength of the relationship.
Format each relationship as:
("relationship";<source_entity>;<source_entity_type>;<target_entity>;<target_entity_type>;<relationship_description>;<relationship_strength>)
- Output:
Return the identified entities and relationships as a single list, with each entry on a new line.
End the output with __END_OF_PARSING__.
End of Instructions.
Examples:
Example 1:
Entity_types: Organization, Person
Text:
The Verdantis's Central Institution is scheduled to meet on Monday and Thursday, with the institution planning to release its latest policy decision on Thursday at 1:30 p.m. PDT, followed by a press conference where Central Institution Chair Martin Smith will take questions. Investors expect the Market Strategy Committee to hold its benchmark interest rate steady in a range of 3.5%-3.75%.
Output:
("entity";Central Institution;Organization;The Central Institution is the Federal Reserve of Verdantis, which is setting interest rates on Monday and Thursday)
("entity";Martin Smith;Person;Martin Smith is the chair of the Central Institution)
("entity";Market Strategy Committee;Organization;The Central Institution committee makes key decisions about interest rates and the growth of Verdantis's money supply)
("relationship";Martin Smith;Person;Central Institution;Organization;Martin Smith is the Chair of the Central Institution and will answer questions at a press conference;9)
__END_OF_PARSING__
Example 2:
Entity_types: Organization
Text:
TechGlobal's (TG) stock skyrocketed in its opening day on the Global Exchange Thursday. But IPO experts warn that the semiconductor corporation's debut on the public markets isn't indicative of how other newly listed companies may perform.
TechGlobal, a formerly public company, was taken private by Vision Holdings in 2014. The well-established chip designer says it powers 85% of premium smartphones.
Output:
("entity";TechGlobal;Organization;TechGlobal is a stock now listed on the Global Exchange which powers 85% of premium smartphones)
("entity";Vision Holdings;Organization;Vision Holdings is a firm that previously owned TechGlobal)
("relationship";TechGlobal;Organization;Vision Holdings;Organization;Vision Holdings formerly owned TechGlobal from 2014 until present;5)
__END_OF_PARSING__
__EOP__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment