{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# <center style=\"font-family: consolas; font-size: 32px; font-weight: bold;\"> Google - 🤟American Sign Language Fingerspelling Recognition🖖</center>\n<p><center style=\"color:#949494; font-family: consolas; font-size: 20px;\">Train fast and accurate American Sign Language fingerspelling recognition models</center></p>\n\n***","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"markdown","source":"# <center style=\"font-family: consolas; font-size: 32px; font-weight: bold;\">(ಠಿ⁠_⁠ಠ) Overview</center>\n\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ The goal of the competition is to detect and translate American Sign Language (ASL) fingerspelling into text.</p>\n\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ The competition is based on a large dataset of over three million fingerspelled characters produced by over 100 Deaf signers captured via the selfie camera of a smartphone with a variety of backgrounds and lighting conditions.</p>\n\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ The competition aims to improve sign language recognition technology, making it more accessible for the Deaf and Hard of Hearing community.</p>\n\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ Fingerspelling is an important part of ASL and is often used for communicating names, addresses, phone numbers, and other information commonly entered on a mobile phone.</p>\n\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ ASL fingerspelling can be substantially faster than typing on a smartphone’s virtual keyboard.</p>\n\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ Sign language recognition AI for text entry lags far behind voice-to-text or even gesture-based typing, as robust datasets didn't previously exist.</p>\n\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ Participating in this competition could help provide Deaf and Hard of Hearing users with the option to fingerspell words instead of using a keyboard, enabling them to communicate with hearing non-signers more quickly and smoothly.</p>","metadata":{}},{"cell_type":"markdown","source":"#### <a id=\"top\"></a>\n# <div style=\"box-shadow: rgb(60, 121, 245) 0px 0px 0px 3px inset, rgb(255, 255, 255) 10px -10px 0px -3px, rgb(31, 193, 27) 10px -10px, rgb(255, 255, 255) 20px -20px 0px -3px, rgb(255, 217, 19) 20px -20px, rgb(255, 255, 255) 30px -30px 0px -3px, rgb(255, 156, 85) 30px -30px, rgb(255, 255, 255) 40px -40px 0px -3px, rgb(255, 85, 85) 40px -40px; padding:20px; margin-right: 40px; font-size:30px; font-family: consolas; text-align:center; display:fill; border-radius:15px; color:rgb(60, 121, 245);\"><b>Table of contents</b></div>\n\n<div style=\"background-color: rgba(60, 121, 245, 0.03); padding:30px; font-size:15px; font-family: consolas;\">\n<ul>\n    <li><a href=\"#0\" target=\"_self\" rel=\" noreferrer nofollow\">0. Import all dependencies</a></li>\n    <li><a href=\"#1\" target=\"_self\" rel=\" noreferrer nofollow\">1. Data overview</a></li>\n    <li><a href=\"#2\" target=\"_self\" rel=\" noreferrer nofollow\">2. Train overview</a></li>\n    <li><a href=\"#3\" target=\"_self\" rel=\" noreferrer nofollow\">3. Supplemental overview</a></li>\n</ul>\n</div>","metadata":{}},{"cell_type":"markdown","source":"<a id=\"0\"></a>\n# <div style=\"box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px inset, rgb(51, 51, 51) 0px 0px 0px 3px inset; padding:20px; font-size:32px; font-family: consolas; text-align:center; display:fill; border-radius:15px;  color:rgb(34, 34, 34);\"> <b> 0. Import all dependencies </b></div>","metadata":{}},{"cell_type":"code","source":"# import the desired packages\nimport numpy as np\nimport pandas as pd\nimport json\nimport plotly.graph_objects as go\nimport plotly.io as pio\npio.templates.default = \"simple_white\"","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:52:02.2002Z","iopub.execute_input":"2023-05-11T19:52:02.200657Z","iopub.status.idle":"2023-05-11T19:52:03.99181Z","shell.execute_reply.started":"2023-05-11T19:52:02.200619Z","shell.execute_reply":"2023-05-11T19:52:03.990644Z"},"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def map_new_to_old_style(sequence):\n    types = []\n    landmark_indexes = []\n    for column in list(sequence.columns)[1:544]:\n        parts = column.split(\"_\")\n        if len(parts) == 4:\n            types.append(parts[1] + \"_\" + parts[2])\n        else:\n            types.append(parts[1])\n\n        landmark_indexes.append(int(parts[-1]))\n\n    data = {\n        \"frame\": [],\n        \"type\": [],\n        \"landmark_index\": [],\n        \"x\": [],\n        \"y\": [],\n        \"z\": []\n    }\n\n    for index, row in sequence.iterrows():\n        data[\"frame\"] += [int(row.frame)]*543\n        data[\"type\"] += types\n        data[\"landmark_index\"] += landmark_indexes\n\n        for _type, landmark_index in zip(types, landmark_indexes):\n            data[\"x\"].append(row[f\"x_{_type}_{landmark_index}\"])\n            data[\"y\"].append(row[f\"y_{_type}_{landmark_index}\"])\n            data[\"z\"].append(row[f\"z_{_type}_{landmark_index}\"])\n\n    return pd.DataFrame.from_dict(data)\n\n# assign desired colors to landmarks\ndef assign_color(row):\n    if row == 'face':\n        return 'red'\n    elif 'hand' in row:\n        return 'dodgerblue'\n    else:\n        return 'green'\n\n# specifies the plotting order\ndef assign_order(row):\n    if row.type == 'face':\n        return row.landmark_index + 101\n    elif row.type == 'pose':\n        return row.landmark_index + 30\n    elif row.type == 'left_hand':\n        return row.landmark_index + 80\n    else:\n        return row.landmark_index\n\ndef visualise2d_landmarks(parquet_df, title=\"\"):\n    connections = [  \n        [0, 1, 2, 3, 4,],\n        [0, 5, 6, 7, 8],\n        [0, 9, 10, 11, 12],\n        [0, 13, 14, 15, 16],\n        [0, 17, 18, 19, 20],\n\n        \n        [38, 36, 35, 34, 30, 31, 32, 33, 37],\n        [40, 39],\n        [52, 46, 50, 48, 46, 44, 42, 41, 43, 45, 47, 49, 45, 51],\n        [42, 54, 56, 58, 60, 62, 58],\n        [41, 53, 55, 57, 59, 61, 57],\n        [54, 53],\n\n        \n        [80, 81, 82, 83, 84, ],\n        [80, 85, 86, 87, 88],\n        [80, 89, 90, 91, 92],\n        [80, 93, 94, 95, 96],\n        [80, 97, 98, 99, 100], ]\n\n    parquet_df = map_new_to_old_style(parquet_df)\n    frames = sorted(set(parquet_df.frame))\n    first_frame = min(frames)\n    parquet_df['color'] = parquet_df.type.apply(lambda row: assign_color(row))\n    parquet_df['plot_order'] = parquet_df.apply(lambda row: assign_order(row), axis=1)\n    first_frame_df = parquet_df[parquet_df.frame == first_frame].copy()\n    first_frame_df = first_frame_df.sort_values([\"plot_order\"]).set_index('plot_order')\n\n\n    frames_l = []\n    for frame in frames:\n        filtered_df = parquet_df[parquet_df.frame == frame].copy()\n        filtered_df = filtered_df.sort_values([\"plot_order\"]).set_index(\"plot_order\")\n        traces = [go.Scatter(\n            x=filtered_df['x'],\n            y=filtered_df['y'],\n            mode='markers',\n            marker=dict(\n                color=filtered_df.color,\n                size=9))]\n\n        for i, seg in enumerate(connections):\n            trace = go.Scatter(\n                    x=filtered_df.loc[seg]['x'],\n                    y=filtered_df.loc[seg]['y'],\n                    mode='lines',\n            )\n            traces.append(trace)\n        frame_data = go.Frame(data=traces, traces = [i for i in range(17)])\n        frames_l.append(frame_data)\n\n    traces = [go.Scatter(\n        x=first_frame_df['x'],\n        y=first_frame_df['y'],\n        mode='markers',\n        marker=dict(\n            color=first_frame_df.color,\n            size=9\n        )\n    )]\n    for i, seg in enumerate(connections):\n        trace = go.Scatter(\n            x=first_frame_df.loc[seg]['x'],\n            y=first_frame_df.loc[seg]['y'],\n            mode='lines',\n            line=dict(\n                color='black',\n                width=2\n            )\n        )\n        traces.append(trace)\n    fig = go.Figure(\n        data=traces,\n        frames=frames_l\n    )\n\n\n    fig.update_layout(\n        width=500,\n        height=800,\n        scene={\n            'aspectmode': 'data',\n        },\n        updatemenus=[\n            {\n                \"buttons\": [\n                    {\n                        \"args\": [None, {\"frame\": {\"duration\": 100,\n                                                  \"redraw\": True},\n                                        \"fromcurrent\": True,\n                                        \"transition\": {\"duration\": 0}}],\n                        \"label\": \"&#9654;\",\n                        \"method\": \"animate\",\n                    },\n\n                ],\n                \"direction\": \"left\",\n                \"pad\": {\"r\": 100, \"t\": 100},\n                \"font\": {\"size\":30},\n                \"type\": \"buttons\",\n                \"x\": 0.1,\n                \"y\": 0,\n            }\n        ],\n    )\n    camera = dict(\n        up=dict(x=0, y=-1, z=0),\n        eye=dict(x=0, y=0, z=2.5)\n    )\n    fig.update_layout(title_text=title, title_x=0.5)\n    fig.update_layout(scene_camera=camera, showlegend=False)\n    fig.update_layout(xaxis = dict(visible=False),\n            yaxis = dict(visible=False),\n    )\n    fig.update_yaxes(autorange=\"reversed\")\n\n    fig.show()\n\n\ndef get_phrase(df, file_id, sequence_id):\n    return df[\n        np.logical_and(\n            df.file_id == file_id, \n            df.sequence_id == sequence_id\n        )\n    ].phrase.iloc[0]","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:52:05.71367Z","iopub.execute_input":"2023-05-11T19:52:05.714058Z","iopub.status.idle":"2023-05-11T19:52:05.752687Z","shell.execute_reply.started":"2023-05-11T19:52:05.714027Z","shell.execute_reply":"2023-05-11T19:52:05.751602Z"},"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"1\"></a>\n# <div style=\"box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px inset, rgb(51, 51, 51) 0px 0px 0px 3px inset; padding:20px; font-size:32px; font-family: consolas; text-align:center; display:fill; border-radius:15px;  color:rgb(34, 34, 34);\"> <b> 1. Data overview</b></div>","metadata":{}},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ The goal of this competition is to detect and translate American Sign Language (ASL) fingerspelling into text.</p> \n\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <code><b>[train/supplemental_metadata].csv</b></code></p>\n\n* <p style=\"font-family: consolas; font-size: 16px;\"><code>path</code> - The path to the landmark file.</p>\n* <p style=\"font-family: consolas; font-size: 16px;\"><code>file_id</code> - A unique identifier for the data file.</p>\n* <p style=\"font-family: consolas; font-size: 16px;\"><code>sequence_id</code> - A unique identifier for the landmark sequence. Each data file may contain many sequences.</p>\n* <p style=\"font-family: consolas; font-size: 16px;\"><code>phrase</code> - The labels for the landmark sequence. The train and test datasets contain randomly generated addresses, phone numbers, and urls derived from components of real addresses/phone numbers/urls. Any overlap with real addresses, phone numbers, or urls is purely accidental. The supplemental dataset consists of fingerspelled sentences. Note that some of the urls include adult content. The intent of this competition is to support the Deaf and Hard of Hearing community in engaging with technology on an equal footing with other adults.</p>","metadata":{}},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ <code><b>[train/supplemental]_landmarks/</b></code> - the landmark data. The landmarks were extracted from raw videos with the <a href=\"https://github.com/google/mediapipe/blob/master/docs/solutions/holistic.md\"><strong>MediaPipe holistic model</strong></a>. Not all of the frames necessarily had visible hands or hands that could be detected by the model.</p>\n\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ The landmark files contain the same data as in the ASL Signs competition (minus the row ID column) but reshaped into a wide format. This allows you to take advantage of the Parquet format to entirely skip loading landmarks that you aren't using.</p>\n\n* <p style=\"font-family: consolas; font-size: 16px;\"><code>sequence_id</code> - A unique identifier for the landmark sequence. Most landmark files contain 1,000 sequences. The sequence ID is used as the dataframe index.</p>\n* <p style=\"font-family: consolas; font-size: 16px;\"><code>frame</code> - The frame number within a landmark sequence.</p>\n* <p style=\"font-family: consolas; font-size: 16px;\"><code>sequence_id</code> - A unique identifier for the landmark sequence. Each data file may contain many sequences.</p>\n* <p style=\"font-family: consolas; font-size: 16px;\"><code>[x/y/z]_[type]_[landmark_index]</code> - There are now 1,629 spatial coordinate columns for the x, y and z coordinates for each of the 543 landmarks. The type of landmark is one of ['face', 'left_hand', 'pose', 'right_hand'].</p>","metadata":{}},{"cell_type":"markdown","source":"<a id=\"1.1\"></a>\n## <div style=\"box-shadow: rgba(0, 0, 0, 0.18) 0px 2px 4px inset; padding:20px; font-size:24px; font-family: consolas; text-align:center; display:fill; border-radius:15px; color:rgb(67, 66, 66)\"> <b> 1.1 American sign language (ASL)</b></div>","metadata":{}},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>ASL Basics</b>: American Sign Language (ASL) is a complete, natural language that has the same linguistic properties as spoken languages, with grammar that differs from English.</p>\n\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>Sign Language in Different Countries</b>: There is no universal sign language. Different sign languages are used in different countries or regions. Some countries adopt features of ASL in their sign languages.</p>\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>Origins of ASL</b>: No person or committee invented ASL. The exact beginnings of ASL are not clear, but some suggest that it arose more than 200 years ago from the intermixing of local sign languages and French Sign Language (LSF, or Langue des Signes Française).</p>\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>ASL Compared to Spoken Language</b>: ASL is a language completely separate and distinct from English. It contains all the fundamental features of language, with its own rules for pronunciation, word formation, and word order. Fingerspelling is part of ASL and is used to spell out English words.</p>\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>Neurobiology of Language Development</b>: Study of sign language can also help scientists understand the neurobiology of language development. Better understanding of the neurobiology of language could provide a translational foundation for treating injury to the language system, for employing signs or gestures in therapy for children or adults, and for diagnosing language impairment in individuals who are deaf.</p>\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>Sign Languages Created Among Small Communities</b>: The NIDCD is also funding research on sign languages created among small communities of people with little to no outside influence.</p>\n\n<p style=\"text-align:center;\"><img src=\"https://d.newsweek.com/en/full/1394686/asl-getty-images.webp?w=1400&f=6685541ca5a5e35b027f9bc9957d27c9\" width=\"90%\" height=\"90%\"></p>\n\n<p style=\"text-align:center; font-family: consolas; font-size: 16px;\"><i>ASL finger alphabet</i></p>","metadata":{}},{"cell_type":"markdown","source":"<a id=\"1.2\"></a>\n## <div style=\"box-shadow: rgba(0, 0, 0, 0.18) 0px 2px 4px inset; padding:20px; font-size:24px; font-family: consolas; text-align:center; display:fill; border-radius:15px; color:rgb(67, 66, 66)\"> <b> 1.2 MediaPipe holistic model</b></div>","metadata":{}},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ MediaPipe Holistic Solution is a powerful, easy-to-use software tool that can detect and track multiple human body parts and gestures in real-time video streams. It is open-source and can run on a variety of platforms, including mobile devices, making it an ideal solution for our competition.</p>\n\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>Real-time Perception:</b> Real-time, simultaneous perception of human pose, face landmarks, and hand tracking can enable impactful applications like fitness analysis, gesture control, and sign language recognition.</p>\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>Open-Source Framework:</b> MediaPipe is an open-source framework designed for complex perception pipelines.</p>\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>State-of-the-Art Solution:</b> MediaPipe Holistic is a solution that provides a state-of-the-art human pose topology, consisting of optimized pose, face, and hand components that each run in real-time.</p>\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>Unified Topology:</b> MediaPipe Holistic provides a unified topology for 540+ keypoints and is available on-device for mobile and desktop.</p>\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>Separate ML Models For Separate Tasks:</b> The pipeline integrates separate models for pose, face, and hand components, treating the different regions using a region-appropriate image resolution.</p>\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>Significant Model Coordination:</b> MediaPipe Holistic requires coordination between up to 8 models per frame and optimized machine learning models and pre- and post-processing algorithms for performance benefits.</p>\n<p style=\"font-family: consolas; font-size: 16px;\">⚪ <b>Performance Benefits:</b> The multi-stage nature of the pipeline provides performance benefits, as models are mostly independent and can be replaced with lighter or heavier versions.</p>\n\n\n<p style=\"text-align:center;\"><img src=\"https://mediapipe.dev/images/mobile/holistic_sports_and_gestures_example.gif\" width=\"90%\" height=\"90%\"></p>\n\n<p style=\"text-align:center; font-family: consolas; font-size: 16px;\"><i><a href=\"https://google.github.io/mediapipe/solutions/holistic.html\">Example of MediaPipe Holistic</a></i></p>\n\n\n<p style=\"text-align:center;\"><img src=\"https://mediapipe.dev/images/mobile/hand_landmarks.png\" width=\"90%\" height=\"90%\"></p>\n\n<p style=\"text-align:center; font-family: consolas; font-size: 16px;\"><i><a href=\"https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.googblogs.com%2Ftag%2Fmediapipe%2F&psig=AOvVaw10h_IFlBkmFPiHLUrQl-Eu&ust=1677514368952000&source=images&cd=vfe&ved=0CBAQjRxqFwoTCOjdt5LKs_0CFQAAAAAdAAAAABAJ\">MediaPipe Landmarks for Hands</a></i></p>","metadata":{}},{"cell_type":"markdown","source":"<a id=\"2\"></a>\n# <div style=\"box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px inset, rgb(51, 51, 51) 0px 0px 0px 3px inset; padding:20px; font-size:32px; font-family: consolas; text-align:center; display:fill; border-radius:15px;  color:rgb(34, 34, 34);\"> <b> 2. Train overview</b></div>","metadata":{}},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ First load train.csv file.</p>","metadata":{}},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/asl-fingerspelling/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:52:19.725876Z","iopub.execute_input":"2023-05-11T19:52:19.726444Z","iopub.status.idle":"2023-05-11T19:52:19.950369Z","shell.execute_reply.started":"2023-05-11T19:52:19.726398Z","shell.execute_reply":"2023-05-11T19:52:19.949243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ Let's look how the data looks like.</p>","metadata":{}},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:52:21.006533Z","iopub.execute_input":"2023-05-11T19:52:21.007232Z","iopub.status.idle":"2023-05-11T19:52:21.039427Z","shell.execute_reply.started":"2023-05-11T19:52:21.007183Z","shell.execute_reply":"2023-05-11T19:52:21.038262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ Show a discribe of the dataframe with its basic information.</p>","metadata":{}},{"cell_type":"code","source":"train_df.describe()","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:52:21.439851Z","iopub.execute_input":"2023-05-11T19:52:21.44025Z","iopub.status.idle":"2023-05-11T19:52:21.476693Z","shell.execute_reply.started":"2023-05-11T19:52:21.440197Z","shell.execute_reply":"2023-05-11T19:52:21.475617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">🔴 Let's try to visualize sequence <code>1816796431</code> from the file <code>5414471</code>.</p>","metadata":{}},{"cell_type":"code","source":"sequence_id = 1816796431\nfile_id = 5414471","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:52:21.919439Z","iopub.execute_input":"2023-05-11T19:52:21.919829Z","iopub.status.idle":"2023-05-11T19:52:21.924616Z","shell.execute_reply.started":"2023-05-11T19:52:21.919797Z","shell.execute_reply":"2023-05-11T19:52:21.923509Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path_to_sign = f\"/kaggle/input/asl-fingerspelling/train_landmarks/{file_id}.parquet\"\nsign = pd.read_parquet(path_to_sign)","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:52:22.366203Z","iopub.execute_input":"2023-05-11T19:52:22.366929Z","iopub.status.idle":"2023-05-11T19:52:37.566934Z","shell.execute_reply.started":"2023-05-11T19:52:22.366885Z","shell.execute_reply":"2023-05-11T19:52:37.565722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ Here is what is inside this parquet file:</p>","metadata":{}},{"cell_type":"code","source":"sign","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:52:37.570916Z","iopub.execute_input":"2023-05-11T19:52:37.571563Z","iopub.status.idle":"2023-05-11T19:52:37.634254Z","shell.execute_reply.started":"2023-05-11T19:52:37.571522Z","shell.execute_reply":"2023-05-11T19:52:37.633255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ The number of unique sequences in an <code>.parquet</code> file is <b>1000</b>.</p>","metadata":{}},{"cell_type":"code","source":"len(np.unique(sign.index))","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:52:37.635444Z","iopub.execute_input":"2023-05-11T19:52:37.635758Z","iopub.status.idle":"2023-05-11T19:52:37.644582Z","shell.execute_reply.started":"2023-05-11T19:52:37.635732Z","shell.execute_reply":"2023-05-11T19:52:37.643451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ Let's get only sequence <code>1816796431</code> from the file.</p>","metadata":{}},{"cell_type":"code","source":"sequence = sign[sign.index == sequence_id]\nsequence","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:52:37.64665Z","iopub.execute_input":"2023-05-11T19:52:37.646953Z","iopub.status.idle":"2023-05-11T19:52:37.684809Z","shell.execute_reply.started":"2023-05-11T19:52:37.646926Z","shell.execute_reply":"2023-05-11T19:52:37.683526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">🔴 Now we can visualize the sequence and the phrase.</p>","metadata":{}},{"cell_type":"code","source":"sequence_phrase = get_phrase(train_df, file_id, sequence_id)\nvisualise2d_landmarks(sequence, f\"Phrase: {sequence_phrase}\")","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:52:37.686142Z","iopub.execute_input":"2023-05-11T19:52:37.68651Z","iopub.status.idle":"2023-05-11T19:52:57.488848Z","shell.execute_reply.started":"2023-05-11T19:52:37.686481Z","shell.execute_reply":"2023-05-11T19:52:57.487313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#TODO: Plot NaN distributions for some features","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#TODO: Text length distribution","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#TODO: Text lenght distribution","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#TODO: Create participant_id distribution","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#TODO: Frames distribution","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<a id=\"3\"></a>\n# <div style=\"box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px inset, rgb(51, 51, 51) 0px 0px 0px 3px inset; padding:20px; font-size:32px; font-family: consolas; text-align:center; display:fill; border-radius:15px;  color:rgb(34, 34, 34);\"> <b>3. Supplemental overview</b></div>","metadata":{}},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ First load supplemental_metadata.csv file.</p>","metadata":{}},{"cell_type":"code","source":"supplemental_df = pd.read_csv(\"/kaggle/input/asl-fingerspelling/supplemental_metadata.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:53:04.474945Z","iopub.execute_input":"2023-05-11T19:53:04.475336Z","iopub.status.idle":"2023-05-11T19:53:04.600017Z","shell.execute_reply.started":"2023-05-11T19:53:04.475305Z","shell.execute_reply":"2023-05-11T19:53:04.599195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ Let's look how the data looks like.</p>","metadata":{}},{"cell_type":"code","source":"supplemental_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:53:06.22052Z","iopub.execute_input":"2023-05-11T19:53:06.221492Z","iopub.status.idle":"2023-05-11T19:53:06.233108Z","shell.execute_reply.started":"2023-05-11T19:53:06.221411Z","shell.execute_reply":"2023-05-11T19:53:06.231998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ Show a discribe of the dataframe with its basic information.</p>","metadata":{}},{"cell_type":"code","source":"supplemental_df.describe()","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:53:06.692784Z","iopub.execute_input":"2023-05-11T19:53:06.693641Z","iopub.status.idle":"2023-05-11T19:53:06.717898Z","shell.execute_reply.started":"2023-05-11T19:53:06.693595Z","shell.execute_reply":"2023-05-11T19:53:06.716737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">🔴 Let's try to visualize sequence <code>1535467051</code> from the file <code>33432165</code>.</p>","metadata":{}},{"cell_type":"code","source":"sequence_id = 1535467051\nfile_id = 33432165","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:53:08.533009Z","iopub.execute_input":"2023-05-11T19:53:08.534121Z","iopub.status.idle":"2023-05-11T19:53:08.539179Z","shell.execute_reply.started":"2023-05-11T19:53:08.534075Z","shell.execute_reply":"2023-05-11T19:53:08.538161Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path_to_sign = f\"/kaggle/input/asl-fingerspelling/supplemental_landmarks/{file_id}.parquet\"\nsign = pd.read_parquet(path_to_sign)","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:53:08.779767Z","iopub.execute_input":"2023-05-11T19:53:08.780152Z","iopub.status.idle":"2023-05-11T19:53:26.810753Z","shell.execute_reply.started":"2023-05-11T19:53:08.780109Z","shell.execute_reply":"2023-05-11T19:53:26.809829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ Here is what is inside this parquet file:</p>","metadata":{}},{"cell_type":"code","source":"sign","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:53:26.81328Z","iopub.execute_input":"2023-05-11T19:53:26.81373Z","iopub.status.idle":"2023-05-11T19:53:26.867055Z","shell.execute_reply.started":"2023-05-11T19:53:26.813688Z","shell.execute_reply":"2023-05-11T19:53:26.86577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ The number of unique sequences in an <code>.parquet</code> file is <b>1000</b>.</p>","metadata":{}},{"cell_type":"code","source":"len(np.unique(sign.index))","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:53:26.868891Z","iopub.execute_input":"2023-05-11T19:53:26.869409Z","iopub.status.idle":"2023-05-11T19:53:26.878742Z","shell.execute_reply.started":"2023-05-11T19:53:26.869379Z","shell.execute_reply":"2023-05-11T19:53:26.877635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">⚪ Let's get only sequence <code>1535467051</code> from the file.</p>","metadata":{}},{"cell_type":"code","source":"sequence = sign[sign.index == sequence_id]\nsequence","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:53:26.881474Z","iopub.execute_input":"2023-05-11T19:53:26.881949Z","iopub.status.idle":"2023-05-11T19:53:26.917047Z","shell.execute_reply.started":"2023-05-11T19:53:26.881911Z","shell.execute_reply":"2023-05-11T19:53:26.915922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<p style=\"font-family: consolas; font-size: 16px;\">🔴 Now we can visualize and sequence with the phrase.</p>","metadata":{}},{"cell_type":"code","source":"sequence_phrase = get_phrase(supplemental_df, file_id, sequence_id)\nvisualise2d_landmarks(sequence, f\"Phrase: {sequence_phrase}\")","metadata":{"execution":{"iopub.status.busy":"2023-05-11T19:53:26.918353Z","iopub.execute_input":"2023-05-11T19:53:26.918675Z","iopub.status.idle":"2023-05-11T19:53:50.377997Z","shell.execute_reply.started":"2023-05-11T19:53:26.918648Z","shell.execute_reply":"2023-05-11T19:53:50.377147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# (⁠ ⁠ꈍ⁠ᴗ⁠ꈍ⁠) WORK STILL IN PROGRESS","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# <div style=\"box-shadow: rgba(240, 46, 170, 0.4) -5px 5px inset, rgba(240, 46, 170, 0.3) -10px 10px inset, rgba(240, 46, 170, 0.2) -15px 15px inset, rgba(240, 46, 170, 0.1) -20px 20px inset, rgba(240, 46, 170, 0.05) -25px 25px inset; padding:20px; font-size:30px; font-family: consolas; display:fill; border-radius:15px; color: rgba(240, 46, 170, 0.7)\"> <b> ༼⁠ ⁠つ⁠ ⁠◕⁠‿⁠◕⁠ ⁠༽⁠つ Thank You!</b></div>\n\n<p style=\"font-family:verdana; color:rgb(34, 34, 34); font-family: consolas; font-size: 16px;\"> 💌 Thank you for taking the time to read through my notebook. I hope you found it interesting and informative. If you have any feedback or suggestions for improvement, please don't hesitate to let me know in the comments. <br><br> 🚀 If you liked this notebook, please consider upvoting it so that others can discover it too. Your support means a lot to me, and it helps to motivate me to create more content in the future. <br><br> ❤️ Once again, thank you for your support, and I hope to see you again soon!</p>","metadata":{}}]}