|
|
|
|
|
desc = """ |
|
# NER |
|
|
|
Notebook implementation of named entity recognition. |
|
Adapted from [promptify](https://github.com/promptslab/Promptify/blob/main/promptify/prompts/nlp/templates/ner.jinja). |
|
""" |
|
|
|
|
|
import json |
|
|
|
import minichain |
|
|
|
|
|
|
|
class NERPrompt(minichain.TemplatePrompt): |
|
template_file = "ner.pmpt.tpl" |
|
|
|
def parse(self, response, inp): |
|
return json.loads(response) |
|
|
|
|
|
|
|
class TeamPrompt(minichain.Prompt): |
|
def prompt(self, inp): |
|
return "Can you describe these basketball teams? " + \ |
|
" ".join([i["E"] for i in inp if i["T"] =="Team"]) |
|
|
|
def parse(self, response, inp): |
|
return response |
|
|
|
|
|
|
|
with minichain.start_chain("ner") as backend: |
|
ner_prompt = NERPrompt(backend.OpenAI()) |
|
team_prompt = TeamPrompt(backend.OpenAI()) |
|
prompt = ner_prompt.chain(team_prompt) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gradio = prompt.to_gradio(fields =["text_input", "labels", "domain"], |
|
examples=[["An NBA playoff pairing a year ago, the 76ers (39-20) meet the Miami Heat (32-29) for the first time this season on Monday night at home.", "Team, Date", "Sports"]], |
|
description=desc) |
|
|
|
|
|
if __name__ == "__main__": |
|
gradio.launch() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|