From 9b3df1df98ea821258ce524a0081c74d60baac14 Mon Sep 17 00:00:00 2001 From: Pavan Somisetty Date: Sat, 1 Mar 2025 07:03:06 +0530 Subject: [PATCH] Add files via upload --- notebooks/Promptify_NER_Using_Cohere.ipynb | 198 +++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 notebooks/Promptify_NER_Using_Cohere.ipynb diff --git a/notebooks/Promptify_NER_Using_Cohere.ipynb b/notebooks/Promptify_NER_Using_Cohere.ipynb new file mode 100644 index 0000000..f9856dd --- /dev/null +++ b/notebooks/Promptify_NER_Using_Cohere.ipynb @@ -0,0 +1,198 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "id": "cKxp2N0L7Vsl" + }, + "outputs": [], + "source": [ + "import json\n", + "\n", + "from promptify import HubModel, Prompter, Pipeline,CohereModel" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": { + "id": "XAdaUXRg7z9z" + }, + "outputs": [], + "source": [ + "model = CohereModel(model='command',api_key=\"api key\")\n", + "\n", + "prompter = Prompter('ner.jinja') # select a template or provide custom template\n", + "pipe = Pipeline(prompter , model)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "0WpJ3BSp9U2e", + "outputId": "8225f9e9-f745-4b7c-830c-1c0923dfce2f" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The patient is a 93-year-old female with a medical history of chronic right hip pain, osteoporosis,hypertension, depression, and chronic atrial fibrillation admitted for evaluation and management of severe nausea and vomiting and urinary tract infection\n" + ] + } + ], + "source": [ + "sent= \"\"\"The patient is a 93-year-old female with a medical history of chronic right hip pain, osteoporosis,hypertension, depression, and chronic atrial fibrillation admitted for evaluation and management of severe nausea and vomiting and urinary tract infection\"\"\"\n", + "print(sent)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "j2qq1w0t74ZK", + "outputId": "a2278abe-d784-4849-8289-d780ff885bfb" + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " 0%| | 0/1 [00:00 [ {'E' : Entity Name, 'T': Type of Entity } ]\n", + "\n", + "result = pipe.fit(sent,\n", + " domain=\"medical\",labels=None)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "pVHFUewt9Qu6", + "outputId": "e325338b-a9fd-406c-e514-37c1d88f5350" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{'text': '[{\"T\": \"age\", \"E\": \"93-year-old\"}, {\"T\": \"gender\", \"E\": \"female\"}, {\"T\": \"medical history\", \"E\": \"chronic right hip pain, osteoporosis, hypertension, depression, chronic atrial fibrillation\"}, {\"T\": \"admission_reason\", \"E\": \"evaluation and management of severe nausea and vomiting and urinary tract infection\"}]', 'parsed': {'status': 'completed', 'object_type': , 'data': {'completion': [{'T': 'age', 'E': '93-year-old'}, {'T': 'gender', 'E': 'female'}, {'T': 'medical history', 'E': 'chronic right hip pain, osteoporosis, hypertension, depression, chronic atrial fibrillation'}, {'T': 'admission_reason', 'E': 'evaluation and management of severe nausea and vomiting and urinary tract infection'}], 'suggestions': []}}}]\n" + ] + } + ], + "source": [ + "print(result)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "NsrBpXJzI391" + }, + "source": [ + "# **output**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "hvRIi-6fCqS-" + }, + "outputs": [], + "source": [ + "[\n", + " {\n", + " 'text': [\n", + " {\n", + " \"T\": \"age\",\n", + " \"E\": \"93-year-old\"\n", + " },\n", + " {\n", + " \"T\": \"gender\",\n", + " \"E\": \"female\"\n", + " },\n", + " {\n", + " \"T\": \"medical history\",\n", + " \"E\": \"chronic right hip pain, osteoporosis, hypertension, depression, chronic atrial fibrillation\"\n", + " },\n", + " {\n", + " \"T\": \"admission_reason\",\n", + " \"E\": \"evaluation and management of severe nausea and vomiting and urinary tract infection\"\n", + " }\n", + " ],\n", + " 'parsed': {\n", + " 'status': 'completed',\n", + " 'object_type': 'list',\n", + " 'data': {\n", + " 'completion': [\n", + " {\n", + " 'T': 'age',\n", + " 'E': '93-year-old'\n", + " },\n", + " {\n", + " 'T': 'gender',\n", + " 'E': 'female'\n", + " },\n", + " {\n", + " 'T': 'medical history',\n", + " 'E': 'chronic right hip pain, osteoporosis, hypertension, depression, chronic atrial fibrillation'\n", + " },\n", + " {\n", + " 'T': 'admission_reason',\n", + " 'E': 'evaluation and management of severe nausea and vomiting and urinary tract infection'\n", + " }\n", + " ],\n", + " 'suggestions': []\n", + " }\n", + " }\n", + " }\n", + "]\n" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.8" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}