{ "cells": [ { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n" ] }, { "ename": "IndexError", "evalue": "list index out of range", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", "Input \u001b[0;32mIn [4]\u001b[0m, in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 16\u001b[0m tokens\u001b[38;5;241m.\u001b[39mappend(splits[\u001b[38;5;241m0\u001b[39m])\n\u001b[1;32m 17\u001b[0m pos_tags\u001b[38;5;241m.\u001b[39mappend(splits[\u001b[38;5;241m1\u001b[39m])\n\u001b[0;32m---> 18\u001b[0m ner_tags\u001b[38;5;241m.\u001b[39mappend(\u001b[43msplits\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241m.\u001b[39mrstrip())\n\u001b[1;32m 20\u001b[0m \u001b[38;5;66;03m# last example\u001b[39;00m\n\u001b[1;32m 21\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m tokens:\n", "\u001b[0;31mIndexError\u001b[0m: list index out of range" ] } ], "source": [ "with open(\"data/train.conll\", encoding=\"utf-8\") as f:\n", " guid = 0\n", " tokens = []\n", " pos_tags = []\n", " ner_tags = []\n", " for line in f:\n", " if line.startswith(\"-DOCSTART-\") or line == \"\" or line == \"\\n\":\n", " if tokens:\n", " guid += 1\n", " tokens = []\n", " pos_tags = []\n", " ner_tags = []\n", " else:\n", " print(guid)\n", " splits = line.split(\" \")\n", " tokens.append(splits[0])\n", " pos_tags.append(splits[1])\n", " ner_tags.append(splits[2].rstrip())\n", "\n", " # last example\n", " if tokens:\n", " print(\"lst\")" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Reusing dataset plod-cw (/home/diptesh/.cache/huggingface/datasets/surrey-nlp___plod-cw/PLOD-CW/0.0.5/ded93459451683583207c3ccb6a22ebeeafd54733e72757b6f73806d9aca6e83)\n" ] }, { "data": { "application/json": { "ascii": false, "bar_format": null, "colour": null, "elapsed": 0.010100603103637695, "initial": 0, "n": 0, "ncols": null, "nrows": null, "postfix": null, "prefix": "", "rate": null, "total": 3, "unit": "it", "unit_divisor": 1000, "unit_scale": false }, "application/vnd.jupyter.widget-view+json": { "model_id": "1f468deeb0f34c0b8fe8bdd94301ba38", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/3 [00:00 maxLen:\n", " maxLen = instanceLen\n", "\n", "print(maxLen)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "hfdataset", "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.9.12" } }, "nbformat": 4, "nbformat_minor": 2 }