- Choose the "Experiment with foundation models and build prompts" task
- Enter into the Prompt Lab
The Prompt Lab facilitates expedient exploration and development of solutions using substantial language models by enabling users to experiment with prompts. These prompts are straightforward text inputs that effectively instruct the model to execute specific commands. Additionally, prompts may incorporate a limited number of examples to steer the model towards the precise behavior sought by the user. This is exactly what we will do to extract named entities.
Select the Freeform option. This will let you enter the prompt in a free way. An alert will pop-up, just accept it. The idea is to freely write the best prompting for a Named Entity Recognition NLP task.
The idea is to give to the model a few examples so that it can improve its extraction. We call this few-shot learning because we constraint the model to follow our directive based on some examples.
Enter the following prompt:
Extract all the named entities from the text surrounded by quotes. Use the following predefined entity labels: PERSON, ORGANIZATION, LOCATION, DATE, GPE, TIME.
Text: "Thousands of demonstrators have marched through London to protest the war in Iraq and demand the withdrawal of British troops from that country."
Entities: London=LOCATION | Iraq=LOCATION | British=GPE
Text: "Families of soldiers killed in the conflict joined the protesters who carried banners with such slogans as 'Bush Number One Terrorist' and 'Stop the Bombings.'"
Text: "They marched from the Houses of Parliament to a rally in Hyde Park."
Entities: Hyde Park=LOCATION
Text: "Police put the number of marchers at 10,000 while organizers claimed it was 100,000."
Text: "The protest comes on the eve of the annual conference of Britain's ruling Labor Party in the southern English seaside resort of Brighton."
Do not add any spaces or new lines after the "Entities:"
These examples are taken from the GMB dataset. You can find it here: https://gmb.let.rug.nl/manual.php
The prompt is separated in 3 parts: one containing the request, one containing the examples based on two lines with always the same form = Text and Entities, and the text to extract followed by an empty "Entities: " line.
Not all models are equivalent to this task. Mainly instruct-based models can do that. I recommand you to select the "flan-t5-xxl-11b" model.
If you have followed my example, you will have an output equivalent to this: Brighton=LOCATION, Labor Party=ORGANISATION, Britain=GPE, Labor Party=ORGANISATION, Brighton=LOCATION.
You can now save you work using the "Save work" drop-down list. You can either create a notebook by using the save to "Notebook" option. This will convert the current experimentation into Python and allow you to rewrite the code and test the changes in your environnement using the API provided by Watsonx.