{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "bd9232bc-0c38-426d-b29d-7b4a03fd5242", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2024-11-22 22:50:45.568704: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n", "2024-11-22 22:50:45.569107: I external/local_xla/xla/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.\n", "2024-11-22 22:50:45.571074: I external/local_xla/xla/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.\n", "2024-11-22 22:50:45.576441: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:477] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n", "WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n", "E0000 00:00:1732312245.585696 11818 cuda_dnn.cc:8310] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n", "E0000 00:00:1732312245.588323 11818 cuda_blas.cc:1418] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n", "2024-11-22 22:50:45.597922: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n", "To enable the following instructions: AVX2 AVX_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n" ] } ], "source": [ "import flair\n", "\n", "from flair.datasets import ClassificationCorpus\n", "\n", "from huggingface_hub import hf_hub_download\n", "\n", "from pathlib import Path\n", "from typing import Optional, Union" ] }, { "cell_type": "code", "execution_count": 2, "id": "eb688e95-92e3-4b09-a523-eb62fd7cb0bc", "metadata": {}, "outputs": [], "source": [ "class OFFENSEVAL_TR_2020(ClassificationCorpus):\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", " for split in [\"train\", \"dev\", \"test\"]:\n", " hf_hub_download(repo_id=\"stefan-it/offenseval2020_tr\", repo_type=\"dataset\",\n", " filename=f\"{split}.txt\", token=True, local_dir=data_folder)\n", "\n", " super().__init__(\n", " data_path,\n", " **corpusargs,\n", " )" ] }, { "cell_type": "code", "execution_count": 3, "id": "add7c7f1-2ea2-40be-99a3-a71d20a3a25a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2024-11-22 22:50:51,534 Reading data from /home/stefan/.flair/datasets/offenseval_tr_2020\n", "2024-11-22 22:50:51,535 Train: /home/stefan/.flair/datasets/offenseval_tr_2020/train.txt\n", "2024-11-22 22:50:51,536 Dev: /home/stefan/.flair/datasets/offenseval_tr_2020/dev.txt\n", "2024-11-22 22:50:51,537 Test: /home/stefan/.flair/datasets/offenseval_tr_2020/test.txt\n", "2024-11-22 22:50:52,068 Initialized corpus /home/stefan/.flair/datasets/offenseval_tr_2020 (label type name is 'class')\n" ] } ], "source": [ "corpus = OFFENSEVAL_TR_2020()" ] }, { "cell_type": "code", "execution_count": 4, "id": "f9d2162a-c9bb-46f0-8898-b12ce286ff37", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Corpus: 30000 train + 1756 dev + 3528 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.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }