{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-06-18T21:36:46.951799Z","iopub.execute_input":"2023-06-18T21:36:46.952293Z","iopub.status.idle":"2023-06-18T21:36:46.958270Z","shell.execute_reply.started":"2023-06-18T21:36:46.952258Z","shell.execute_reply":"2023-06-18T21:36:46.956933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kaggle = pd.read_csv(\"/kaggle/input/2023-kaggle-ai-report/kaggle_writeups_20230510.csv\")\nkaggle.head()","metadata":{"execution":{"iopub.status.busy":"2023-06-18T21:36:46.967636Z","iopub.execute_input":"2023-06-18T21:36:46.968169Z","iopub.status.idle":"2023-06-18T21:36:47.206231Z","shell.execute_reply.started":"2023-06-18T21:36:46.968120Z","shell.execute_reply":"2023-06-18T21:36:47.205016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import requests\n\nAPI_URL = \"https://api-inference.huggingface.co/models/dslim/bert-base-NER\"\nheaders = {\"Authorization\": \"Bearer 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\"}\n\ndef query(payload):\n\tresponse = requests.post(API_URL, headers=headers, json=payload)\n\treturn response.json()\n","metadata":{"execution":{"iopub.status.busy":"2023-06-18T21:36:47.208199Z","iopub.execute_input":"2023-06-18T21:36:47.209176Z","iopub.status.idle":"2023-06-18T21:36:47.214708Z","shell.execute_reply.started":"2023-06-18T21:36:47.209140Z","shell.execute_reply":"2023-06-18T21:36:47.213580Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"entities = []\n\nfor i, writeup in enumerate(kaggle.Writeup):\n    output = query({\"inputs\": str(writeup),})\n    print(i, len(output))\n    entities.append(output)","metadata":{"execution":{"iopub.status.busy":"2023-06-18T21:36:47.216013Z","iopub.execute_input":"2023-06-18T21:36:47.216530Z","iopub.status.idle":"2023-06-18T21:36:48.235568Z","shell.execute_reply.started":"2023-06-18T21:36:47.216489Z","shell.execute_reply":"2023-06-18T21:36:48.233577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"kaggle[\"entities\"] = entities\nkaggle.to_csv(\"kaggle_writeups_20230510_with_entities.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-06-18T21:37:19.811371Z","iopub.execute_input":"2023-06-18T21:37:19.811828Z","iopub.status.idle":"2023-06-18T21:37:20.156886Z","shell.execute_reply.started":"2023-06-18T21:37:19.811793Z","shell.execute_reply":"2023-06-18T21:37:20.155563Z"},"trusted":true},"execution_count":null,"outputs":[]}]}