File size: 3,129 Bytes
57ba6a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from datasets import load_dataset\n",
    "\n",
    "dataset = load_dataset(\"divyasharma0795/AppleVisionPro_Tweets\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "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"
     ]
    }
   ],
   "source": [
    "from dataclasses import dataclass\n",
    "from typing import List\n",
    "from datasets import load_dataset\n",
    "\n",
    "\n",
    "@dataclass\n",
    "class HuggingFaceDataset:\n",
    "    id: int\n",
    "    tweetText: str\n",
    "    tweetURL: str\n",
    "    tweetAuthor: str\n",
    "    handle: str\n",
    "    replyCount: int\n",
    "    quoteCount: int\n",
    "    retweetCount: int\n",
    "    likeCount: int\n",
    "    views: int\n",
    "    bookmarkCount: int\n",
    "    createdAt: str\n",
    "\n",
    "\n",
    "def load_custom_dataset(dataset_name):\n",
    "    dataset = load_dataset(dataset_name)\n",
    "\n",
    "    # Extract relevant information and create a list of HuggingFaceDataset instances\n",
    "    custom_dataset = [\n",
    "        HuggingFaceDataset(\n",
    "            id=row[\"id\"],\n",
    "            tweetText=row[\"tweetText\"],\n",
    "            tweetURL=row[\"tweetURL\"],\n",
    "            tweetAuthor=row[\"tweetAuthor\"],\n",
    "            handle=row[\"handle\"],\n",
    "            replyCount=row[\"replyCount\"],\n",
    "            quoteCount=row[\"quoteCount\"],\n",
    "            retweetCount=row[\"retweetCount\"],\n",
    "            likeCount=row[\"likeCount\"],\n",
    "            views=row[\"views\"],\n",
    "            bookmarkCount=row[\"bookmarkCount\"],\n",
    "            createdAt=row[\"createdAt\"],\n",
    "        )\n",
    "        for row in dataset[\"train\"]\n",
    "    ]\n",
    "\n",
    "    return custom_dataset\n",
    "\n",
    "\n",
    "# Usage\n",
    "custom_dataset = load_custom_dataset(\"divyasharma0795/AppleVisionPro_Tweets\")\n",
    "print(custom_dataset[0])  # Print the first instance"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "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.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}