Datasets:
Upload dataclass_code.ipynb
Browse files- 01 Codes/dataclass_code.ipynb +101 -0
01 Codes/dataclass_code.ipynb
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 1,
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"outputs": [],
|
| 8 |
+
"source": [
|
| 9 |
+
"from datasets import load_dataset\n",
|
| 10 |
+
"\n",
|
| 11 |
+
"dataset = load_dataset(\"divyasharma0795/AppleVisionPro_Tweets\")"
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"cell_type": "code",
|
| 16 |
+
"execution_count": 2,
|
| 17 |
+
"metadata": {},
|
| 18 |
+
"outputs": [
|
| 19 |
+
{
|
| 20 |
+
"name": "stdout",
|
| 21 |
+
"output_type": "stream",
|
| 22 |
+
"text": [
|
| 23 |
+
"HuggingFaceDataset(id=1769458624638619691, tweetText=\"Mordecai I can't sell nft for 10 dollars, how does this nft business work? #bloodbath #AppleVisionPro #DeadpoolAndWolverine #RegularShow @JGQuintel link: https://t.co/Bq3dzV4wgR https://t.co/rbrerIFcIs\", tweetURL='https://twitter.com/harndefty/status/1769458624638619691', tweetAuthor='Harndefty 🐔🍗', handle='@harndefty', replyCount=0, quoteCount=0, retweetCount=0, likeCount=0, views='26', bookmarkCount=0, createdAt='2024-03-17 13:19:45')\n"
|
| 24 |
+
]
|
| 25 |
+
}
|
| 26 |
+
],
|
| 27 |
+
"source": [
|
| 28 |
+
"from dataclasses import dataclass\n",
|
| 29 |
+
"from typing import List\n",
|
| 30 |
+
"from datasets import load_dataset\n",
|
| 31 |
+
"\n",
|
| 32 |
+
"\n",
|
| 33 |
+
"@dataclass\n",
|
| 34 |
+
"class HuggingFaceDataset:\n",
|
| 35 |
+
" id: int\n",
|
| 36 |
+
" tweetText: str\n",
|
| 37 |
+
" tweetURL: str\n",
|
| 38 |
+
" tweetAuthor: str\n",
|
| 39 |
+
" handle: str\n",
|
| 40 |
+
" replyCount: int\n",
|
| 41 |
+
" quoteCount: int\n",
|
| 42 |
+
" retweetCount: int\n",
|
| 43 |
+
" likeCount: int\n",
|
| 44 |
+
" views: int\n",
|
| 45 |
+
" bookmarkCount: int\n",
|
| 46 |
+
" createdAt: str\n",
|
| 47 |
+
"\n",
|
| 48 |
+
"\n",
|
| 49 |
+
"def load_custom_dataset(dataset_name):\n",
|
| 50 |
+
" dataset = load_dataset(dataset_name)\n",
|
| 51 |
+
"\n",
|
| 52 |
+
" # Extract relevant information and create a list of HuggingFaceDataset instances\n",
|
| 53 |
+
" custom_dataset = [\n",
|
| 54 |
+
" HuggingFaceDataset(\n",
|
| 55 |
+
" id=row[\"id\"],\n",
|
| 56 |
+
" tweetText=row[\"tweetText\"],\n",
|
| 57 |
+
" tweetURL=row[\"tweetURL\"],\n",
|
| 58 |
+
" tweetAuthor=row[\"tweetAuthor\"],\n",
|
| 59 |
+
" handle=row[\"handle\"],\n",
|
| 60 |
+
" replyCount=row[\"replyCount\"],\n",
|
| 61 |
+
" quoteCount=row[\"quoteCount\"],\n",
|
| 62 |
+
" retweetCount=row[\"retweetCount\"],\n",
|
| 63 |
+
" likeCount=row[\"likeCount\"],\n",
|
| 64 |
+
" views=row[\"views\"],\n",
|
| 65 |
+
" bookmarkCount=row[\"bookmarkCount\"],\n",
|
| 66 |
+
" createdAt=row[\"createdAt\"],\n",
|
| 67 |
+
" )\n",
|
| 68 |
+
" for row in dataset[\"train\"]\n",
|
| 69 |
+
" ]\n",
|
| 70 |
+
"\n",
|
| 71 |
+
" return custom_dataset\n",
|
| 72 |
+
"\n",
|
| 73 |
+
"\n",
|
| 74 |
+
"# Usage\n",
|
| 75 |
+
"custom_dataset = load_custom_dataset(\"divyasharma0795/AppleVisionPro_Tweets\")\n",
|
| 76 |
+
"print(custom_dataset[0]) # Print the first instance"
|
| 77 |
+
]
|
| 78 |
+
}
|
| 79 |
+
],
|
| 80 |
+
"metadata": {
|
| 81 |
+
"kernelspec": {
|
| 82 |
+
"display_name": "base",
|
| 83 |
+
"language": "python",
|
| 84 |
+
"name": "python3"
|
| 85 |
+
},
|
| 86 |
+
"language_info": {
|
| 87 |
+
"codemirror_mode": {
|
| 88 |
+
"name": "ipython",
|
| 89 |
+
"version": 3
|
| 90 |
+
},
|
| 91 |
+
"file_extension": ".py",
|
| 92 |
+
"mimetype": "text/x-python",
|
| 93 |
+
"name": "python",
|
| 94 |
+
"nbconvert_exporter": "python",
|
| 95 |
+
"pygments_lexer": "ipython3",
|
| 96 |
+
"version": "3.11.5"
|
| 97 |
+
}
|
| 98 |
+
},
|
| 99 |
+
"nbformat": 4,
|
| 100 |
+
"nbformat_minor": 2
|
| 101 |
+
}
|