data: add example script that show how to use this dataset within Flair library
Browse files- FlairDatasetLoader.ipynb +127 -0
FlairDatasetLoader.ipynb
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "bd9232bc-0c38-426d-b29d-7b4a03fd5242",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"name": "stderr",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"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",
|
14 |
+
"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",
|
15 |
+
"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",
|
16 |
+
"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",
|
17 |
+
"WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n",
|
18 |
+
"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",
|
19 |
+
"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",
|
20 |
+
"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",
|
21 |
+
"To enable the following instructions: AVX2 AVX_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n"
|
22 |
+
]
|
23 |
+
}
|
24 |
+
],
|
25 |
+
"source": [
|
26 |
+
"import flair\n",
|
27 |
+
"\n",
|
28 |
+
"from flair.datasets import ClassificationCorpus\n",
|
29 |
+
"\n",
|
30 |
+
"from huggingface_hub import hf_hub_download\n",
|
31 |
+
"\n",
|
32 |
+
"from pathlib import Path\n",
|
33 |
+
"from typing import Optional, Union"
|
34 |
+
]
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"cell_type": "code",
|
38 |
+
"execution_count": 2,
|
39 |
+
"id": "eb688e95-92e3-4b09-a523-eb62fd7cb0bc",
|
40 |
+
"metadata": {},
|
41 |
+
"outputs": [],
|
42 |
+
"source": [
|
43 |
+
"class OFFENSEVAL_TR_2020(ClassificationCorpus):\n",
|
44 |
+
" def __init__(\n",
|
45 |
+
" self,\n",
|
46 |
+
" base_path: Optional[Union[str, Path]] = None,\n",
|
47 |
+
" in_memory: bool = True,\n",
|
48 |
+
" **corpusargs,\n",
|
49 |
+
" ) -> None:\n",
|
50 |
+
" base_path = flair.cache_root / \"datasets\" if not base_path else Path(base_path)\n",
|
51 |
+
" dataset_name = self.__class__.__name__.lower()\n",
|
52 |
+
" data_folder = base_path / dataset_name\n",
|
53 |
+
" data_path = flair.cache_root / \"datasets\" / dataset_name\n",
|
54 |
+
"\n",
|
55 |
+
" for split in [\"train\", \"dev\", \"test\"]:\n",
|
56 |
+
" hf_hub_download(repo_id=\"stefan-it/offenseval2020_tr\", repo_type=\"dataset\",\n",
|
57 |
+
" filename=f\"{split}.txt\", token=True, local_dir=data_folder)\n",
|
58 |
+
"\n",
|
59 |
+
" super().__init__(\n",
|
60 |
+
" data_path,\n",
|
61 |
+
" **corpusargs,\n",
|
62 |
+
" )"
|
63 |
+
]
|
64 |
+
},
|
65 |
+
{
|
66 |
+
"cell_type": "code",
|
67 |
+
"execution_count": 3,
|
68 |
+
"id": "add7c7f1-2ea2-40be-99a3-a71d20a3a25a",
|
69 |
+
"metadata": {},
|
70 |
+
"outputs": [
|
71 |
+
{
|
72 |
+
"name": "stdout",
|
73 |
+
"output_type": "stream",
|
74 |
+
"text": [
|
75 |
+
"2024-11-22 22:50:51,534 Reading data from /home/stefan/.flair/datasets/offenseval_tr_2020\n",
|
76 |
+
"2024-11-22 22:50:51,535 Train: /home/stefan/.flair/datasets/offenseval_tr_2020/train.txt\n",
|
77 |
+
"2024-11-22 22:50:51,536 Dev: /home/stefan/.flair/datasets/offenseval_tr_2020/dev.txt\n",
|
78 |
+
"2024-11-22 22:50:51,537 Test: /home/stefan/.flair/datasets/offenseval_tr_2020/test.txt\n",
|
79 |
+
"2024-11-22 22:50:52,068 Initialized corpus /home/stefan/.flair/datasets/offenseval_tr_2020 (label type name is 'class')\n"
|
80 |
+
]
|
81 |
+
}
|
82 |
+
],
|
83 |
+
"source": [
|
84 |
+
"corpus = OFFENSEVAL_TR_2020()"
|
85 |
+
]
|
86 |
+
},
|
87 |
+
{
|
88 |
+
"cell_type": "code",
|
89 |
+
"execution_count": 4,
|
90 |
+
"id": "f9d2162a-c9bb-46f0-8898-b12ce286ff37",
|
91 |
+
"metadata": {},
|
92 |
+
"outputs": [
|
93 |
+
{
|
94 |
+
"name": "stdout",
|
95 |
+
"output_type": "stream",
|
96 |
+
"text": [
|
97 |
+
"Corpus: 30000 train + 1756 dev + 3528 test sentences\n"
|
98 |
+
]
|
99 |
+
}
|
100 |
+
],
|
101 |
+
"source": [
|
102 |
+
"print(str(corpus))"
|
103 |
+
]
|
104 |
+
}
|
105 |
+
],
|
106 |
+
"metadata": {
|
107 |
+
"kernelspec": {
|
108 |
+
"display_name": "Python 3 (ipykernel)",
|
109 |
+
"language": "python",
|
110 |
+
"name": "python3"
|
111 |
+
},
|
112 |
+
"language_info": {
|
113 |
+
"codemirror_mode": {
|
114 |
+
"name": "ipython",
|
115 |
+
"version": 3
|
116 |
+
},
|
117 |
+
"file_extension": ".py",
|
118 |
+
"mimetype": "text/x-python",
|
119 |
+
"name": "python",
|
120 |
+
"nbconvert_exporter": "python",
|
121 |
+
"pygments_lexer": "ipython3",
|
122 |
+
"version": "3.12.3"
|
123 |
+
}
|
124 |
+
},
|
125 |
+
"nbformat": 4,
|
126 |
+
"nbformat_minor": 5
|
127 |
+
}
|