File size: 5,881 Bytes
006fa2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d78b2b50-9c54-441e-a835-b28cb0f8e096",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-11-29 23:21:49.836344: 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-29 23:21:49.836729: 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-29 23:21:49.838569: 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-29 23:21:49.843832: 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:1732918909.852690   10769 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:1732918909.855335   10769 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-29 23:21:49.864609: 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": "404f1a80-5dcd-44cf-a37c-731553bebafc",
   "metadata": {},
   "outputs": [],
   "source": [
    "class SENTI_ANNO(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/senti-anno\", 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": "146baf74-5208-4a46-bb1f-0b652bae92c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "cfb52f4fd9bd47d496df3c39a460aac3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "train.txt:   0%|          | 0.00/210k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ee09bd462f6f4837bd3d21ff21faa3c8",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "dev.txt:   0%|          | 0.00/26.2k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "db9260082d304746875ef8fa6b7c6869",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "test.txt:   0%|          | 0.00/26.3k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2024-11-29 23:24:50,712 Reading data from /home/stefan/.flair/datasets/senti_anno\n",
      "2024-11-29 23:24:50,713 Train: /home/stefan/.flair/datasets/senti_anno/train.txt\n",
      "2024-11-29 23:24:50,713 Dev: /home/stefan/.flair/datasets/senti_anno/dev.txt\n",
      "2024-11-29 23:24:50,714 Test: /home/stefan/.flair/datasets/senti_anno/test.txt\n",
      "2024-11-29 23:24:50,725 Initialized corpus /home/stefan/.flair/datasets/senti_anno (label type name is 'class')\n"
     ]
    }
   ],
   "source": [
    "corpus = SENTI_ANNO()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0b4badbf-6e62-4a72-af41-cce3811007ae",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Corpus: 741 train + 93 dev + 95 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
}