Spaces:
Sleeping
Sleeping
Kabeer Akande
commited on
Commit
•
604701b
1
Parent(s):
bd1ec5c
adds demo script
Browse files
notebooks/Named_Entity_Recognition_Demo.ipynb
CHANGED
@@ -2,223 +2,255 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
-
"id": "
|
7 |
"metadata": {},
|
8 |
"outputs": [],
|
9 |
"source": [
|
10 |
-
"#
|
|
|
11 |
]
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "code",
|
15 |
-
"execution_count":
|
16 |
-
"id": "
|
17 |
"metadata": {},
|
18 |
"outputs": [
|
19 |
{
|
20 |
-
"
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
"
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
"\u001b[2K \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m126.8/126.8 kB\u001b[0m \u001b[31m4.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
33 |
-
"\u001b[?25hRequirement already satisfied: filelock in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from datasets) (3.13.1)\n",
|
34 |
-
"Requirement already satisfied: numpy>=1.17 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from datasets) (1.26.2)\n",
|
35 |
-
"Collecting pyarrow>=8.0.0 (from datasets)\n",
|
36 |
-
" Obtaining dependency information for pyarrow>=8.0.0 from https://files.pythonhosted.org/packages/6c/6c/882a57798877e3a49ba54d8e0540bea24aed78fb42e1d860f08c3449c75e/pyarrow-14.0.2-cp311-cp311-macosx_11_0_arm64.whl.metadata\n",
|
37 |
-
" Downloading pyarrow-14.0.2-cp311-cp311-macosx_11_0_arm64.whl.metadata (3.0 kB)\n",
|
38 |
-
"Collecting pyarrow-hotfix (from datasets)\n",
|
39 |
-
" Obtaining dependency information for pyarrow-hotfix from https://files.pythonhosted.org/packages/e4/f4/9ec2222f5f5f8ea04f66f184caafd991a39c8782e31f5b0266f101cb68ca/pyarrow_hotfix-0.6-py3-none-any.whl.metadata\n",
|
40 |
-
" Downloading pyarrow_hotfix-0.6-py3-none-any.whl.metadata (3.6 kB)\n",
|
41 |
-
"Collecting dill<0.3.8,>=0.3.0 (from datasets)\n",
|
42 |
-
" Obtaining dependency information for dill<0.3.8,>=0.3.0 from https://files.pythonhosted.org/packages/f5/3a/74a29b11cf2cdfcd6ba89c0cecd70b37cd1ba7b77978ce611eb7a146a832/dill-0.3.7-py3-none-any.whl.metadata\n",
|
43 |
-
" Downloading dill-0.3.7-py3-none-any.whl.metadata (9.9 kB)\n",
|
44 |
-
"Requirement already satisfied: pandas in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from datasets) (2.1.4)\n",
|
45 |
-
"Requirement already satisfied: requests>=2.19.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from datasets) (2.31.0)\n",
|
46 |
-
"Requirement already satisfied: tqdm>=4.62.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from datasets) (4.66.1)\n",
|
47 |
-
"Collecting xxhash (from datasets)\n",
|
48 |
-
" Obtaining dependency information for xxhash from https://files.pythonhosted.org/packages/9c/0a/d0fd8d78c8a2c3c3b34e7a9dccf85f01bf38f32e0228d107fa3903e0981f/xxhash-3.4.1-cp311-cp311-macosx_11_0_arm64.whl.metadata\n",
|
49 |
-
" Downloading xxhash-3.4.1-cp311-cp311-macosx_11_0_arm64.whl.metadata (12 kB)\n",
|
50 |
-
"Collecting multiprocess (from datasets)\n",
|
51 |
-
" Obtaining dependency information for multiprocess from https://files.pythonhosted.org/packages/e7/41/96ac938770ba6e7d5ae1d8c9cafebac54b413549042c6260f0d0a6ec6622/multiprocess-0.70.15-py311-none-any.whl.metadata\n",
|
52 |
-
" Downloading multiprocess-0.70.15-py311-none-any.whl.metadata (7.2 kB)\n",
|
53 |
-
"Collecting fsspec[http]<=2023.10.0,>=2023.1.0 (from datasets)\n",
|
54 |
-
" Obtaining dependency information for fsspec[http]<=2023.10.0,>=2023.1.0 from https://files.pythonhosted.org/packages/e8/f6/3eccfb530aac90ad1301c582da228e4763f19e719ac8200752a4841b0b2d/fsspec-2023.10.0-py3-none-any.whl.metadata\n",
|
55 |
-
" Downloading fsspec-2023.10.0-py3-none-any.whl.metadata (6.8 kB)\n",
|
56 |
-
"Collecting aiohttp (from datasets)\n",
|
57 |
-
" Obtaining dependency information for aiohttp from https://files.pythonhosted.org/packages/54/5d/4ea65eaf9a81821e2a02ba1f77644920dd0a575a2fd05557adb433db3ef6/aiohttp-3.9.1-cp311-cp311-macosx_11_0_arm64.whl.metadata\n",
|
58 |
-
" Downloading aiohttp-3.9.1-cp311-cp311-macosx_11_0_arm64.whl.metadata (7.4 kB)\n",
|
59 |
-
"Requirement already satisfied: huggingface-hub>=0.19.4 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from datasets) (0.20.1)\n",
|
60 |
-
"Requirement already satisfied: packaging in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from datasets) (23.2)\n",
|
61 |
-
"Requirement already satisfied: pyyaml>=5.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from datasets) (6.0.1)\n",
|
62 |
-
"Collecting responses<0.19 (from evaluate)\n",
|
63 |
-
" Downloading responses-0.18.0-py3-none-any.whl (38 kB)\n",
|
64 |
-
"Collecting regex!=2019.12.17 (from transformers)\n",
|
65 |
-
" Obtaining dependency information for regex!=2019.12.17 from https://files.pythonhosted.org/packages/60/9e/4b0223e05776aa3be806a902093b2ab1de3ba26b652d92065d5c7e1d4df3/regex-2023.12.25-cp311-cp311-macosx_11_0_arm64.whl.metadata\n",
|
66 |
-
" Downloading regex-2023.12.25-cp311-cp311-macosx_11_0_arm64.whl.metadata (40 kB)\n",
|
67 |
-
"\u001b[2K \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m40.9/40.9 kB\u001b[0m \u001b[31m4.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
68 |
-
"\u001b[?25hCollecting tokenizers<0.19,>=0.14 (from transformers)\n",
|
69 |
-
" Obtaining dependency information for tokenizers<0.19,>=0.14 from https://files.pythonhosted.org/packages/c5/0e/8961075de3aca5435fa6371088d44594cdc0e59b5b935afdaf1af028cf36/tokenizers-0.15.0-cp311-cp311-macosx_11_0_arm64.whl.metadata\n",
|
70 |
-
" Downloading tokenizers-0.15.0-cp311-cp311-macosx_11_0_arm64.whl.metadata (6.7 kB)\n",
|
71 |
-
"Collecting safetensors>=0.3.1 (from transformers)\n",
|
72 |
-
" Obtaining dependency information for safetensors>=0.3.1 from https://files.pythonhosted.org/packages/0c/84/1e59b0594ca421ff308169b0802d72adcce359619925141b69d2ebc89269/safetensors-0.4.1-cp311-cp311-macosx_11_0_arm64.whl.metadata\n",
|
73 |
-
" Downloading safetensors-0.4.1-cp311-cp311-macosx_11_0_arm64.whl.metadata (3.8 kB)\n",
|
74 |
-
"Requirement already satisfied: attrs>=17.3.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from aiohttp->datasets) (23.2.0)\n",
|
75 |
-
"Collecting multidict<7.0,>=4.5 (from aiohttp->datasets)\n",
|
76 |
-
" Downloading multidict-6.0.4-cp311-cp311-macosx_11_0_arm64.whl (29 kB)\n",
|
77 |
-
"Collecting yarl<2.0,>=1.0 (from aiohttp->datasets)\n",
|
78 |
-
" Obtaining dependency information for yarl<2.0,>=1.0 from https://files.pythonhosted.org/packages/20/3d/7dabf580dfc0b588e48830486b488858122b10a61f33325e0d7cf1d6180b/yarl-1.9.4-cp311-cp311-macosx_11_0_arm64.whl.metadata\n",
|
79 |
-
" Downloading yarl-1.9.4-cp311-cp311-macosx_11_0_arm64.whl.metadata (31 kB)\n",
|
80 |
-
"Collecting frozenlist>=1.1.1 (from aiohttp->datasets)\n",
|
81 |
-
" Obtaining dependency information for frozenlist>=1.1.1 from https://files.pythonhosted.org/packages/5b/9c/f12b69997d3891ddc0d7895999a00b0c6a67f66f79498c0e30f27876435d/frozenlist-1.4.1-cp311-cp311-macosx_11_0_arm64.whl.metadata\n",
|
82 |
-
" Downloading frozenlist-1.4.1-cp311-cp311-macosx_11_0_arm64.whl.metadata (12 kB)\n",
|
83 |
-
"Collecting aiosignal>=1.1.2 (from aiohttp->datasets)\n",
|
84 |
-
" Downloading aiosignal-1.3.1-py3-none-any.whl (7.6 kB)\n",
|
85 |
-
"Requirement already satisfied: typing-extensions>=3.7.4.3 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from huggingface-hub>=0.19.4->datasets) (4.9.0)\n",
|
86 |
-
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from requests>=2.19.0->datasets) (3.3.2)\n",
|
87 |
-
"Requirement already satisfied: idna<4,>=2.5 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from requests>=2.19.0->datasets) (3.6)\n",
|
88 |
-
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from requests>=2.19.0->datasets) (1.26.18)\n",
|
89 |
-
"Requirement already satisfied: certifi>=2017.4.17 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from requests>=2.19.0->datasets) (2023.11.17)\n"
|
90 |
-
]
|
91 |
},
|
92 |
{
|
93 |
-
"
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
"
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
"
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
"
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
"
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
"
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
"Successfully installed aiohttp-3.9.1 aiosignal-1.3.1 datasets-2.16.1 dill-0.3.7 evaluate-0.4.1 frozenlist-1.4.1 fsspec-2023.10.0 multidict-6.0.4 multiprocess-0.70.15 pyarrow-14.0.2 pyarrow-hotfix-0.6 regex-2023.12.25 responses-0.18.0 safetensors-0.4.1 tokenizers-0.15.0 transformers-4.36.2 xxhash-3.4.1 yarl-1.9.4\n",
|
134 |
-
"\n",
|
135 |
-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.2.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.3.2\u001b[0m\n",
|
136 |
-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
|
137 |
-
"Requirement already satisfied: gradio in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (4.12.0)\n",
|
138 |
-
"Requirement already satisfied: aiofiles<24.0,>=22.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (23.2.1)\n",
|
139 |
-
"Requirement already satisfied: altair<6.0,>=4.2.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (5.2.0)\n",
|
140 |
-
"Requirement already satisfied: fastapi in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (0.108.0)\n",
|
141 |
-
"Requirement already satisfied: ffmpy in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (0.3.1)\n",
|
142 |
-
"Requirement already satisfied: gradio-client==0.8.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (0.8.0)\n",
|
143 |
-
"Requirement already satisfied: httpx in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (0.26.0)\n",
|
144 |
-
"Requirement already satisfied: huggingface-hub>=0.19.3 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (0.20.1)\n",
|
145 |
-
"Requirement already satisfied: importlib-resources<7.0,>=1.3 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (6.1.1)\n",
|
146 |
-
"Requirement already satisfied: jinja2<4.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (3.1.2)\n",
|
147 |
-
"Requirement already satisfied: markupsafe~=2.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (2.1.3)\n",
|
148 |
-
"Requirement already satisfied: matplotlib~=3.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (3.8.2)\n",
|
149 |
-
"Requirement already satisfied: numpy~=1.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (1.26.2)\n",
|
150 |
-
"Requirement already satisfied: orjson~=3.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (3.9.10)\n",
|
151 |
-
"Requirement already satisfied: packaging in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (23.2)\n",
|
152 |
-
"Requirement already satisfied: pandas<3.0,>=1.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (2.1.4)\n",
|
153 |
-
"Requirement already satisfied: pillow<11.0,>=8.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (10.1.0)\n",
|
154 |
-
"Requirement already satisfied: pydantic>=2.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (2.5.3)\n",
|
155 |
-
"Requirement already satisfied: pydub in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (0.25.1)\n",
|
156 |
-
"Requirement already satisfied: python-multipart in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (0.0.6)\n",
|
157 |
-
"Requirement already satisfied: pyyaml<7.0,>=5.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (6.0.1)\n",
|
158 |
-
"Requirement already satisfied: semantic-version~=2.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (2.10.0)\n",
|
159 |
-
"Requirement already satisfied: tomlkit==0.12.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (0.12.0)\n",
|
160 |
-
"Requirement already satisfied: typer[all]<1.0,>=0.9 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (0.9.0)\n",
|
161 |
-
"Requirement already satisfied: typing-extensions~=4.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (4.9.0)\n",
|
162 |
-
"Requirement already satisfied: uvicorn>=0.14.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio) (0.25.0)\n",
|
163 |
-
"Requirement already satisfied: fsspec in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio-client==0.8.0->gradio) (2023.10.0)\n",
|
164 |
-
"Requirement already satisfied: websockets<12.0,>=10.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from gradio-client==0.8.0->gradio) (11.0.3)\n"
|
165 |
-
]
|
166 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
{
|
168 |
"name": "stdout",
|
169 |
"output_type": "stream",
|
170 |
"text": [
|
171 |
-
"
|
172 |
-
"Requirement already satisfied: toolz in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from altair<6.0,>=4.2.0->gradio) (0.12.0)\n",
|
173 |
-
"Requirement already satisfied: filelock in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from huggingface-hub>=0.19.3->gradio) (3.13.1)\n",
|
174 |
-
"Requirement already satisfied: requests in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from huggingface-hub>=0.19.3->gradio) (2.31.0)\n",
|
175 |
-
"Requirement already satisfied: tqdm>=4.42.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from huggingface-hub>=0.19.3->gradio) (4.66.1)\n",
|
176 |
-
"Requirement already satisfied: contourpy>=1.0.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (1.2.0)\n",
|
177 |
-
"Requirement already satisfied: cycler>=0.10 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (0.12.1)\n",
|
178 |
-
"Requirement already satisfied: fonttools>=4.22.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (4.47.0)\n",
|
179 |
-
"Requirement already satisfied: kiwisolver>=1.3.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (1.4.5)\n",
|
180 |
-
"Requirement already satisfied: pyparsing>=2.3.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (3.1.1)\n",
|
181 |
-
"Requirement already satisfied: python-dateutil>=2.7 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from matplotlib~=3.0->gradio) (2.8.2)\n",
|
182 |
-
"Requirement already satisfied: pytz>=2020.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from pandas<3.0,>=1.0->gradio) (2023.3.post1)\n",
|
183 |
-
"Requirement already satisfied: tzdata>=2022.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from pandas<3.0,>=1.0->gradio) (2023.4)\n",
|
184 |
-
"Requirement already satisfied: annotated-types>=0.4.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from pydantic>=2.0->gradio) (0.6.0)\n",
|
185 |
-
"Requirement already satisfied: pydantic-core==2.14.6 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from pydantic>=2.0->gradio) (2.14.6)\n",
|
186 |
-
"Requirement already satisfied: click<9.0.0,>=7.1.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from typer[all]<1.0,>=0.9->gradio) (8.1.7)\n",
|
187 |
-
"Requirement already satisfied: colorama<0.5.0,>=0.4.3 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from typer[all]<1.0,>=0.9->gradio) (0.4.6)\n",
|
188 |
-
"Requirement already satisfied: shellingham<2.0.0,>=1.3.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from typer[all]<1.0,>=0.9->gradio) (1.5.4)\n",
|
189 |
-
"Requirement already satisfied: rich<14.0.0,>=10.11.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from typer[all]<1.0,>=0.9->gradio) (13.7.0)\n",
|
190 |
-
"Requirement already satisfied: h11>=0.8 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from uvicorn>=0.14.0->gradio) (0.14.0)\n",
|
191 |
-
"Requirement already satisfied: starlette<0.33.0,>=0.29.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from fastapi->gradio) (0.32.0.post1)\n",
|
192 |
-
"Requirement already satisfied: anyio in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from httpx->gradio) (4.2.0)\n",
|
193 |
-
"Requirement already satisfied: certifi in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from httpx->gradio) (2023.11.17)\n",
|
194 |
-
"Requirement already satisfied: httpcore==1.* in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from httpx->gradio) (1.0.2)\n",
|
195 |
-
"Requirement already satisfied: idna in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from httpx->gradio) (3.6)\n",
|
196 |
-
"Requirement already satisfied: sniffio in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from httpx->gradio) (1.3.0)\n",
|
197 |
-
"Requirement already satisfied: attrs>=22.2.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (23.2.0)\n",
|
198 |
-
"Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (2023.12.1)\n",
|
199 |
-
"Requirement already satisfied: referencing>=0.28.4 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.32.0)\n",
|
200 |
-
"Requirement already satisfied: rpds-py>=0.7.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.16.2)\n",
|
201 |
-
"Requirement already satisfied: six>=1.5 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n",
|
202 |
-
"Requirement already satisfied: markdown-it-py>=2.2.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (3.0.0)\n",
|
203 |
-
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (2.17.2)\n",
|
204 |
-
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from requests->huggingface-hub>=0.19.3->gradio) (3.3.2)\n",
|
205 |
-
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from requests->huggingface-hub>=0.19.3->gradio) (1.26.18)\n",
|
206 |
-
"Requirement already satisfied: mdurl~=0.1 in /Users/kabeerakande/Library/Caches/pypoetry/virtualenvs/mlplatform-NR7YTMyt-py3.11/lib/python3.11/site-packages (from markdown-it-py>=2.2.0->rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (0.1.2)\n",
|
207 |
"\n",
|
208 |
-
"
|
209 |
-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
|
210 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
}
|
212 |
],
|
213 |
"source": [
|
214 |
-
"
|
215 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
]
|
217 |
},
|
218 |
{
|
219 |
"cell_type": "code",
|
220 |
"execution_count": null,
|
221 |
-
"id": "
|
222 |
"metadata": {},
|
223 |
"outputs": [],
|
224 |
"source": []
|
@@ -226,9 +258,9 @@
|
|
226 |
],
|
227 |
"metadata": {
|
228 |
"kernelspec": {
|
229 |
-
"display_name": "
|
230 |
"language": "python",
|
231 |
-
"name": "
|
232 |
},
|
233 |
"language_info": {
|
234 |
"codemirror_mode": {
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"id": "aa1a8952",
|
7 |
"metadata": {},
|
8 |
"outputs": [],
|
9 |
"source": [
|
10 |
+
"#import libraries\n",
|
11 |
+
"from transformers import pipeline"
|
12 |
]
|
13 |
},
|
14 |
{
|
15 |
"cell_type": "code",
|
16 |
+
"execution_count": 1,
|
17 |
+
"id": "5493cee5",
|
18 |
"metadata": {},
|
19 |
"outputs": [
|
20 |
{
|
21 |
+
"data": {
|
22 |
+
"application/vnd.jupyter.widget-view+json": {
|
23 |
+
"model_id": "9b94e18c676540d1ad8312149bdbcc7c",
|
24 |
+
"version_major": 2,
|
25 |
+
"version_minor": 0
|
26 |
+
},
|
27 |
+
"text/plain": [
|
28 |
+
"model.safetensors: 0%| | 0.00/431M [00:00<?, ?B/s]"
|
29 |
+
]
|
30 |
+
},
|
31 |
+
"metadata": {},
|
32 |
+
"output_type": "display_data"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
},
|
34 |
{
|
35 |
+
"data": {
|
36 |
+
"application/vnd.jupyter.widget-view+json": {
|
37 |
+
"model_id": "586b43b1b9e2484c9b8636f9b41ab5e2",
|
38 |
+
"version_major": 2,
|
39 |
+
"version_minor": 0
|
40 |
+
},
|
41 |
+
"text/plain": [
|
42 |
+
"tokenizer_config.json: 0%| | 0.00/1.19k [00:00<?, ?B/s]"
|
43 |
+
]
|
44 |
+
},
|
45 |
+
"metadata": {},
|
46 |
+
"output_type": "display_data"
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"data": {
|
50 |
+
"application/vnd.jupyter.widget-view+json": {
|
51 |
+
"model_id": "d6c722044e074fd58b9cf1c67fa48551",
|
52 |
+
"version_major": 2,
|
53 |
+
"version_minor": 0
|
54 |
+
},
|
55 |
+
"text/plain": [
|
56 |
+
"vocab.txt: 0%| | 0.00/213k [00:00<?, ?B/s]"
|
57 |
+
]
|
58 |
+
},
|
59 |
+
"metadata": {},
|
60 |
+
"output_type": "display_data"
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"data": {
|
64 |
+
"application/vnd.jupyter.widget-view+json": {
|
65 |
+
"model_id": "95002c472f794e3b9b96dcfba697395e",
|
66 |
+
"version_major": 2,
|
67 |
+
"version_minor": 0
|
68 |
+
},
|
69 |
+
"text/plain": [
|
70 |
+
"tokenizer.json: 0%| | 0.00/669k [00:00<?, ?B/s]"
|
71 |
+
]
|
72 |
+
},
|
73 |
+
"metadata": {},
|
74 |
+
"output_type": "display_data"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
},
|
76 |
+
{
|
77 |
+
"data": {
|
78 |
+
"application/vnd.jupyter.widget-view+json": {
|
79 |
+
"model_id": "b71e5e8241de454c9bd5f7066b3f5413",
|
80 |
+
"version_major": 2,
|
81 |
+
"version_minor": 0
|
82 |
+
},
|
83 |
+
"text/plain": [
|
84 |
+
"special_tokens_map.json: 0%| | 0.00/125 [00:00<?, ?B/s]"
|
85 |
+
]
|
86 |
+
},
|
87 |
+
"metadata": {},
|
88 |
+
"output_type": "display_data"
|
89 |
+
}
|
90 |
+
],
|
91 |
+
"source": [
|
92 |
+
"#reference appropriate Hugging Face model\n",
|
93 |
+
"model_name = 'koakande/bert-finetuned-ner'\n",
|
94 |
+
"\n",
|
95 |
+
"# Load token classification pipeline modelfrom Hugging Face\n",
|
96 |
+
"model = pipeline(\"token-classification\", model=model_name, aggregation_strategy=\"simple\")"
|
97 |
+
]
|
98 |
+
},
|
99 |
+
{
|
100 |
+
"cell_type": "code",
|
101 |
+
"execution_count": 3,
|
102 |
+
"id": "f59488e3",
|
103 |
+
"metadata": {},
|
104 |
+
"outputs": [
|
105 |
+
{
|
106 |
+
"data": {
|
107 |
+
"text/plain": [
|
108 |
+
"'koakande/bert-finetuned-ner'"
|
109 |
+
]
|
110 |
+
},
|
111 |
+
"execution_count": 3,
|
112 |
+
"metadata": {},
|
113 |
+
"output_type": "execute_result"
|
114 |
+
}
|
115 |
+
],
|
116 |
+
"source": [
|
117 |
+
"model_name"
|
118 |
+
]
|
119 |
+
},
|
120 |
+
{
|
121 |
+
"cell_type": "code",
|
122 |
+
"execution_count": 4,
|
123 |
+
"id": "e6b97a0e",
|
124 |
+
"metadata": {},
|
125 |
+
"outputs": [
|
126 |
+
{
|
127 |
+
"data": {
|
128 |
+
"text/plain": [
|
129 |
+
"[{'entity_group': 'PER',\n",
|
130 |
+
" 'score': 0.99741244,\n",
|
131 |
+
" 'word': 'Kabeer',\n",
|
132 |
+
" 'start': 12,\n",
|
133 |
+
" 'end': 18},\n",
|
134 |
+
" {'entity_group': 'ORG',\n",
|
135 |
+
" 'score': 0.9985826,\n",
|
136 |
+
" 'word': 'OVO',\n",
|
137 |
+
" 'start': 61,\n",
|
138 |
+
" 'end': 64},\n",
|
139 |
+
" {'entity_group': 'LOC',\n",
|
140 |
+
" 'score': 0.99884343,\n",
|
141 |
+
" 'word': 'UK',\n",
|
142 |
+
" 'start': 72,\n",
|
143 |
+
" 'end': 74}]"
|
144 |
+
]
|
145 |
+
},
|
146 |
+
"execution_count": 4,
|
147 |
+
"metadata": {},
|
148 |
+
"output_type": "execute_result"
|
149 |
+
}
|
150 |
+
],
|
151 |
+
"source": [
|
152 |
+
"msg = \"Hello, I am Kabeer. I work as a machine learning engineer at OVO in the UK\"\n",
|
153 |
+
"model(msg)"
|
154 |
+
]
|
155 |
+
},
|
156 |
+
{
|
157 |
+
"cell_type": "code",
|
158 |
+
"execution_count": 5,
|
159 |
+
"id": "7c54c0ca",
|
160 |
+
"metadata": {},
|
161 |
+
"outputs": [
|
162 |
+
{
|
163 |
+
"data": {
|
164 |
+
"text/plain": [
|
165 |
+
"\"Hello, I am <span style='border: 2px solid green;'>Kabeer</span>. I work as a machine learning engineer at <span style='border: 2px solid green;'>OVO</span> in the <span style='border: 2px solid green;'>UK</span>\""
|
166 |
+
]
|
167 |
+
},
|
168 |
+
"execution_count": 5,
|
169 |
+
"metadata": {},
|
170 |
+
"output_type": "execute_result"
|
171 |
+
}
|
172 |
+
],
|
173 |
+
"source": [
|
174 |
+
"# write a prediction method for the model\n",
|
175 |
+
"def predict_entities(text):\n",
|
176 |
+
" # Use the loaded model to identify entities in the text\n",
|
177 |
+
" entities = model(text)\n",
|
178 |
+
" # Highlight identified entities in the input text\n",
|
179 |
+
" highlighted_text = text\n",
|
180 |
+
" for entity in entities:\n",
|
181 |
+
" entity_text = text[entity['start']:entity['end']]\n",
|
182 |
+
" replacement = f\"<span style='border: 2px solid green;'>{entity_text}</span>\"\n",
|
183 |
+
" highlighted_text = highlighted_text.replace(entity_text, replacement)\n",
|
184 |
+
" return highlighted_text\n",
|
185 |
+
"\n",
|
186 |
+
"predict_entities(msg)"
|
187 |
+
]
|
188 |
+
},
|
189 |
+
{
|
190 |
+
"cell_type": "code",
|
191 |
+
"execution_count": 6,
|
192 |
+
"id": "4d784554",
|
193 |
+
"metadata": {},
|
194 |
+
"outputs": [
|
195 |
{
|
196 |
"name": "stdout",
|
197 |
"output_type": "stream",
|
198 |
"text": [
|
199 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
"\n",
|
201 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
|
|
202 |
]
|
203 |
+
},
|
204 |
+
{
|
205 |
+
"data": {
|
206 |
+
"text/html": [
|
207 |
+
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
208 |
+
],
|
209 |
+
"text/plain": [
|
210 |
+
"<IPython.core.display.HTML object>"
|
211 |
+
]
|
212 |
+
},
|
213 |
+
"metadata": {},
|
214 |
+
"output_type": "display_data"
|
215 |
+
},
|
216 |
+
{
|
217 |
+
"data": {
|
218 |
+
"text/plain": []
|
219 |
+
},
|
220 |
+
"execution_count": 6,
|
221 |
+
"metadata": {},
|
222 |
+
"output_type": "execute_result"
|
223 |
}
|
224 |
],
|
225 |
"source": [
|
226 |
+
"# gradio interface\n",
|
227 |
+
"import gradio as gr\n",
|
228 |
+
"\n",
|
229 |
+
"title = \"Named Entity Recognizer\"\n",
|
230 |
+
"\n",
|
231 |
+
"description = \"\"\"\n",
|
232 |
+
"This model has been trained to identify entities in a given text. It returns the input text with the entities highlighted in green. Give it a try!\n",
|
233 |
+
"\"\"\"\n",
|
234 |
+
"\n",
|
235 |
+
"article = \"The model is trained using bert-finetuned-ner.\"\n",
|
236 |
+
"\n",
|
237 |
+
"iface = gr.Interface(\n",
|
238 |
+
" fn=predict_entities,\n",
|
239 |
+
" inputs=gr.Textbox(lines=5, placeholder=\"Enter text...\"),\n",
|
240 |
+
" outputs=gr.HTML(),\n",
|
241 |
+
" title=title,\n",
|
242 |
+
" description=description,\n",
|
243 |
+
" article=article,\n",
|
244 |
+
" examples=[[\"Hello, I am Kabeer. I work as a machine learning engineer at OVO in the UK\"], [\"This is Maryam who is a Leicester based NHS Doctor\"]],\n",
|
245 |
+
")\n",
|
246 |
+
"\n",
|
247 |
+
"iface.launch()"
|
248 |
]
|
249 |
},
|
250 |
{
|
251 |
"cell_type": "code",
|
252 |
"execution_count": null,
|
253 |
+
"id": "4f930b57",
|
254 |
"metadata": {},
|
255 |
"outputs": [],
|
256 |
"source": []
|
|
|
258 |
],
|
259 |
"metadata": {
|
260 |
"kernelspec": {
|
261 |
+
"display_name": "named_entity__kernel",
|
262 |
"language": "python",
|
263 |
+
"name": "named_entity__kernel"
|
264 |
},
|
265 |
"language_info": {
|
266 |
"codemirror_mode": {
|