{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "784eec04-5ea5-4664-b5dc-76aca7af15d6", "metadata": {}, "outputs": [], "source": [ "import flair\n", "\n", "from flair.datasets.sequence_labeling import ColumnCorpus\n", "from flair.file_utils import cached_path\n", "\n", "from pathlib import Path\n", "from typing import Optional, Union" ] }, { "cell_type": "code", "execution_count": 4, "id": "8a44d348-22a7-4b40-a982-e227ebf5e942", "metadata": {}, "outputs": [], "source": [ "class NER_CO_FUNER(ColumnCorpus):\n", " def __init__(\n", " self,\n", " base_path: Optional[Union[str, Path]] = None,\n", " in_memory: bool = True,\n", " **corpusargs,\n", " ) -> None:\n", " base_path = flair.cache_root / \"datasets\" if not base_path else Path(base_path)\n", " dataset_name = self.__class__.__name__.lower()\n", " data_folder = base_path / dataset_name\n", " data_path = flair.cache_root / \"datasets\" / dataset_name\n", "\n", " columns = {0: \"text\", 2: \"ner\"}\n", "\n", " hf_download_path = \"https://huggingface.co/datasets/stefan-it/co-funer/resolve/main\"\n", "\n", " for split in [\"train\", \"dev\", \"test\"]:\n", " cached_path(f\"{hf_download_path}/{split}.tsv\", data_path)\n", " \n", " super().__init__(\n", " data_folder,\n", " columns,\n", " in_memory=in_memory,\n", " comment_symbol=None,\n", " **corpusargs,\n", " )" ] }, { "cell_type": "code", "execution_count": 5, "id": "efea04d2-957b-4b8c-a5b3-bb53f8b5264a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2024-03-25 13:46:15,348 https://huggingface.co/datasets/stefan-it/co-funer/resolve/main/train.tsv not found in cache, downloading to /tmp/tmpezcb9ala\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 669k/669k [00:00<00:00, 3.97MB/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "2024-03-25 13:46:15,771 copying /tmp/tmpezcb9ala to cache at /home/stefan/.flair/datasets/ner_co_funer/train.tsv\n", "2024-03-25 13:46:15,775 removing temp file /tmp/tmpezcb9ala\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "2024-03-25 13:46:16,020 https://huggingface.co/datasets/stefan-it/co-funer/resolve/main/dev.tsv not found in cache, downloading to /tmp/tmptresi_zq\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 74.9k/74.9k [00:00<00:00, 2.40MB/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "2024-03-25 13:46:16,299 copying /tmp/tmptresi_zq to cache at /home/stefan/.flair/datasets/ner_co_funer/dev.tsv\n", "2024-03-25 13:46:16,300 removing temp file /tmp/tmptresi_zq\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "2024-03-25 13:46:16,516 https://huggingface.co/datasets/stefan-it/co-funer/resolve/main/test.tsv not found in cache, downloading to /tmp/tmpma214nwe\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 75.0k/75.0k [00:00<00:00, 2.13MB/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "2024-03-25 13:46:16,810 copying /tmp/tmpma214nwe to cache at /home/stefan/.flair/datasets/ner_co_funer/test.tsv\n", "2024-03-25 13:46:16,811 removing temp file /tmp/tmpma214nwe\n", "2024-03-25 13:46:16,818 Reading data from /home/stefan/.flair/datasets/ner_co_funer\n", "2024-03-25 13:46:16,819 Train: /home/stefan/.flair/datasets/ner_co_funer/train.tsv\n", "2024-03-25 13:46:16,819 Dev: /home/stefan/.flair/datasets/ner_co_funer/dev.tsv\n", "2024-03-25 13:46:16,820 Test: /home/stefan/.flair/datasets/ner_co_funer/test.tsv\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "corpus = NER_CO_FUNER()" ] }, { "cell_type": "code", "execution_count": 6, "id": "a83b693a-de00-4bd9-bb00-91cb6b99fdc2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Corpus: 758 train + 94 dev + 96 test sentences\n" ] } ], "source": [ "print(str(corpus))" ] } ], "metadata": { "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.11.6" } }, "nbformat": 4, "nbformat_minor": 5 }