├── .gitignore ├── LICENSE ├── README.md ├── ground_truth_gen ├── polished_rl_training_data.csv └── r1_distill_reasoning_graph_extraction.ipynb └── train └── Qwen_GRPO_Graph_Extraction.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | .ipynb_checkpoints/* 4 | .ipynb_checkpoints 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Qwen GRPO Graph Extraction RL Finetune 2 | 3 | We initially explored GRPO based on the Reasoning model synthetic CoT Graph Extraction data, with LLM involved in the reward function. 4 | 5 | ```bash 6 | . 7 | ├── LICENSE 8 | ├── ground_truth_gen # data gen via DeepSeek R1 9 | │   ├── polished_rl_training_data.csv 10 | │   └── r1_distill_reasoning_graph_extraction.ipynb 11 | └── train 12 | └── Qwen_GRPO_Graph_Extraction.ipynb # training process 13 | ``` 14 | 15 | > update: Seems the training notebook doesnt render properly in github, check from colab instead: 16 | 17 | | Data Gen | Training | 18 | | ------------------------------------------------------------ | ------------------------------------------------------------ | 19 | | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/wey-gu/gpro-graph-extraction/blob/main/ground_truth_gen/r1_distill_reasoning_graph_extraction.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/wey-gu/gpro-graph-extraction/blob/main/train/Qwen_GRPO_Graph_Extraction.ipynb) | 20 | 21 | 22 | ### Credits 23 | 24 | - DeepSeek-Math and DeepSeek R1's work and DeepSeek R1 Model 25 | - https://arxiv.org/html/2501.12948 26 | - https://arxiv.org/html/2402.03300 27 | - Qwen's Great [Base model](https://huggingface.co/Qwen/Qwen2.5-3B) 28 | - [Will's](https://x.com/willccbb), [this](https://colab.research.google.com/drive/1bfhs1FMLW3FGa8ydvkOZyBNxLYOu0Hev?usp=sharing)(cannot find the author), and Unsloth's [Daniel Han Chen](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen2.5_(3B)-GRPO.ipynb#scrollTo=SDKIhhvN6lAF) work 29 | 30 | training 31 | -------------------------------------------------------------------------------- /ground_truth_gen/r1_distill_reasoning_graph_extraction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "8a1cfd27-c14e-4385-b294-db50feb8d79b", 6 | "metadata": {}, 7 | "source": [ 8 | "## Data Gen" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 29, 14 | "id": "f80677de-fa0b-4b3a-9d0a-6f959f1dbf5c", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "data": { 19 | "text/plain": [ 20 | "True" 21 | ] 22 | }, 23 | "execution_count": 29, 24 | "metadata": {}, 25 | "output_type": "execute_result" 26 | } 27 | ], 28 | "source": [ 29 | "import os\n", 30 | "from dotenv import load_dotenv\n", 31 | "\n", 32 | "# Load environment variables from .env file\n", 33 | "load_dotenv()" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 30, 39 | "id": "bd20f9af-3724-47fc-aba6-5e12cc8d50ae", 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "The number of major languages in the world is not fixed and depends on the criteria used (e.g., speaker count, regional influence, official status). However, common estimates suggest:\n", 47 | "\n", 48 | "1. **Top 20–30 Languages**: Often identified by **native/total speakers** (e.g., Ethnologue lists **23 languages** with over 50 million native speakers). \n", 49 | " Examples: Mandarin Chinese, Spanish, English, Hindi, Arabic, Bengali, Portuguese, Russian, Japanese, French, German, Swahili, etc.\n", 50 | "\n", 51 | "2. **UN Official Languages**: 6 languages (Arabic, Chinese, English, French, Russian, Spanish) are designated for global diplomacy.\n", 52 | "\n", 53 | "3. **Regional Significance**: Languages like Swahili (Africa) or Indonesian (Southeast Asia) are major in specific regions, even with fewer global speakers.\n", 54 | "\n", 55 | "4. **Total Speakers**: Including second-language users, languages like English (~1.5 billion total speakers) and French (~300 million) rank highly.\n", 56 | "\n", 57 | "**Key Factors**: \n", 58 | "- **Native speakers**: Mandarin Chinese leads with ~1 billion. \n", 59 | "- **Global influence**: English dominates in international business/science. \n", 60 | "- **Lingua franca**: Arabic, Hindi-Urdu, or Malay/Indonesian serve large, diverse populations.\n", 61 | "\n", 62 | "**Conclusion**: While definitions vary, **20–30 languages** are typically considered \"major\" based on speaker numbers, geographic spread, and sociopolitical impact. Over 200 languages have ≥1 million speakers, but \"major\" usually refers to those with broader global or regional significance.\n", 63 | "\n", 64 | "\n", 65 | "Okay, so the user is asking about how many major languages there are in the world. Hmm, let's think about this. First, I need to clarify what counts as a \"major\" language. There's no strict definition, but usually, people consider factors like the number of native speakers, the number of total speakers, the geographical distribution, and the language's influence in international contexts like business, politics, or culture.\n", 66 | "\n", 67 | "Alright, so maybe start by looking at the number of speakers. Languages like Mandarin Chinese, Spanish, English, Hindi, Arabic, and others come to mind because they have hundreds of millions of speakers. But wait, some sources may categorize some languages differently. For example, Arabic has many dialects, some of which are mutually unintelligible, so should they be considered separate languages or dialects under the Arabic umbrella? That could affect the count.\n", 68 | "\n", 69 | "Also, there's the question of second-language speakers. English, for instance, is widely spoken as a second language around the world, so its total number of speakers is huge. Similarly, French is an official language in many countries, especially in Africa, so even if native speakers aren't the majority, the total number including second-language speakers could be substantial. \n", 70 | "\n", 71 | "Then there are languages that are significant in specific regions. Swahili in East Africa, for example, is a lingua franca for many countries there. Similarly, Indonesian (Bahasa Indonesia) is widely spoken in Indonesia, a country with a large population. So even though their global speaker count might not be as high as Mandarin or English, their regional importance makes them major in their areas.\n", 72 | "\n", 73 | "Another angle is official status. The United Nations has six official languages: Arabic, Chinese, English, French, Russian, and Spanish. Those are definitely major by that measure. But does that cover all major languages? Probably not, because there are languages with more speakers than some of these. For example, Hindi has a lot more speakers than French, but it's not a UN official language. But Hindi is mostly concentrated in India, whereas French is official in many countries. So maybe political and international influence plays a role here.\n", 74 | "\n", 75 | "I should also think about linguistic diversity. Ethnologue, which is a well-known resource on languages, lists about 7,000 living languages. But the vast majority of these have very few speakers. So when we talk about \"major\" languages, we're probably focusing on those with at least millions of speakers. The cutoff might be arbitrary. Some sources might list the top 20 or 30 languages by speaker numbers. \n", 76 | "\n", 77 | "Wait, let me recall some numbers. Mandarin Chinese has around 1 billion native speakers. Spanish and English each have hundreds of millions. Then Hindi, Bengali, Portuguese, Russian, Japanese, etc. Maybe around 20 languages have over 50 million speakers. Then there are others with fewer speakers but significant regional importance. So if someone is asking about major languages, maybe around 20 to 30 would be a reasonable estimate. But again, it depends on the criteria.\n", 78 | "\n", 79 | "Alternatively, sometimes people refer to major languages as those that have a certain level of institutional support, like being used in education, government, and media. In that case, even languages with fewer speakers but official status in a country could be considered major. However, the user's question is about the world as a whole, so perhaps focusing on languages with a large number of speakers and global influence.\n", 80 | "\n", 81 | "I need to check if there's a commonly accepted number. I remember reading that there are about 200 languages with over a million speakers. But that would be more than \"major\". The user probably doesn't need the full list but a concise answer. So maybe condensing to a range based on common definitions. For example, between 20 to 30 languages are considered major based on their speaker numbers and global influence. Often cited are the top 10, 20, or 23 (like the number with more than 50 million speakers according to Ethnologue). \n", 82 | "\n", 83 | "Wait, let me think. According to Ethnologue's 2023 data, there are about 23 languages with at least 50 million native speakers, and if we include second-language speakers, the number of total speakers would be higher. But some languages might have fewer native speakers but more total speakers. So depending on whether we count native or total, the list changes. English, for example, has around 375 million native speakers but over a billion total speakers. Similarly, French has about 80 million native but over 200 million total. \n", 84 | "\n", 85 | "So if the criteria is total speakers, English is number one, then Mandarin because of the native speakers, even though second-language isn't as high. Then Hindi, Spanish, etc. Maybe there are around 20-25 languages that surpass a certain threshold, like 100 million speakers total. But again, the exact number might vary. \n", 86 | "\n", 87 | "I should also consider writing systems and standardization. Some languages might be widely spoken but not have a standardized written form, which might affect their classification as major. But perhaps that's too technical for the general answer the user might be seeking. \n", 88 | "\n", 89 | "Another factor is whether the language is a lingua franca. For example, Swahili in East Africa, Urdu in Pakistan and parts of India, Indonesian in Southeast Asia. These might not have the highest speaker numbers globally but are crucial in their regions, making them major in a regional context. However, the user's question is about the world, so maybe regional major languages add to the count but aren't the main focus. \n", 90 | "\n", 91 | "So synthesizing all this, the answer probably needs to state that while the exact number depends on criteria, typically around 20 to 30 languages are considered major based on factors like number of speakers, global influence, and official status. Also mention that estimates often range between 20 and 30, sometimes mentioning specific numbers like 23 (from Ethnologue's 50+ million native speakers) or up to 200 if considering a million speakers as the threshold. But the key is to clarify that \"major\" is subjective. \n", 92 | "\n", 93 | "So in the answer, first explain that there's no exact number, then provide the common estimates based on speaker count, mention the UN languages perhaps, note the difference between native and total speakers, and maybe list some examples. Make sure to convey that depending on the criteria, the number can vary, but the common answer is around 20-30.\n", 94 | "\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "from openai import OpenAI\n", 100 | "\n", 101 | "client = OpenAI(\n", 102 | " base_url=\"https://openrouter.ai/api/v1\",\n", 103 | " api_key=os.getenv(\"OPENROUTER_API_KEY\"),\n", 104 | ")\n", 105 | "\n", 106 | "completion = client.chat.completions.create(\n", 107 | " extra_body={\n", 108 | " \"include_reasoning\": True\n", 109 | " },\n", 110 | " model=\"deepseek/deepseek-r1\",\n", 111 | " messages=[\n", 112 | " {\n", 113 | " \"role\": \"user\",\n", 114 | " \"content\": \"How many major languages are in the world?\"\n", 115 | " }\n", 116 | " ],\n", 117 | ")\n", 118 | "print(completion.choices[0].message.content)\n", 119 | "print(\"\")\n", 120 | "print(completion.choices[0].message.model_extra.get(\"reasoning\"))" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 18, 126 | "id": "27bb4bd3-45f7-43b7-8e34-87346890f14c", 127 | "metadata": {}, 128 | "outputs": [], 129 | "source": [ 130 | "import os\n", 131 | "import re\n", 132 | "import json\n", 133 | "#import openai\n", 134 | "import pandas as pd\n", 135 | "import tiktoken\n", 136 | "\n", 137 | "# ---------------------------\n", 138 | "# Configuration & API Setup\n", 139 | "# ---------------------------\n", 140 | "\n", 141 | "# Set your API key (if using OpenAI’s client for deepseek/deepseek-r1)\n", 142 | "#openai.api_key = \"YOUR_API_KEY\"\n", 143 | "\n", 144 | "# Choose the encoding – here we use a model’s encoding (adjust if needed)\n", 145 | "encoding = tiktoken.encoding_for_model(\"gpt-3.5-turbo\") # or any model you prefer\n", 146 | "\n", 147 | "# Maximum token limit per chunk and overlap tokens for sliding window\n", 148 | "MAX_TOKENS = 1500\n", 149 | "OVERLAP_TOKENS = 150\n", 150 | "\n", 151 | "# ---------------------------\n", 152 | "# Helper Functions\n", 153 | "# ---------------------------\n", 154 | "\n", 155 | "def count_tokens(text: str) -> int:\n", 156 | " \"\"\"Count the tokens in text using tiktoken.\"\"\"\n", 157 | " return len(encoding.encode(text))\n", 158 | "\n", 159 | "def split_text_sliding_window(text: str, max_tokens: int = MAX_TOKENS, overlap: int = OVERLAP_TOKENS) -> list:\n", 160 | " \"\"\"\n", 161 | " Splits text into multiple overlapping chunks if it exceeds max_tokens.\n", 162 | " Returns a list of text chunks.\n", 163 | " \"\"\"\n", 164 | " tokens = encoding.encode(text)\n", 165 | " total = len(tokens)\n", 166 | " chunks = []\n", 167 | " start = 0\n", 168 | " while start < total:\n", 169 | " end = min(start + max_tokens, total)\n", 170 | " chunk_tokens = tokens[start:end]\n", 171 | " chunk_text = encoding.decode(chunk_tokens)\n", 172 | " chunks.append(chunk_text)\n", 173 | " if end == total:\n", 174 | " break\n", 175 | " start = end - overlap # slide the window with overlap\n", 176 | " return chunks\n", 177 | "\n", 178 | "def split_markdown_file(filepath: str, max_tokens: int = MAX_TOKENS, overlap: int = OVERLAP_TOKENS) -> dict:\n", 179 | " \"\"\"\n", 180 | " Reads a markdown file and splits it into chunks.\n", 181 | " It uses all markdown headings (levels 1-6) as split points.\n", 182 | " Also, it extracts the article head (text before the first heading).\n", 183 | " If a section exceeds max_tokens, it is further split via a sliding window.\n", 184 | " Returns a dict with keys:\n", 185 | " - 'head': overall article text (used as summary)\n", 186 | " - 'chunks': a list of dicts with keys 'heading' and 'chunk_text'\n", 187 | " \"\"\"\n", 188 | " with open(filepath, \"r\", encoding=\"utf-8\") as f:\n", 189 | " content = f.read()\n", 190 | "\n", 191 | " # Pattern for markdown headings (levels 1 to 6)\n", 192 | " heading_regex = re.compile(r\"^(#{1,6}\\s+.*)$\", re.MULTILINE)\n", 193 | " matches = list(heading_regex.finditer(content))\n", 194 | " \n", 195 | " # The article head is text before the first heading (if any)\n", 196 | " if matches:\n", 197 | " first_header_start = matches[0].start()\n", 198 | " article_head = content[:first_header_start].strip()\n", 199 | " else:\n", 200 | " article_head = content.strip()\n", 201 | " \n", 202 | " # Now, split the document into sections based on the heading positions.\n", 203 | " sections = []\n", 204 | " # If there is initial text (head) without a heading, treat it as one section.\n", 205 | " if article_head:\n", 206 | " sections.append({\"heading\": \"Article Head\", \"text\": article_head})\n", 207 | " \n", 208 | " for i, match in enumerate(matches):\n", 209 | " heading = match.group().strip()\n", 210 | " start = match.end()\n", 211 | " end = matches[i+1].start() if i+1 < len(matches) else len(content)\n", 212 | " section_text = content[start:end].strip()\n", 213 | " # Prepend the header line to the section text if desired\n", 214 | " full_text = f\"{heading}\\n\\n{section_text}\"\n", 215 | " sections.append({\"heading\": heading, \"text\": full_text})\n", 216 | " \n", 217 | " # Now, for each section, if its token count exceeds max_tokens, further split it via sliding window.\n", 218 | " chunks = []\n", 219 | " for section in sections:\n", 220 | " section_text = section[\"text\"]\n", 221 | " token_count = count_tokens(section_text)\n", 222 | " if token_count > max_tokens:\n", 223 | " subchunks = split_text_sliding_window(section_text, max_tokens, overlap)\n", 224 | " # Each subchunk inherits the section heading\n", 225 | " for sub in subchunks:\n", 226 | " chunks.append({\"heading\": section[\"heading\"], \"chunk_text\": sub})\n", 227 | " else:\n", 228 | " chunks.append({\"heading\": section[\"heading\"], \"chunk_text\": section_text})\n", 229 | " \n", 230 | " # For the overall article summary, we use the article head.\n", 231 | " return {\"head\": article_head, \"chunks\": chunks}\n", 232 | "\n", 233 | "# ---------------------------\n", 234 | "# (Optional) Summarization Function\n", 235 | "# ---------------------------\n", 236 | "def summarize_article_head(article_head: str) -> str:\n", 237 | " \"\"\"\n", 238 | " Generate an overall summary for the article.\n", 239 | " In this example, we simply use the first 100 tokens (or a similar heuristic).\n", 240 | " In practice, you might call an LLM summarizer.\n", 241 | " \"\"\"\n", 242 | " tokens = encoding.encode(article_head)\n", 243 | " summary_tokens = tokens[:min(100, len(tokens))]\n", 244 | " summary = encoding.decode(summary_tokens)\n", 245 | " return summary\n", 246 | "\n", 247 | "# ---------------------------\n", 248 | "# (2) Prepare Prompt and Call DeepSeek R1\n", 249 | "# ---------------------------\n", 250 | "def prepare_prompt(article_summary: str, chunk_text: str) -> str:\n", 251 | " \"\"\"\n", 252 | " Prepares the prompt for DeepSeek R1.\n", 253 | " The prompt includes:\n", 254 | " - Overall Article Summary (from the article head)\n", 255 | " - The current chunk's text\n", 256 | " - Extraction instructions\n", 257 | " \"\"\"\n", 258 | " prompt = (\n", 259 | " \"Article Summary:\\n\" + article_summary + \"\\n\\n\" +\n", 260 | " \"Chunk Text:\\n\" + chunk_text + \"\\n\\n\" +\n", 261 | " \"Instructions: Analyze the above text, explain your reasoning inside tags, \"\n", 262 | " \"and output a structured knowledge graph in JSON format inside tags. \"\n", 263 | " \"The JSON should have two keys: 'nodes' and 'edges'. For example:\\n\"\n", 264 | " '{\"nodes\": [{\"id\": 1, \"label\": \"EntityName\", \"type\": \"EntityType\"}, ...],\\n'\n", 265 | " '\"edges\": [{\"source\": 1, \"target\": 2, \"relation\": \"RELATION_TYPE\"}, ...]}\\n'\n", 266 | " \"Ensure your output strictly follows this format.\"\n", 267 | " )\n", 268 | " return prompt\n", 269 | "\n", 270 | "def call_deepseek(prompt: str):\n", 271 | " \"\"\"\n", 272 | " Calls the deepseek/deepseek-r1 model using the OpenAI chat completions interface.\n", 273 | " Returns the raw output.\n", 274 | " \"\"\"\n", 275 | " try:\n", 276 | " completion = client.chat.completions.create(\n", 277 | " extra_body={\n", 278 | " \"include_reasoning\": True\n", 279 | " },\n", 280 | " model=\"deepseek/deepseek-r1\",\n", 281 | " messages=[\n", 282 | " {\"role\": \"user\", \"content\": prompt}\n", 283 | " ]\n", 284 | " )\n", 285 | " output = completion.choices[0].message.content\n", 286 | " thinking_process = completion.choices[0].message.model_extra.get(\"reasoning\")\n", 287 | " e = \"\"\n", 288 | " except Exception as e:\n", 289 | " print(\"API call failed:\", e)\n", 290 | " output = \"\"\n", 291 | " thinking_process = \"\"\n", 292 | " return output, thinking_process, e\n", 293 | "\n", 294 | "# ---------------------------\n", 295 | "# (3) Persist Data in Tables\n", 296 | "# ---------------------------\n", 297 | "def persist_results(results: list, output_csv: str = \"rl_training_data.csv\"):\n", 298 | " \"\"\"\n", 299 | " Persists a list of results (each a dict) into a CSV file.\n", 300 | " \"\"\"\n", 301 | " df = pd.DataFrame(results)\n", 302 | " df.to_csv(output_csv, index=False)\n", 303 | " print(f\"Results saved to {output_csv}\")\n", 304 | "\n", 305 | "# ---------------------------\n", 306 | "# Main Script\n", 307 | "# ---------------------------\n", 308 | "def main():\n", 309 | " # Directory containing your Markdown files\n", 310 | " docs_dir = \"data_raw\"\n", 311 | " result_list = []\n", 312 | "\n", 313 | " for filename in os.listdir(docs_dir):\n", 314 | " if filename.endswith(\".md\"):\n", 315 | " filepath = os.path.join(docs_dir, filename)\n", 316 | " print(f\"Processing {filepath}...\")\n", 317 | " file_data = split_markdown_file(filepath, MAX_TOKENS, OVERLAP_TOKENS)\n", 318 | " # Use the article head from file_data as the overall summary\n", 319 | " article_head = file_data[\"head\"]\n", 320 | " if article_head:\n", 321 | " article_summary = summarize_article_head(article_head)\n", 322 | " else:\n", 323 | " article_summary = \"\"\n", 324 | " # Process each chunk\n", 325 | " for idx, chunk in enumerate(file_data[\"chunks\"]):\n", 326 | " chunk_text = chunk[\"chunk_text\"]\n", 327 | " # Build the prompt using the overall article summary and the current chunk text\n", 328 | " prompt = prepare_prompt(article_summary, chunk_text)\n", 329 | " # Call the DeepSeek R1 model\n", 330 | " api_output, thinking_process, error = call_deepseek(prompt)\n", 331 | " # Append the results with metadata to result_list\n", 332 | " result_list.append({\n", 333 | " \"file\": filename,\n", 334 | " \"chunk_index\": idx,\n", 335 | " \"heading\": chunk[\"heading\"],\n", 336 | " \"chunk_text\": chunk_text,\n", 337 | " \"article_summary\": article_summary,\n", 338 | " \"prompt\": prompt,\n", 339 | " \"api_output\": api_output,\n", 340 | " \"thinking_process\": thinking_process,\n", 341 | " \"error\": error,\n", 342 | " })\n", 343 | " \n", 344 | " # Persist the results to a CSV file\n", 345 | " persist_results(result_list)\n", 346 | "\n", 347 | "if __name__ == \"__main__\":\n", 348 | " # main()\n", 349 | " pass\n" 350 | ] 351 | }, 352 | { 353 | "cell_type": "code", 354 | "execution_count": 19, 355 | "id": "a6a28e74-91a9-4363-9682-837c70c42981", 356 | "metadata": {}, 357 | "outputs": [ 358 | { 359 | "name": "stdout", 360 | "output_type": "stream", 361 | "text": [ 362 | "Processing data_raw/2024_in_science.md...\n", 363 | "Processing data_raw/year-in-review-the-biggest-climate-headlines-of-2024.md...\n", 364 | "Processing data_raw/2024-wrapped-for-african-startups-a-year-of-growth-and-challenges.md...\n", 365 | "Processing data_raw/2024_in_spaceflight.md...\n", 366 | "Results saved to rl_training_data.csv\n" 367 | ] 368 | } 369 | ], 370 | "source": [ 371 | "main()" 372 | ] 373 | }, 374 | { 375 | "cell_type": "code", 376 | "execution_count": null, 377 | "id": "1e0d3290-1fed-422a-8781-238825b95a65", 378 | "metadata": { 379 | "jupyter": { 380 | "source_hidden": true 381 | } 382 | }, 383 | "outputs": [], 384 | "source": [ 385 | "# the parallel version, so you don't have to wait a long time if your r1 could handle batch calls\n", 386 | "\n", 387 | "# import os\n", 388 | "# import re\n", 389 | "# import json\n", 390 | "# import pandas as pd\n", 391 | "# import tiktoken\n", 392 | "# import concurrent.futures\n", 393 | "\n", 394 | "# # ---------------------------\n", 395 | "# # Configuration & API Setup\n", 396 | "# # ---------------------------\n", 397 | "\n", 398 | "# # Set your API key (if using OpenAI’s client for deepseek/deepseek-r1)\n", 399 | "# # For example, if using an openai-like client, you might set:\n", 400 | "# # openai.api_key = \"YOUR_API_KEY\"\n", 401 | "\n", 402 | "# # For this example, we assume a 'client' object is available.\n", 403 | "# # If you're using the OpenAI library, you might import it and set up accordingly.\n", 404 | "# # import openai\n", 405 | "\n", 406 | "# # Choose the encoding – here we use a model’s encoding (adjust if needed)\n", 407 | "# encoding = tiktoken.encoding_for_model(\"gpt-3.5-turbo\") # or any model you prefer\n", 408 | "\n", 409 | "# # Maximum token limit per chunk and overlap tokens for sliding window\n", 410 | "# MAX_TOKENS = 1500\n", 411 | "# OVERLAP_TOKENS = 150\n", 412 | "\n", 413 | "# # Batch size for concurrent API calls\n", 414 | "# BATCH_SIZE = 32\n", 415 | "\n", 416 | "# # ---------------------------\n", 417 | "# # Helper Functions\n", 418 | "# # ---------------------------\n", 419 | "# def count_tokens(text: str) -> int:\n", 420 | "# \"\"\"Count the tokens in text using tiktoken.\"\"\"\n", 421 | "# return len(encoding.encode(text))\n", 422 | "\n", 423 | "# def split_text_sliding_window(text: str, max_tokens: int = MAX_TOKENS, overlap: int = OVERLAP_TOKENS) -> list:\n", 424 | "# \"\"\"\n", 425 | "# Splits text into multiple overlapping chunks if it exceeds max_tokens.\n", 426 | "# Returns a list of text chunks.\n", 427 | "# \"\"\"\n", 428 | "# tokens = encoding.encode(text)\n", 429 | "# total = len(tokens)\n", 430 | "# chunks = []\n", 431 | "# start = 0\n", 432 | "# while start < total:\n", 433 | "# end = min(start + max_tokens, total)\n", 434 | "# chunk_tokens = tokens[start:end]\n", 435 | "# chunk_text = encoding.decode(chunk_tokens)\n", 436 | "# chunks.append(chunk_text)\n", 437 | "# if end == total:\n", 438 | "# break\n", 439 | "# start = end - overlap # slide the window with overlap\n", 440 | "# return chunks\n", 441 | "\n", 442 | "# def split_markdown_file(filepath: str, max_tokens: int = MAX_TOKENS, overlap: int = OVERLAP_TOKENS) -> dict:\n", 443 | "# \"\"\"\n", 444 | "# Reads a markdown file and splits it into chunks.\n", 445 | "# It uses all markdown headings (levels 1-6) as split points.\n", 446 | "# Also, it extracts the article head (text before the first heading).\n", 447 | "# If a section exceeds max_tokens, it is further split via a sliding window.\n", 448 | "# Returns a dict with keys:\n", 449 | "# - 'head': overall article text (used as summary)\n", 450 | "# - 'chunks': a list of dicts with keys 'heading' and 'chunk_text'\n", 451 | "# \"\"\"\n", 452 | "# with open(filepath, \"r\", encoding=\"utf-8\") as f:\n", 453 | "# content = f.read()\n", 454 | "\n", 455 | "# # Pattern for markdown headings (levels 1 to 6)\n", 456 | "# heading_regex = re.compile(r\"^(#{1,6}\\s+.*)$\", re.MULTILINE)\n", 457 | "# matches = list(heading_regex.finditer(content))\n", 458 | " \n", 459 | "# # The article head is text before the first heading (if any)\n", 460 | "# if matches:\n", 461 | "# first_header_start = matches[0].start()\n", 462 | "# article_head = content[:first_header_start].strip()\n", 463 | "# else:\n", 464 | "# article_head = content.strip()\n", 465 | " \n", 466 | "# # Now, split the document into sections based on the heading positions.\n", 467 | "# sections = []\n", 468 | "# # If there is initial text (head) without a heading, treat it as one section.\n", 469 | "# if article_head:\n", 470 | "# sections.append({\"heading\": \"Article Head\", \"text\": article_head})\n", 471 | " \n", 472 | "# for i, match in enumerate(matches):\n", 473 | "# heading = match.group().strip()\n", 474 | "# start = match.end()\n", 475 | "# end = matches[i+1].start() if i+1 < len(matches) else len(content)\n", 476 | "# section_text = content[start:end].strip()\n", 477 | "# # Prepend the header line to the section text if desired\n", 478 | "# full_text = f\"{heading}\\n\\n{section_text}\"\n", 479 | "# sections.append({\"heading\": heading, \"text\": full_text})\n", 480 | " \n", 481 | "# # Now, for each section, if its token count exceeds max_tokens, further split it via sliding window.\n", 482 | "# chunks = []\n", 483 | "# for section in sections:\n", 484 | "# section_text = section[\"text\"]\n", 485 | "# token_count = count_tokens(section_text)\n", 486 | "# if token_count > max_tokens:\n", 487 | "# subchunks = split_text_sliding_window(section_text, max_tokens, overlap)\n", 488 | "# for sub in subchunks:\n", 489 | "# chunks.append({\"heading\": section[\"heading\"], \"chunk_text\": sub})\n", 490 | "# else:\n", 491 | "# chunks.append({\"heading\": section[\"heading\"], \"chunk_text\": section_text})\n", 492 | " \n", 493 | "# return {\"head\": article_head, \"chunks\": chunks}\n", 494 | "\n", 495 | "# def summarize_article_head(article_head: str) -> str:\n", 496 | "# \"\"\"\n", 497 | "# Generate an overall summary for the article.\n", 498 | "# In this example, we simply use the first 100 tokens.\n", 499 | "# In practice, you might call an LLM summarizer.\n", 500 | "# \"\"\"\n", 501 | "# tokens = encoding.encode(article_head)\n", 502 | "# summary_tokens = tokens[:min(100, len(tokens))]\n", 503 | "# summary = encoding.decode(summary_tokens)\n", 504 | "# return summary\n", 505 | "\n", 506 | "# # ---------------------------\n", 507 | "# # (2) Prepare Prompt and Call DeepSeek R1\n", 508 | "# # ---------------------------\n", 509 | "# def prepare_prompt(article_summary: str, chunk_text: str) -> str:\n", 510 | "# \"\"\"\n", 511 | "# Prepares the prompt for DeepSeek R1.\n", 512 | "# The prompt includes:\n", 513 | "# - Overall Article Summary (from the article head)\n", 514 | "# - The current chunk's text\n", 515 | "# - Extraction instructions\n", 516 | "# \"\"\"\n", 517 | "# prompt = (\n", 518 | "# \"Article Summary:\\n\" + article_summary + \"\\n\\n\" +\n", 519 | "# \"Chunk Text:\\n\" + chunk_text + \"\\n\\n\" +\n", 520 | "# \"Instructions: Analyze the above text, explain your reasoning inside tags, \"\n", 521 | "# \"and output a structured knowledge graph in JSON format inside tags. \"\n", 522 | "# \"The JSON should have two keys: 'nodes' and 'edges'. For example:\\n\"\n", 523 | "# '{\"nodes\": [{\"id\": 1, \"label\": \"EntityName\", \"type\": \"EntityType\"}, ...],\\n'\n", 524 | "# '\"edges\": [{\"source\": 1, \"target\": 2, \"relation\": \"RELATION_TYPE\"}, ...]}\\n'\n", 525 | "# \"Ensure your output strictly follows this format.\"\n", 526 | "# )\n", 527 | "# return prompt\n", 528 | "\n", 529 | "# def call_deepseek(prompt: str):\n", 530 | "# \"\"\"\n", 531 | "# Calls the deepseek/deepseek-r1 model using the OpenAI chat completions interface.\n", 532 | "# Returns a tuple of (api_output, thinking_process, error).\n", 533 | "# \"\"\"\n", 534 | "# try:\n", 535 | "# # Replace 'client.chat.completions.create' with your actual API call.\n", 536 | "# # For example, if using OpenAI's client:\n", 537 | "# completion = client.chat.completions.create(\n", 538 | "# extra_body={\"include_reasoning\": True},\n", 539 | "# model=\"deepseek/deepseek-r1\",\n", 540 | "# messages=[{\"role\": \"user\", \"content\": prompt}]\n", 541 | "# )\n", 542 | "# output = completion.choices[0].message.content\n", 543 | "# # Assume reasoning is returned in model_extra (if available)\n", 544 | "# thinking_process = completion.choices[0].message.model_extra.get(\"reasoning\", \"\")\n", 545 | "# error = \"\"\n", 546 | "# except Exception as e:\n", 547 | "# print(\"API call failed:\", e)\n", 548 | "# output = \"\"\n", 549 | "# thinking_process = \"\"\n", 550 | "# error = str(e)\n", 551 | "# return output, thinking_process, error\n", 552 | "\n", 553 | "# def process_chunk(metadata: dict) -> dict:\n", 554 | "# \"\"\"\n", 555 | "# Processes a single chunk using the prepared prompt and returns the metadata updated\n", 556 | "# with API output.\n", 557 | "# \"\"\"\n", 558 | "# prompt = metadata[\"prompt\"]\n", 559 | "# api_output, thinking_process, error = call_deepseek(prompt)\n", 560 | "# metadata[\"api_output\"] = api_output\n", 561 | "# metadata[\"thinking_process\"] = thinking_process\n", 562 | "# metadata[\"error\"] = error\n", 563 | "# return metadata\n", 564 | "\n", 565 | "# # ---------------------------\n", 566 | "# # (3) Persist Data in Tables\n", 567 | "# # ---------------------------\n", 568 | "# def persist_results(results: list, output_csv: str = \"rl_training_data.csv\"):\n", 569 | "# \"\"\"\n", 570 | "# Persists a list of results (each a dict) into a CSV file.\n", 571 | "# \"\"\"\n", 572 | "# df = pd.DataFrame(results)\n", 573 | "# df.to_csv(output_csv, index=False)\n", 574 | "# print(f\"Results saved to {output_csv}\")\n", 575 | "\n", 576 | "# # ---------------------------\n", 577 | "# # Main Script with Batch Processing\n", 578 | "# # ---------------------------\n", 579 | "# def main():\n", 580 | "# docs_dir = \"data_raw\"\n", 581 | "# all_metadata = []\n", 582 | "\n", 583 | "# # Process each markdown file and accumulate chunk metadata\n", 584 | "# for filename in os.listdir(docs_dir):\n", 585 | "# if filename.endswith(\".md\"):\n", 586 | "# filepath = os.path.join(docs_dir, filename)\n", 587 | "# print(f\"Processing {filepath}...\")\n", 588 | "# file_data = split_markdown_file(filepath, MAX_TOKENS, OVERLAP_TOKENS)\n", 589 | "# article_head = file_data[\"head\"]\n", 590 | "# article_summary = summarize_article_head(article_head) if article_head else \"\"\n", 591 | " \n", 592 | "# for idx, chunk in enumerate(file_data[\"chunks\"]):\n", 593 | "# chunk_text = chunk[\"chunk_text\"]\n", 594 | "# prompt = prepare_prompt(article_summary, chunk_text)\n", 595 | "# meta = {\n", 596 | "# \"file\": filename,\n", 597 | "# \"chunk_index\": idx,\n", 598 | "# \"heading\": chunk[\"heading\"],\n", 599 | "# \"chunk_text\": chunk_text,\n", 600 | "# \"article_summary\": article_summary,\n", 601 | "# \"prompt\": prompt\n", 602 | "# }\n", 603 | "# all_metadata.append(meta)\n", 604 | " \n", 605 | "# # Process chunks in parallel using a ThreadPoolExecutor with batch size BATCH_SIZE.\n", 606 | "# results = []\n", 607 | "# with concurrent.futures.ThreadPoolExecutor(max_workers=BATCH_SIZE) as executor:\n", 608 | "# # Map all_metadata to process_chunk concurrently\n", 609 | "# futures = [executor.submit(process_chunk, meta) for meta in all_metadata]\n", 610 | "# for future in concurrent.futures.as_completed(futures):\n", 611 | "# result = future.result()\n", 612 | "# results.append(result)\n", 613 | " \n", 614 | "# # Persist the results to a CSV file\n", 615 | "# persist_results(results)\n", 616 | "\n", 617 | "# if __name__ == \"__main__\":\n", 618 | "# main()" 619 | ] 620 | }, 621 | { 622 | "cell_type": "markdown", 623 | "id": "bc8d851c-9584-4c37-9293-e69d7b733f12", 624 | "metadata": {}, 625 | "source": [ 626 | "## Data Wangling\n", 627 | "\n", 628 | "### Human Editing\n", 629 | "\n", 630 | "- removed first part per each article, it's the summary section of the article\n", 631 | "- removed dirty items during the execution" 632 | ] 633 | }, 634 | { 635 | "cell_type": "markdown", 636 | "id": "f6c6c4e5-88be-455c-bd99-dc6bb4b6786e", 637 | "metadata": {}, 638 | "source": [ 639 | "### Polishing of data\n", 640 | "\n", 641 | "- we now mark those with too long reasoning process\n", 642 | "- we now count and validate the output of edges and nodes extracted" 643 | ] 644 | }, 645 | { 646 | "cell_type": "code", 647 | "execution_count": 24, 648 | "id": "c6327179-c832-4efa-a03e-dd97c37020e8", 649 | "metadata": {}, 650 | "outputs": [ 651 | { 652 | "name": "stdout", 653 | "output_type": "stream", 654 | "text": [ 655 | "Polished dataset saved to polished_rl_training_data.csv\n" 656 | ] 657 | } 658 | ], 659 | "source": [ 660 | "import pandas as pd\n", 661 | "import json\n", 662 | "import re\n", 663 | "import tiktoken\n", 664 | "\n", 665 | "# ---------------------------\n", 666 | "# Configuration for tiktoken\n", 667 | "# ---------------------------\n", 668 | "# Use the appropriate encoding for your model.\n", 669 | "encoding = tiktoken.encoding_for_model(\"gpt-3.5-turbo\")\n", 670 | "\n", 671 | "def count_tokens(text: str) -> int:\n", 672 | " \"\"\"Count tokens in the given text using tiktoken.\"\"\"\n", 673 | " try:\n", 674 | " return len(encoding.encode(text))\n", 675 | " except Exception as e:\n", 676 | " return 0\n", 677 | "\n", 678 | "def extract_json_from_answer(api_output: str) -> str:\n", 679 | " \"\"\"\n", 680 | " Extracts the content inside ... tags.\n", 681 | " Returns None if not found.\n", 682 | " \"\"\"\n", 683 | " match = re.search(r\"(.*?)\", api_output, re.DOTALL)\n", 684 | " if match:\n", 685 | " return match.group(1).strip()\n", 686 | " return None\n", 687 | "\n", 688 | "def validate_json(json_text: str):\n", 689 | " \"\"\"\n", 690 | " Validates and parses JSON from text.\n", 691 | " Returns (parsed_object, True) if valid; otherwise, (None, False).\n", 692 | " \"\"\"\n", 693 | " try:\n", 694 | " data = json.loads(json_text)\n", 695 | " return data, True\n", 696 | " except Exception as e:\n", 697 | " return None, False\n", 698 | "\n", 699 | "def polish_row(row: pd.Series) -> pd.Series:\n", 700 | " \"\"\"\n", 701 | " Processes a single row from the dataset:\n", 702 | " - Counts tokens in 'thinking_process' and marks if too long.\n", 703 | " - Extracts and validates JSON from 'api_output' (the content inside tags).\n", 704 | " - If JSON is valid, counts nodes and edges.\n", 705 | " \"\"\"\n", 706 | " # Process thinking_process\n", 707 | " tp = row.get(\"thinking_process\", \"\")\n", 708 | " tp_token_count = count_tokens(tp)\n", 709 | " row[\"thinking_process_token_count\"] = tp_token_count\n", 710 | " row[\"bad_reasoning\"] = tp_token_count >= 7800\n", 711 | "\n", 712 | " # Process api_output for JSON extraction\n", 713 | " api_output = row.get(\"api_output\", \"\")\n", 714 | " json_text = extract_json_from_answer(str(api_output))\n", 715 | " if not json_text:\n", 716 | " row[\"bad_extraction\"] = True\n", 717 | " row[\"node_count\"] = None\n", 718 | " row[\"edge_count\"] = None\n", 719 | " else:\n", 720 | " parsed_json, is_valid = validate_json(json_text)\n", 721 | " row[\"bad_extraction\"] = not is_valid\n", 722 | " if is_valid and isinstance(parsed_json, dict):\n", 723 | " nodes = parsed_json.get(\"nodes\", [])\n", 724 | " edges = parsed_json.get(\"edges\", [])\n", 725 | " row[\"node_count\"] = len(nodes)\n", 726 | " row[\"edge_count\"] = len(edges)\n", 727 | " else:\n", 728 | " row[\"node_count\"] = None\n", 729 | " row[\"edge_count\"] = None\n", 730 | "\n", 731 | " # (Optional) Additional polishing steps can be added here\n", 732 | " # For example: count tokens in prompt or chunk_text, flag if missing fields, etc.\n", 733 | " \n", 734 | " return row\n", 735 | "\n", 736 | "def polish_dataset(input_csv: str, output_csv: str):\n", 737 | " \"\"\"\n", 738 | " Loads the dataset from a CSV file, applies polishing to each row,\n", 739 | " and saves the polished dataset into another CSV file.\n", 740 | " \"\"\"\n", 741 | " df = pd.read_csv(input_csv)\n", 742 | " df = df.apply(polish_row, axis=1)\n", 743 | " df.to_csv(output_csv, index=False)\n", 744 | " print(f\"Polished dataset saved to {output_csv}\")\n", 745 | "\n", 746 | "if __name__ == \"__main__\":\n", 747 | " polish_dataset(\"rl_training_data_human_reviewed.csv\", \"polished_rl_training_data.csv\")\n" 748 | ] 749 | }, 750 | { 751 | "cell_type": "markdown", 752 | "id": "dc0e35f4-b0d4-4c6c-be55-e6d430407349", 753 | "metadata": {}, 754 | "source": [ 755 | "After performing this, we could see that one data entry got truncated in its reasoning with more than 8000 tokens during reasoning, and a couple(5) of entries got truncated during graph extraction in output." 756 | ] 757 | }, 758 | { 759 | "cell_type": "code", 760 | "execution_count": 27, 761 | "id": "35d99334-22e3-4032-946d-b6fb534990f9", 762 | "metadata": {}, 763 | "outputs": [], 764 | "source": [ 765 | "df = pd.read_csv(\"polished_rl_training_data.csv\")\n", 766 | "filtered_df = df[(df['bad_reasoning'] == False) & (df['bad_extraction'] == False)]" 767 | ] 768 | }, 769 | { 770 | "cell_type": "code", 771 | "execution_count": 28, 772 | "id": "b0c9eeca-6075-4e79-a55f-7c2664bae4bb", 773 | "metadata": {}, 774 | "outputs": [ 775 | { 776 | "data": { 777 | "text/html": [ 778 | "
\n", 779 | "\n", 792 | "\n", 793 | " \n", 794 | " \n", 795 | " \n", 796 | " \n", 797 | " \n", 798 | " \n", 799 | " \n", 800 | " \n", 801 | " \n", 802 | " \n", 803 | " \n", 804 | " \n", 805 | " \n", 806 | " \n", 807 | " \n", 808 | " \n", 809 | " \n", 810 | " \n", 811 | " \n", 812 | " \n", 813 | " \n", 814 | " \n", 815 | " \n", 816 | " \n", 817 | " \n", 818 | " \n", 819 | " \n", 820 | " \n", 821 | " \n", 822 | " \n", 823 | " \n", 824 | " \n", 825 | " \n", 826 | " \n", 827 | " \n", 828 | " \n", 829 | " \n", 830 | " \n", 831 | " \n", 832 | " \n", 833 | " \n", 834 | " \n", 835 | " \n", 836 | " \n", 837 | " \n", 838 | " \n", 839 | " \n", 840 | " \n", 841 | " \n", 842 | " \n", 843 | " \n", 844 | " \n", 845 | " \n", 846 | " \n", 847 | " \n", 848 | " \n", 849 | " \n", 850 | " \n", 851 | " \n", 852 | " \n", 853 | " \n", 854 | " \n", 855 | " \n", 856 | " \n", 857 | " \n", 858 | " \n", 859 | " \n", 860 | " \n", 861 | " \n", 862 | " \n", 863 | " \n", 864 | " \n", 865 | " \n", 866 | " \n", 867 | " \n", 868 | " \n", 869 | " \n", 870 | " \n", 871 | " \n", 872 | " \n", 873 | " \n", 874 | " \n", 875 | " \n", 876 | " \n", 877 | " \n", 878 | " \n", 879 | " \n", 880 | " \n", 881 | " \n", 882 | " \n", 883 | " \n", 884 | " \n", 885 | " \n", 886 | " \n", 887 | " \n", 888 | " \n", 889 | " \n", 890 | " \n", 891 | " \n", 892 | " \n", 893 | " \n", 894 | " \n", 895 | " \n", 896 | " \n", 897 | " \n", 898 | " \n", 899 | " \n", 900 | " \n", 901 | " \n", 902 | " \n", 903 | " \n", 904 | " \n", 905 | " \n", 906 | " \n", 907 | " \n", 908 | " \n", 909 | " \n", 910 | " \n", 911 | " \n", 912 | " \n", 913 | " \n", 914 | " \n", 915 | " \n", 916 | " \n", 917 | " \n", 918 | " \n", 919 | " \n", 920 | " \n", 921 | " \n", 922 | " \n", 923 | " \n", 924 | " \n", 925 | " \n", 926 | " \n", 927 | " \n", 928 | " \n", 929 | " \n", 930 | " \n", 931 | " \n", 932 | " \n", 933 | " \n", 934 | " \n", 935 | " \n", 936 | " \n", 937 | " \n", 938 | " \n", 939 | " \n", 940 | " \n", 941 | " \n", 942 | " \n", 943 | " \n", 944 | " \n", 945 | " \n", 946 | " \n", 947 | " \n", 948 | " \n", 949 | " \n", 950 | " \n", 951 | " \n", 952 | " \n", 953 | " \n", 954 | " \n", 955 | " \n", 956 | " \n", 957 | " \n", 958 | " \n", 959 | " \n", 960 | " \n", 961 | " \n", 962 | " \n", 963 | " \n", 964 | " \n", 965 | " \n", 966 | " \n", 967 | " \n", 968 | " \n", 969 | " \n", 970 | " \n", 971 | " \n", 972 | " \n", 973 | " \n", 974 | " \n", 975 | " \n", 976 | " \n", 977 | " \n", 978 | " \n", 979 | " \n", 980 | " \n", 981 | " \n", 982 | " \n", 983 | " \n", 984 | " \n", 985 | " \n", 986 | " \n", 987 | " \n", 988 | " \n", 989 | " \n", 990 | " \n", 991 | " \n", 992 | " \n", 993 | " \n", 994 | " \n", 995 | " \n", 996 | " \n", 997 | " \n", 998 | " \n", 999 | " \n", 1000 | " \n", 1001 | " \n", 1002 | " \n", 1003 | " \n", 1004 | " \n", 1005 | " \n", 1006 | " \n", 1007 | " \n", 1008 | " \n", 1009 | " \n", 1010 | " \n", 1011 | " \n", 1012 | " \n", 1013 | " \n", 1014 | " \n", 1015 | " \n", 1016 | " \n", 1017 | " \n", 1018 | " \n", 1019 | " \n", 1020 | " \n", 1021 | " \n", 1022 | " \n", 1023 | " \n", 1024 | " \n", 1025 | " \n", 1026 | " \n", 1027 | " \n", 1028 | " \n", 1029 | " \n", 1030 | " \n", 1031 | " \n", 1032 | " \n", 1033 | " \n", 1034 | " \n", 1035 | " \n", 1036 | " \n", 1037 | " \n", 1038 | " \n", 1039 | " \n", 1040 | " \n", 1041 | " \n", 1042 | " \n", 1043 | " \n", 1044 | " \n", 1045 | " \n", 1046 | " \n", 1047 | " \n", 1048 | " \n", 1049 | " \n", 1050 | " \n", 1051 | " \n", 1052 | " \n", 1053 | " \n", 1054 | " \n", 1055 | " \n", 1056 | " \n", 1057 | " \n", 1058 | " \n", 1059 | " \n", 1060 | " \n", 1061 | " \n", 1062 | " \n", 1063 | " \n", 1064 | " \n", 1065 | " \n", 1066 | " \n", 1067 | " \n", 1068 | " \n", 1069 | " \n", 1070 | " \n", 1071 | " \n", 1072 | " \n", 1073 | " \n", 1074 | " \n", 1075 | " \n", 1076 | " \n", 1077 | " \n", 1078 | " \n", 1079 | " \n", 1080 | " \n", 1081 | " \n", 1082 | " \n", 1083 | " \n", 1084 | " \n", 1085 | " \n", 1086 | " \n", 1087 | " \n", 1088 | " \n", 1089 | " \n", 1090 | " \n", 1091 | " \n", 1092 | " \n", 1093 | " \n", 1094 | " \n", 1095 | " \n", 1096 | " \n", 1097 | " \n", 1098 | " \n", 1099 | " \n", 1100 | " \n", 1101 | " \n", 1102 | " \n", 1103 | " \n", 1104 | " \n", 1105 | " \n", 1106 | " \n", 1107 | " \n", 1108 | " \n", 1109 | " \n", 1110 | " \n", 1111 | " \n", 1112 | " \n", 1113 | " \n", 1114 | " \n", 1115 | " \n", 1116 | " \n", 1117 | " \n", 1118 | " \n", 1119 | " \n", 1120 | " \n", 1121 | " \n", 1122 | " \n", 1123 | " \n", 1124 | " \n", 1125 | " \n", 1126 | " \n", 1127 | " \n", 1128 | " \n", 1129 | " \n", 1130 | " \n", 1131 | " \n", 1132 | " \n", 1133 | " \n", 1134 | " \n", 1135 | " \n", 1136 | " \n", 1137 | " \n", 1138 | " \n", 1139 | " \n", 1140 | " \n", 1141 | " \n", 1142 | " \n", 1143 | " \n", 1144 | " \n", 1145 | " \n", 1146 | " \n", 1147 | " \n", 1148 | " \n", 1149 | " \n", 1150 | " \n", 1151 | " \n", 1152 | " \n", 1153 | " \n", 1154 | " \n", 1155 | " \n", 1156 | " \n", 1157 | " \n", 1158 | " \n", 1159 | " \n", 1160 | " \n", 1161 | " \n", 1162 | " \n", 1163 | " \n", 1164 | " \n", 1165 | " \n", 1166 | " \n", 1167 | " \n", 1168 | " \n", 1169 | " \n", 1170 | " \n", 1171 | " \n", 1172 | " \n", 1173 | " \n", 1174 | " \n", 1175 | " \n", 1176 | " \n", 1177 | " \n", 1178 | " \n", 1179 | " \n", 1180 | " \n", 1181 | " \n", 1182 | " \n", 1183 | " \n", 1184 | " \n", 1185 | " \n", 1186 | " \n", 1187 | " \n", 1188 | " \n", 1189 | " \n", 1190 | " \n", 1191 | " \n", 1192 | " \n", 1193 | " \n", 1194 | " \n", 1195 | " \n", 1196 | " \n", 1197 | " \n", 1198 | " \n", 1199 | " \n", 1200 | " \n", 1201 | " \n", 1202 | " \n", 1203 | " \n", 1204 | " \n", 1205 | " \n", 1206 | " \n", 1207 | " \n", 1208 | " \n", 1209 | " \n", 1210 | " \n", 1211 | " \n", 1212 | " \n", 1213 | " \n", 1214 | " \n", 1215 | " \n", 1216 | " \n", 1217 | " \n", 1218 | " \n", 1219 | " \n", 1220 | " \n", 1221 | " \n", 1222 | " \n", 1223 | " \n", 1224 | " \n", 1225 | " \n", 1226 | " \n", 1227 | " \n", 1228 | " \n", 1229 | " \n", 1230 | " \n", 1231 | " \n", 1232 | " \n", 1233 | " \n", 1234 | " \n", 1235 | " \n", 1236 | " \n", 1237 | " \n", 1238 | " \n", 1239 | " \n", 1240 | " \n", 1241 | " \n", 1242 | " \n", 1243 | " \n", 1244 | " \n", 1245 | " \n", 1246 | " \n", 1247 | " \n", 1248 | " \n", 1249 | " \n", 1250 | " \n", 1251 | " \n", 1252 | " \n", 1253 | " \n", 1254 | " \n", 1255 | " \n", 1256 | " \n", 1257 | " \n", 1258 | " \n", 1259 | " \n", 1260 | " \n", 1261 | " \n", 1262 | " \n", 1263 | " \n", 1264 | " \n", 1265 | " \n", 1266 | " \n", 1267 | " \n", 1268 | " \n", 1269 | " \n", 1270 | " \n", 1271 | " \n", 1272 | " \n", 1273 | " \n", 1274 | " \n", 1275 | " \n", 1276 | " \n", 1277 | " \n", 1278 | " \n", 1279 | " \n", 1280 | " \n", 1281 | " \n", 1282 | " \n", 1283 | " \n", 1284 | " \n", 1285 | " \n", 1286 | " \n", 1287 | " \n", 1288 | " \n", 1289 | " \n", 1290 | " \n", 1291 | " \n", 1292 | " \n", 1293 | " \n", 1294 | " \n", 1295 | " \n", 1296 | " \n", 1297 | " \n", 1298 | " \n", 1299 | " \n", 1300 | " \n", 1301 | " \n", 1302 | " \n", 1303 | " \n", 1304 | " \n", 1305 | " \n", 1306 | " \n", 1307 | " \n", 1308 | " \n", 1309 | " \n", 1310 | " \n", 1311 | " \n", 1312 | " \n", 1313 | " \n", 1314 | " \n", 1315 | " \n", 1316 | " \n", 1317 | " \n", 1318 | " \n", 1319 | " \n", 1320 | " \n", 1321 | " \n", 1322 | " \n", 1323 | " \n", 1324 | " \n", 1325 | " \n", 1326 | " \n", 1327 | " \n", 1328 | " \n", 1329 | " \n", 1330 | " \n", 1331 | " \n", 1332 | " \n", 1333 | " \n", 1334 | " \n", 1335 | " \n", 1336 | " \n", 1337 | " \n", 1338 | " \n", 1339 | " \n", 1340 | " \n", 1341 | " \n", 1342 | " \n", 1343 | " \n", 1344 | " \n", 1345 | " \n", 1346 | " \n", 1347 | " \n", 1348 | " \n", 1349 | " \n", 1350 | " \n", 1351 | " \n", 1352 | " \n", 1353 | " \n", 1354 | " \n", 1355 | " \n", 1356 | " \n", 1357 | " \n", 1358 | " \n", 1359 | " \n", 1360 | " \n", 1361 | " \n", 1362 | " \n", 1363 | " \n", 1364 | " \n", 1365 | " \n", 1366 | " \n", 1367 | " \n", 1368 | " \n", 1369 | " \n", 1370 | " \n", 1371 | " \n", 1372 | " \n", 1373 | " \n", 1374 | " \n", 1375 | " \n", 1376 | " \n", 1377 | " \n", 1378 | " \n", 1379 | " \n", 1380 | " \n", 1381 | " \n", 1382 | " \n", 1383 | " \n", 1384 | " \n", 1385 | " \n", 1386 | " \n", 1387 | " \n", 1388 | " \n", 1389 | " \n", 1390 | " \n", 1391 | " \n", 1392 | " \n", 1393 | " \n", 1394 | " \n", 1395 | " \n", 1396 | " \n", 1397 | " \n", 1398 | " \n", 1399 | " \n", 1400 | " \n", 1401 | " \n", 1402 | " \n", 1403 | " \n", 1404 | " \n", 1405 | " \n", 1406 | " \n", 1407 | " \n", 1408 | " \n", 1409 | " \n", 1410 | " \n", 1411 | " \n", 1412 | " \n", 1413 | " \n", 1414 | " \n", 1415 | " \n", 1416 | " \n", 1417 | " \n", 1418 | " \n", 1419 | " \n", 1420 | " \n", 1421 | " \n", 1422 | " \n", 1423 | " \n", 1424 | " \n", 1425 | " \n", 1426 | " \n", 1427 | " \n", 1428 | " \n", 1429 | " \n", 1430 | " \n", 1431 | " \n", 1432 | " \n", 1433 | " \n", 1434 | " \n", 1435 | " \n", 1436 | " \n", 1437 | " \n", 1438 | " \n", 1439 | " \n", 1440 | " \n", 1441 | " \n", 1442 | " \n", 1443 | " \n", 1444 | " \n", 1445 | " \n", 1446 | " \n", 1447 | " \n", 1448 | " \n", 1449 | " \n", 1450 | " \n", 1451 | " \n", 1452 | " \n", 1453 | " \n", 1454 | " \n", 1455 | " \n", 1456 | " \n", 1457 | " \n", 1458 | " \n", 1459 | " \n", 1460 | " \n", 1461 | " \n", 1462 | " \n", 1463 | " \n", 1464 | " \n", 1465 | " \n", 1466 | " \n", 1467 | " \n", 1468 | " \n", 1469 | " \n", 1470 | " \n", 1471 | " \n", 1472 | " \n", 1473 | " \n", 1474 | " \n", 1475 | " \n", 1476 | " \n", 1477 | " \n", 1478 | " \n", 1479 | " \n", 1480 | " \n", 1481 | " \n", 1482 | " \n", 1483 | " \n", 1484 | " \n", 1485 | " \n", 1486 | " \n", 1487 | " \n", 1488 | " \n", 1489 | " \n", 1490 | " \n", 1491 | " \n", 1492 | " \n", 1493 | " \n", 1494 | " \n", 1495 | " \n", 1496 | " \n", 1497 | " \n", 1498 | " \n", 1499 | " \n", 1500 | " \n", 1501 | " \n", 1502 | " \n", 1503 | " \n", 1504 | " \n", 1505 | " \n", 1506 | " \n", 1507 | " \n", 1508 | " \n", 1509 | " \n", 1510 | " \n", 1511 | " \n", 1512 | " \n", 1513 | " \n", 1514 | " \n", 1515 | " \n", 1516 | " \n", 1517 | " \n", 1518 | " \n", 1519 | " \n", 1520 | " \n", 1521 | " \n", 1522 | " \n", 1523 | " \n", 1524 | " \n", 1525 | " \n", 1526 | " \n", 1527 | " \n", 1528 | " \n", 1529 | " \n", 1530 | " \n", 1531 | " \n", 1532 | " \n", 1533 | " \n", 1534 | " \n", 1535 | " \n", 1536 | " \n", 1537 | " \n", 1538 | " \n", 1539 | " \n", 1540 | " \n", 1541 | " \n", 1542 | " \n", 1543 | " \n", 1544 | " \n", 1545 | " \n", 1546 | " \n", 1547 | " \n", 1548 | " \n", 1549 | " \n", 1550 | " \n", 1551 | " \n", 1552 | " \n", 1553 | " \n", 1554 | " \n", 1555 | " \n", 1556 | " \n", 1557 | " \n", 1558 | " \n", 1559 | " \n", 1560 | " \n", 1561 | " \n", 1562 | " \n", 1563 | " \n", 1564 | " \n", 1565 | " \n", 1566 | " \n", 1567 | " \n", 1568 | " \n", 1569 | " \n", 1570 | " \n", 1571 | " \n", 1572 | " \n", 1573 | " \n", 1574 | " \n", 1575 | " \n", 1576 | " \n", 1577 | " \n", 1578 | " \n", 1579 | " \n", 1580 | " \n", 1581 | " \n", 1582 | " \n", 1583 | " \n", 1584 | " \n", 1585 | " \n", 1586 | " \n", 1587 | " \n", 1588 | " \n", 1589 | " \n", 1590 | " \n", 1591 | " \n", 1592 | " \n", 1593 | " \n", 1594 | " \n", 1595 | " \n", 1596 | " \n", 1597 | " \n", 1598 | " \n", 1599 | " \n", 1600 | " \n", 1601 | " \n", 1602 | " \n", 1603 | " \n", 1604 | " \n", 1605 | " \n", 1606 | " \n", 1607 | " \n", 1608 | " \n", 1609 | " \n", 1610 | " \n", 1611 | " \n", 1612 | " \n", 1613 | " \n", 1614 | " \n", 1615 | " \n", 1616 | " \n", 1617 | " \n", 1618 | " \n", 1619 | " \n", 1620 | " \n", 1621 | " \n", 1622 | " \n", 1623 | " \n", 1624 | " \n", 1625 | " \n", 1626 | " \n", 1627 | " \n", 1628 | " \n", 1629 | " \n", 1630 | " \n", 1631 | " \n", 1632 | " \n", 1633 | " \n", 1634 | " \n", 1635 | " \n", 1636 | " \n", 1637 | " \n", 1638 | " \n", 1639 | " \n", 1640 | " \n", 1641 | " \n", 1642 | " \n", 1643 | " \n", 1644 | " \n", 1645 | " \n", 1646 | " \n", 1647 | " \n", 1648 | " \n", 1649 | " \n", 1650 | " \n", 1651 | " \n", 1652 | " \n", 1653 | " \n", 1654 | " \n", 1655 | " \n", 1656 | " \n", 1657 | " \n", 1658 | " \n", 1659 | " \n", 1660 | " \n", 1661 | " \n", 1662 | " \n", 1663 | " \n", 1664 | " \n", 1665 | " \n", 1666 | " \n", 1667 | " \n", 1668 | " \n", 1669 | " \n", 1670 | " \n", 1671 | " \n", 1672 | " \n", 1673 | " \n", 1674 | " \n", 1675 | " \n", 1676 | " \n", 1677 | " \n", 1678 | " \n", 1679 | " \n", 1680 | " \n", 1681 | " \n", 1682 | " \n", 1683 | " \n", 1684 | " \n", 1685 | " \n", 1686 | " \n", 1687 | " \n", 1688 | " \n", 1689 | " \n", 1690 | " \n", 1691 | " \n", 1692 | " \n", 1693 | " \n", 1694 | " \n", 1695 | " \n", 1696 | " \n", 1697 | " \n", 1698 | " \n", 1699 | " \n", 1700 | " \n", 1701 | " \n", 1702 | " \n", 1703 | " \n", 1704 | " \n", 1705 | " \n", 1706 | " \n", 1707 | " \n", 1708 | " \n", 1709 | " \n", 1710 | " \n", 1711 | " \n", 1712 | " \n", 1713 | " \n", 1714 | " \n", 1715 | " \n", 1716 | " \n", 1717 | " \n", 1718 | " \n", 1719 | " \n", 1720 | " \n", 1721 | " \n", 1722 | " \n", 1723 | " \n", 1724 | " \n", 1725 | " \n", 1726 | " \n", 1727 | " \n", 1728 | " \n", 1729 | " \n", 1730 | " \n", 1731 | " \n", 1732 | " \n", 1733 | " \n", 1734 | " \n", 1735 | " \n", 1736 | " \n", 1737 | " \n", 1738 | " \n", 1739 | " \n", 1740 | " \n", 1741 | " \n", 1742 | " \n", 1743 | " \n", 1744 | " \n", 1745 | " \n", 1746 | " \n", 1747 | " \n", 1748 | " \n", 1749 | " \n", 1750 | " \n", 1751 | " \n", 1752 | " \n", 1753 | " \n", 1754 | " \n", 1755 | " \n", 1756 | " \n", 1757 | " \n", 1758 | " \n", 1759 | " \n", 1760 | " \n", 1761 | " \n", 1762 | " \n", 1763 | " \n", 1764 | " \n", 1765 | " \n", 1766 | " \n", 1767 | " \n", 1768 | " \n", 1769 | " \n", 1770 | " \n", 1771 | " \n", 1772 | " \n", 1773 | " \n", 1774 | " \n", 1775 | " \n", 1776 | " \n", 1777 | " \n", 1778 | " \n", 1779 | " \n", 1780 | " \n", 1781 | " \n", 1782 | " \n", 1783 | " \n", 1784 | " \n", 1785 | " \n", 1786 | " \n", 1787 | " \n", 1788 | " \n", 1789 | " \n", 1790 | " \n", 1791 | " \n", 1792 | " \n", 1793 | " \n", 1794 | " \n", 1795 | " \n", 1796 | " \n", 1797 | " \n", 1798 | " \n", 1799 | " \n", 1800 | " \n", 1801 | " \n", 1802 | " \n", 1803 | " \n", 1804 | " \n", 1805 | " \n", 1806 | " \n", 1807 | " \n", 1808 | " \n", 1809 | " \n", 1810 | " \n", 1811 | " \n", 1812 | " \n", 1813 | " \n", 1814 | " \n", 1815 | " \n", 1816 | " \n", 1817 | "
filechunk_indexheadingchunk_textarticle_summarypromptapi_outputthinking_processerrorthinking_process_token_countbad_reasoningbad_extractionnode_countedge_count
02024_in_science.md1### January### January\\n\\n- 2 January – The [Japan Meteor...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n\\n## 2024 in science\\n\\n> UR...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN1053FalseFalse25.017.0
12024_in_science.md2### January](https://en.wikipedia.org/wiki/Extinction) of...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN988FalseFalse34.023.0
22024_in_science.md3### Januaryen.wikipedia.org/wiki/101955_Bennu), after thr...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN2919FalseFalse32.021.0
32024_in_science.md4### January-first_century.webp)[24 January](https://en.wi...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN4959FalseFalse36.023.0
42024_in_science.md5### January2024_in_science#cite_note-81)[[82]](https://en...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN1368FalseFalse17.012.0
52024_in_science.md6### February### February\\n\\n- 2 February\\n - Scientists r...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN2717FalseFalse28.018.0
62024_in_science.md7### February.wikipedia.org/wiki/Mobile_phone).[[114]](http...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...\\nOkay, let's tackle this problem step by step...NaN1085FalseFalse17.014.0
72024_in_science.md8### Februaryor pollution-mediated, deaths from automobili...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN3960FalseFalse30.019.0
82024_in_science.md9### February[prebiotic](https://en.wikipedia.org/wiki/Pre...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN1963FalseFalse40.023.0
92024_in_science.md10### February.wikipedia.org/wiki/2024_in_science#cite_note-...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n\\n## 2024 in science\\n\\n> UR...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN5365FalseFalse33.021.0
102024_in_science.md11### March### March\\n\\n- 4 March\\n - Astronomers report...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's tackle this. The user provided a c...NaN3930FalseFalse42.030.0
112024_in_science.md12### March(https://en.wikipedia.org/wiki/2024_in_science...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN2952FalseFalse38.026.0
122024_in_science.md13### March://en.wikipedia.org/wiki/2024_in_science#cite_...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN3805FalseFalse6.05.0
132024_in_science.md14### April### April\\n\\n- 1 April\\n - An entirely new cl...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN2525FalseFalse38.027.0
142024_in_science.md15### Aprilen.wikipedia.org/wiki/Dsup).[[243]](https://en...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN1559FalseFalse48.033.0
152024_in_science.md16### Aprilater_pollution), finding many samples exceed P...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN3812FalseFalse14.010.0
172024_in_science.md18### May28jades4%29.jpg/220px-Webb_finds_most_distant_...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN1324FalseFalse29.016.0
192024_in_science.md20### Mayto 2016 (6 May),[[319]](https://en.wikipedia....## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading the provided text...NaN2788FalseFalse12.09.0
212024_in_science.md22### Junelongevity.[[339]](https://en.wikipedia.org/wi...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN3744FalseFalse20.012.0
222024_in_science.md23### July### July\\n\\n- 2 July\\n - Two new [satellite g...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN752FalseFalse26.016.0
232024_in_science.md24### July://en.wikipedia.org/wiki/2024_in_science#cite_...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN1748FalseFalse10.08.0
242024_in_science.md25### August### August\\n\\n- 1 August – A study in *[Nature...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...\\nOkay, let me try to figure out how to approa...NaN3852FalseFalse45.033.0
252024_in_science.md26### AugustRNA) lung cancer vaccine, begins a Phase I cli...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN3065FalseFalse17.013.0
262024_in_science.md27### September### September\\n\\n- 4 September – The [ESA](htt...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...\\nAlright, I need to tackle this problem where...NaN1157FalseFalse35.022.0
272024_in_science.md28### September://en.wikipedia.org/wiki/2024_in_science#cite_...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...\\nAlright, let's try to tackle this. The user ...NaN5858FalseFalse22.015.0
282024_in_science.md29### October### October\\n\\n- 1 October – The [European Sou...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...\\nAlright, let me start by understanding the p...NaN3137FalseFalse36.025.0
302024_in_science.md32### December### December\\n\\n- 5 December – A single mutati...## 2024 in science\\n\\n> URL Source: https://en...Article Summary:\\n## 2024 in science\\n\\n> URL ...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...\\nAlright, let's try to parse this out. First,...NaN1737FalseFalse37.027.0
31year-in-review-the-biggest-climate-headlines-o...1### **1. 2024 ‘Virtually Certain’ to Be Hottes...### **1. 2024 ‘Virtually Certain’ to Be Hottes...Title: Year in Review: The Biggest Climate Hea...Article Summary:\\nTitle: Year in Review: The B...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...\\nOkay, let's start by reading through the giv...NaN497FalseFalse25.023.0
32year-in-review-the-biggest-climate-headlines-o...2### **2. COP29 Negotiators Finalize $300 Billi...### **2. COP29 Negotiators Finalize $300 Billi...Title: Year in Review: The Biggest Climate Hea...Article Summary:\\nTitle: Year in Review: The B...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN748FalseFalse9.010.0
33year-in-review-the-biggest-climate-headlines-o...3### **3. Historic Global Growth of Renewables ...### **3. Historic Global Growth of Renewables ...Title: Year in Review: The Biggest Climate Hea...Article Summary:\\nTitle: Year in Review: The B...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...\\nOkay, let's start by analyzing the given tex...NaN2219FalseFalse21.020.0
34year-in-review-the-biggest-climate-headlines-o...4### **4. Disappointment Over COP16 Finance Dea...### **4. Disappointment Over COP16 Finance Dea...Title: Year in Review: The Biggest Climate Hea...Article Summary:\\nTitle: Year in Review: The B...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN1117FalseFalse13.013.0
35year-in-review-the-biggest-climate-headlines-o...5### **5. Ocean Warming Intensified Wind Speed ...### **5. Ocean Warming Intensified Wind Speed ...Title: Year in Review: The Biggest Climate Hea...Article Summary:\\nTitle: Year in Review: The B...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN1272FalseFalse12.010.0
36year-in-review-the-biggest-climate-headlines-o...6### **6. Negotiators Fail to Agree on Global P...### **6. Negotiators Fail to Agree on Global P...Title: Year in Review: The Biggest Climate Hea...Article Summary:\\nTitle: Year in Review: The B...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN1348FalseFalse15.012.0
37year-in-review-the-biggest-climate-headlines-o...7### **7. World on Track for 3.1C Warming, UN R...### **7. World on Track for 3.1C Warming, UN R...Title: Year in Review: The Biggest Climate Hea...Article Summary:\\nTitle: Year in Review: The B...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN2165FalseFalse21.019.0
38year-in-review-the-biggest-climate-headlines-o...8### **8. Mount Fuji Snowless in October For Fi...### **8. Mount Fuji Snowless in October For Fi...Title: Year in Review: The Biggest Climate Hea...Article Summary:\\nTitle: Year in Review: The B...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN1530FalseFalse9.09.0
40year-in-review-the-biggest-climate-headlines-o...10### **10. One in Five Migratory Species Threat...### **10. One in Five Migratory Species Threat...Title: Year in Review: The Biggest Climate Hea...Article Summary:\\nTitle: Year in Review: The B...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by understanding the task. I...NaN3206FalseFalse16.016.0
412024-wrapped-for-african-startups-a-year-of-gr...0Article HeadTitle: 2024 WRAPPED for African Startups: A Ye...Title: 2024 WRAPPED for African Startups: A Ye...Article Summary:\\nTitle: 2024 WRAPPED for Afri...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN3441FalseFalse6.08.0
422024-wrapped-for-african-startups-a-year-of-gr...2### **The Rise of Local and Regional Investors**### **The Rise of Local and Regional Investors...Title: 2024 WRAPPED for African Startups: A Ye...Article Summary:\\nTitle: 2024 WRAPPED for Afri...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by understanding the task. I...NaN4431FalseFalse39.055.0
432024-wrapped-for-african-startups-a-year-of-gr...3### **Lessons from Startup Closures**### **Lessons from Startup Closures**\\n\\nDespi...Title: 2024 WRAPPED for African Startups: A Ye...Article Summary:\\nTitle: 2024 WRAPPED for Afri...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN1246FalseFalse11.011.0
442024-wrapped-for-african-startups-a-year-of-gr...4### **Opportunities for Growth: A Call to Acti...### **Opportunities for Growth: A Call to Acti...Title: 2024 WRAPPED for African Startups: A Ye...Article Summary:\\nTitle: 2024 WRAPPED for Afri...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN2194FalseFalse10.012.0
452024-wrapped-for-african-startups-a-year-of-gr...5### **Looking Ahead: The Year 2025 Outlook**### **Looking Ahead: The Year 2025 Outlook**\\n...Title: 2024 WRAPPED for African Startups: A Ye...Article Summary:\\nTitle: 2024 WRAPPED for Afri...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN1392FalseFalse10.09.0
462024_in_spaceflight.md1### 2024 in spaceflight### 2024 in spaceflight\\n\\nIn 2024, saw new wo...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN4076FalseFalse33.026.0
472024_in_spaceflight.md2### Overview### Overview\\n\\n> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's tackle this problem. The user prov...NaN1189FalseFalse5.04.0
482024_in_spaceflight.md3#### Astronomy and astrophysics#### Astronomy and astrophysics\\n\\nOn New Year...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN5416FalseFalse16.014.0
492024_in_spaceflight.md4#### Exploration of the Solar System#### Exploration of the Solar System\\n\\nNASA's...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading the provided text...NaN2175FalseFalse10.010.0
502024_in_spaceflight.md5#### Lunar exploration#### Lunar exploration\\n\\n> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...\\nOkay, let's start by analyzing the user's re...NaN5616FalseFalse11.010.0
512024_in_spaceflight.md6##### Artemis Program##### Artemis Program\\n\\nIn November, stacking...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN540FalseFalse13.014.0
522024_in_spaceflight.md7##### Peregrine##### Peregrine\\n\\nPeregrine lunar lander was ...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading the provided text...NaN1889FalseFalse8.08.0
532024_in_spaceflight.md8##### SLIM##### SLIM\\n\\nSLIM achieved the first-ever lun...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN4511FalseFalse15.019.0
542024_in_spaceflight.md9##### Nova-C##### Nova-C\\n\\nIM-1 Nova-C Odysseus launched ...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN3601FalseFalse10.010.0
552024_in_spaceflight.md10##### China Lunar Exploration Program##### China Lunar Exploration Program\\n\\nMain ...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN1178FalseFalse21.025.0
562024_in_spaceflight.md11##### Future##### Future\\n\\nDARPA provided funding towards...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\\n \"id\": ...\\nOkay, let me parse the given text and figure...NaN1265FalseFalse5.04.0
572024_in_spaceflight.md12#### Human spaceflight#### Human spaceflight\\n\\nOn 4 February, Russi...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN653FalseFalse18.017.0
582024_in_spaceflight.md13##### Private human spaceflight and space tourism##### Private human spaceflight and space tour...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN3439FalseFalse19.019.0
592024_in_spaceflight.md14#### Rocket innovation#### Rocket innovation\\n\\nThe maiden flight of...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN1036FalseFalse31.023.0
602024_in_spaceflight.md15#### Satellite technology#### Satellite technology\\n\\nPlankton, Aerosol...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by reading through the provi...NaN5580FalseFalse20.015.0
612024_in_spaceflight.md16#### Launches from the Moon#### Launches from the Moon\\n\\nDate and time (...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN3388FalseFalse12.013.0
622024_in_spaceflight.md17#### Deep-space rendezvous#### Deep-space rendezvous\\n\\nDate (UTC) Spac...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by understanding the task. I...NaN5456FalseFalse24.026.0
632024_in_spaceflight.md18#### Extravehicular activities (EVAs)#### Extravehicular activities (EVAs)\\n\\nSee a...> URL Source: https://en.wikipedia.org/wiki/20...Article Summary:\\n> URL Source: https://en.wik...<answer>\\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe...Okay, let's start by analyzing the given text....NaN696FalseFalse32.025.0
\n", 1818 | "
" 1819 | ], 1820 | "text/plain": [ 1821 | " file chunk_index \\\n", 1822 | "0 2024_in_science.md 1 \n", 1823 | "1 2024_in_science.md 2 \n", 1824 | "2 2024_in_science.md 3 \n", 1825 | "3 2024_in_science.md 4 \n", 1826 | "4 2024_in_science.md 5 \n", 1827 | "5 2024_in_science.md 6 \n", 1828 | "6 2024_in_science.md 7 \n", 1829 | "7 2024_in_science.md 8 \n", 1830 | "8 2024_in_science.md 9 \n", 1831 | "9 2024_in_science.md 10 \n", 1832 | "10 2024_in_science.md 11 \n", 1833 | "11 2024_in_science.md 12 \n", 1834 | "12 2024_in_science.md 13 \n", 1835 | "13 2024_in_science.md 14 \n", 1836 | "14 2024_in_science.md 15 \n", 1837 | "15 2024_in_science.md 16 \n", 1838 | "17 2024_in_science.md 18 \n", 1839 | "19 2024_in_science.md 20 \n", 1840 | "21 2024_in_science.md 22 \n", 1841 | "22 2024_in_science.md 23 \n", 1842 | "23 2024_in_science.md 24 \n", 1843 | "24 2024_in_science.md 25 \n", 1844 | "25 2024_in_science.md 26 \n", 1845 | "26 2024_in_science.md 27 \n", 1846 | "27 2024_in_science.md 28 \n", 1847 | "28 2024_in_science.md 29 \n", 1848 | "30 2024_in_science.md 32 \n", 1849 | "31 year-in-review-the-biggest-climate-headlines-o... 1 \n", 1850 | "32 year-in-review-the-biggest-climate-headlines-o... 2 \n", 1851 | "33 year-in-review-the-biggest-climate-headlines-o... 3 \n", 1852 | "34 year-in-review-the-biggest-climate-headlines-o... 4 \n", 1853 | "35 year-in-review-the-biggest-climate-headlines-o... 5 \n", 1854 | "36 year-in-review-the-biggest-climate-headlines-o... 6 \n", 1855 | "37 year-in-review-the-biggest-climate-headlines-o... 7 \n", 1856 | "38 year-in-review-the-biggest-climate-headlines-o... 8 \n", 1857 | "40 year-in-review-the-biggest-climate-headlines-o... 10 \n", 1858 | "41 2024-wrapped-for-african-startups-a-year-of-gr... 0 \n", 1859 | "42 2024-wrapped-for-african-startups-a-year-of-gr... 2 \n", 1860 | "43 2024-wrapped-for-african-startups-a-year-of-gr... 3 \n", 1861 | "44 2024-wrapped-for-african-startups-a-year-of-gr... 4 \n", 1862 | "45 2024-wrapped-for-african-startups-a-year-of-gr... 5 \n", 1863 | "46 2024_in_spaceflight.md 1 \n", 1864 | "47 2024_in_spaceflight.md 2 \n", 1865 | "48 2024_in_spaceflight.md 3 \n", 1866 | "49 2024_in_spaceflight.md 4 \n", 1867 | "50 2024_in_spaceflight.md 5 \n", 1868 | "51 2024_in_spaceflight.md 6 \n", 1869 | "52 2024_in_spaceflight.md 7 \n", 1870 | "53 2024_in_spaceflight.md 8 \n", 1871 | "54 2024_in_spaceflight.md 9 \n", 1872 | "55 2024_in_spaceflight.md 10 \n", 1873 | "56 2024_in_spaceflight.md 11 \n", 1874 | "57 2024_in_spaceflight.md 12 \n", 1875 | "58 2024_in_spaceflight.md 13 \n", 1876 | "59 2024_in_spaceflight.md 14 \n", 1877 | "60 2024_in_spaceflight.md 15 \n", 1878 | "61 2024_in_spaceflight.md 16 \n", 1879 | "62 2024_in_spaceflight.md 17 \n", 1880 | "63 2024_in_spaceflight.md 18 \n", 1881 | "\n", 1882 | " heading \\\n", 1883 | "0 ### January \n", 1884 | "1 ### January \n", 1885 | "2 ### January \n", 1886 | "3 ### January \n", 1887 | "4 ### January \n", 1888 | "5 ### February \n", 1889 | "6 ### February \n", 1890 | "7 ### February \n", 1891 | "8 ### February \n", 1892 | "9 ### February \n", 1893 | "10 ### March \n", 1894 | "11 ### March \n", 1895 | "12 ### March \n", 1896 | "13 ### April \n", 1897 | "14 ### April \n", 1898 | "15 ### April \n", 1899 | "17 ### May \n", 1900 | "19 ### May \n", 1901 | "21 ### June \n", 1902 | "22 ### July \n", 1903 | "23 ### July \n", 1904 | "24 ### August \n", 1905 | "25 ### August \n", 1906 | "26 ### September \n", 1907 | "27 ### September \n", 1908 | "28 ### October \n", 1909 | "30 ### December \n", 1910 | "31 ### **1. 2024 ‘Virtually Certain’ to Be Hottes... \n", 1911 | "32 ### **2. COP29 Negotiators Finalize $300 Billi... \n", 1912 | "33 ### **3. Historic Global Growth of Renewables ... \n", 1913 | "34 ### **4. Disappointment Over COP16 Finance Dea... \n", 1914 | "35 ### **5. Ocean Warming Intensified Wind Speed ... \n", 1915 | "36 ### **6. Negotiators Fail to Agree on Global P... \n", 1916 | "37 ### **7. World on Track for 3.1C Warming, UN R... \n", 1917 | "38 ### **8. Mount Fuji Snowless in October For Fi... \n", 1918 | "40 ### **10. One in Five Migratory Species Threat... \n", 1919 | "41 Article Head \n", 1920 | "42 ### **The Rise of Local and Regional Investors** \n", 1921 | "43 ### **Lessons from Startup Closures** \n", 1922 | "44 ### **Opportunities for Growth: A Call to Acti... \n", 1923 | "45 ### **Looking Ahead: The Year 2025 Outlook** \n", 1924 | "46 ### 2024 in spaceflight \n", 1925 | "47 ### Overview \n", 1926 | "48 #### Astronomy and astrophysics \n", 1927 | "49 #### Exploration of the Solar System \n", 1928 | "50 #### Lunar exploration \n", 1929 | "51 ##### Artemis Program \n", 1930 | "52 ##### Peregrine \n", 1931 | "53 ##### SLIM \n", 1932 | "54 ##### Nova-C \n", 1933 | "55 ##### China Lunar Exploration Program \n", 1934 | "56 ##### Future \n", 1935 | "57 #### Human spaceflight \n", 1936 | "58 ##### Private human spaceflight and space tourism \n", 1937 | "59 #### Rocket innovation \n", 1938 | "60 #### Satellite technology \n", 1939 | "61 #### Launches from the Moon \n", 1940 | "62 #### Deep-space rendezvous \n", 1941 | "63 #### Extravehicular activities (EVAs) \n", 1942 | "\n", 1943 | " chunk_text \\\n", 1944 | "0 ### January\\n\\n- 2 January – The [Japan Meteor... \n", 1945 | "1 ](https://en.wikipedia.org/wiki/Extinction) of... \n", 1946 | "2 en.wikipedia.org/wiki/101955_Bennu), after thr... \n", 1947 | "3 -first_century.webp)[24 January](https://en.wi... \n", 1948 | "4 2024_in_science#cite_note-81)[[82]](https://en... \n", 1949 | "5 ### February\\n\\n- 2 February\\n - Scientists r... \n", 1950 | "6 .wikipedia.org/wiki/Mobile_phone).[[114]](http... \n", 1951 | "7 or pollution-mediated, deaths from automobili... \n", 1952 | "8 [prebiotic](https://en.wikipedia.org/wiki/Pre... \n", 1953 | "9 .wikipedia.org/wiki/2024_in_science#cite_note-... \n", 1954 | "10 ### March\\n\\n- 4 March\\n - Astronomers report... \n", 1955 | "11 (https://en.wikipedia.org/wiki/2024_in_science... \n", 1956 | "12 ://en.wikipedia.org/wiki/2024_in_science#cite_... \n", 1957 | "13 ### April\\n\\n- 1 April\\n - An entirely new cl... \n", 1958 | "14 en.wikipedia.org/wiki/Dsup).[[243]](https://en... \n", 1959 | "15 ater_pollution), finding many samples exceed P... \n", 1960 | "17 28jades4%29.jpg/220px-Webb_finds_most_distant_... \n", 1961 | "19 to 2016 (6 May),[[319]](https://en.wikipedia.... \n", 1962 | "21 longevity.[[339]](https://en.wikipedia.org/wi... \n", 1963 | "22 ### July\\n\\n- 2 July\\n - Two new [satellite g... \n", 1964 | "23 ://en.wikipedia.org/wiki/2024_in_science#cite_... \n", 1965 | "24 ### August\\n\\n- 1 August – A study in *[Nature... \n", 1966 | "25 RNA) lung cancer vaccine, begins a Phase I cli... \n", 1967 | "26 ### September\\n\\n- 4 September – The [ESA](htt... \n", 1968 | "27 ://en.wikipedia.org/wiki/2024_in_science#cite_... \n", 1969 | "28 ### October\\n\\n- 1 October – The [European Sou... \n", 1970 | "30 ### December\\n\\n- 5 December – A single mutati... \n", 1971 | "31 ### **1. 2024 ‘Virtually Certain’ to Be Hottes... \n", 1972 | "32 ### **2. COP29 Negotiators Finalize $300 Billi... \n", 1973 | "33 ### **3. Historic Global Growth of Renewables ... \n", 1974 | "34 ### **4. Disappointment Over COP16 Finance Dea... \n", 1975 | "35 ### **5. Ocean Warming Intensified Wind Speed ... \n", 1976 | "36 ### **6. Negotiators Fail to Agree on Global P... \n", 1977 | "37 ### **7. World on Track for 3.1C Warming, UN R... \n", 1978 | "38 ### **8. Mount Fuji Snowless in October For Fi... \n", 1979 | "40 ### **10. One in Five Migratory Species Threat... \n", 1980 | "41 Title: 2024 WRAPPED for African Startups: A Ye... \n", 1981 | "42 ### **The Rise of Local and Regional Investors... \n", 1982 | "43 ### **Lessons from Startup Closures**\\n\\nDespi... \n", 1983 | "44 ### **Opportunities for Growth: A Call to Acti... \n", 1984 | "45 ### **Looking Ahead: The Year 2025 Outlook**\\n... \n", 1985 | "46 ### 2024 in spaceflight\\n\\nIn 2024, saw new wo... \n", 1986 | "47 ### Overview\\n\\n \n", 1987 | "48 #### Astronomy and astrophysics\\n\\nOn New Year... \n", 1988 | "49 #### Exploration of the Solar System\\n\\nNASA's... \n", 1989 | "50 #### Lunar exploration\\n\\n \n", 1990 | "51 ##### Artemis Program\\n\\nIn November, stacking... \n", 1991 | "52 ##### Peregrine\\n\\nPeregrine lunar lander was ... \n", 1992 | "53 ##### SLIM\\n\\nSLIM achieved the first-ever lun... \n", 1993 | "54 ##### Nova-C\\n\\nIM-1 Nova-C Odysseus launched ... \n", 1994 | "55 ##### China Lunar Exploration Program\\n\\nMain ... \n", 1995 | "56 ##### Future\\n\\nDARPA provided funding towards... \n", 1996 | "57 #### Human spaceflight\\n\\nOn 4 February, Russi... \n", 1997 | "58 ##### Private human spaceflight and space tour... \n", 1998 | "59 #### Rocket innovation\\n\\nThe maiden flight of... \n", 1999 | "60 #### Satellite technology\\n\\nPlankton, Aerosol... \n", 2000 | "61 #### Launches from the Moon\\n\\nDate and time (... \n", 2001 | "62 #### Deep-space rendezvous\\n\\nDate (UTC) Spac... \n", 2002 | "63 #### Extravehicular activities (EVAs)\\n\\nSee a... \n", 2003 | "\n", 2004 | " article_summary \\\n", 2005 | "0 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2006 | "1 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2007 | "2 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2008 | "3 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2009 | "4 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2010 | "5 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2011 | "6 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2012 | "7 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2013 | "8 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2014 | "9 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2015 | "10 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2016 | "11 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2017 | "12 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2018 | "13 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2019 | "14 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2020 | "15 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2021 | "17 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2022 | "19 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2023 | "21 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2024 | "22 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2025 | "23 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2026 | "24 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2027 | "25 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2028 | "26 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2029 | "27 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2030 | "28 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2031 | "30 ## 2024 in science\\n\\n> URL Source: https://en... \n", 2032 | "31 Title: Year in Review: The Biggest Climate Hea... \n", 2033 | "32 Title: Year in Review: The Biggest Climate Hea... \n", 2034 | "33 Title: Year in Review: The Biggest Climate Hea... \n", 2035 | "34 Title: Year in Review: The Biggest Climate Hea... \n", 2036 | "35 Title: Year in Review: The Biggest Climate Hea... \n", 2037 | "36 Title: Year in Review: The Biggest Climate Hea... \n", 2038 | "37 Title: Year in Review: The Biggest Climate Hea... \n", 2039 | "38 Title: Year in Review: The Biggest Climate Hea... \n", 2040 | "40 Title: Year in Review: The Biggest Climate Hea... \n", 2041 | "41 Title: 2024 WRAPPED for African Startups: A Ye... \n", 2042 | "42 Title: 2024 WRAPPED for African Startups: A Ye... \n", 2043 | "43 Title: 2024 WRAPPED for African Startups: A Ye... \n", 2044 | "44 Title: 2024 WRAPPED for African Startups: A Ye... \n", 2045 | "45 Title: 2024 WRAPPED for African Startups: A Ye... \n", 2046 | "46 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2047 | "47 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2048 | "48 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2049 | "49 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2050 | "50 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2051 | "51 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2052 | "52 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2053 | "53 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2054 | "54 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2055 | "55 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2056 | "56 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2057 | "57 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2058 | "58 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2059 | "59 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2060 | "60 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2061 | "61 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2062 | "62 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2063 | "63 > URL Source: https://en.wikipedia.org/wiki/20... \n", 2064 | "\n", 2065 | " prompt \\\n", 2066 | "0 Article Summary:\\n\\n## 2024 in science\\n\\n> UR... \n", 2067 | "1 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2068 | "2 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2069 | "3 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2070 | "4 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2071 | "5 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2072 | "6 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2073 | "7 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2074 | "8 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2075 | "9 Article Summary:\\n\\n## 2024 in science\\n\\n> UR... \n", 2076 | "10 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2077 | "11 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2078 | "12 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2079 | "13 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2080 | "14 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2081 | "15 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2082 | "17 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2083 | "19 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2084 | "21 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2085 | "22 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2086 | "23 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2087 | "24 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2088 | "25 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2089 | "26 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2090 | "27 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2091 | "28 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2092 | "30 Article Summary:\\n## 2024 in science\\n\\n> URL ... \n", 2093 | "31 Article Summary:\\nTitle: Year in Review: The B... \n", 2094 | "32 Article Summary:\\nTitle: Year in Review: The B... \n", 2095 | "33 Article Summary:\\nTitle: Year in Review: The B... \n", 2096 | "34 Article Summary:\\nTitle: Year in Review: The B... \n", 2097 | "35 Article Summary:\\nTitle: Year in Review: The B... \n", 2098 | "36 Article Summary:\\nTitle: Year in Review: The B... \n", 2099 | "37 Article Summary:\\nTitle: Year in Review: The B... \n", 2100 | "38 Article Summary:\\nTitle: Year in Review: The B... \n", 2101 | "40 Article Summary:\\nTitle: Year in Review: The B... \n", 2102 | "41 Article Summary:\\nTitle: 2024 WRAPPED for Afri... \n", 2103 | "42 Article Summary:\\nTitle: 2024 WRAPPED for Afri... \n", 2104 | "43 Article Summary:\\nTitle: 2024 WRAPPED for Afri... \n", 2105 | "44 Article Summary:\\nTitle: 2024 WRAPPED for Afri... \n", 2106 | "45 Article Summary:\\nTitle: 2024 WRAPPED for Afri... \n", 2107 | "46 Article Summary:\\n> URL Source: https://en.wik... \n", 2108 | "47 Article Summary:\\n> URL Source: https://en.wik... \n", 2109 | "48 Article Summary:\\n> URL Source: https://en.wik... \n", 2110 | "49 Article Summary:\\n> URL Source: https://en.wik... \n", 2111 | "50 Article Summary:\\n> URL Source: https://en.wik... \n", 2112 | "51 Article Summary:\\n> URL Source: https://en.wik... \n", 2113 | "52 Article Summary:\\n> URL Source: https://en.wik... \n", 2114 | "53 Article Summary:\\n> URL Source: https://en.wik... \n", 2115 | "54 Article Summary:\\n> URL Source: https://en.wik... \n", 2116 | "55 Article Summary:\\n> URL Source: https://en.wik... \n", 2117 | "56 Article Summary:\\n> URL Source: https://en.wik... \n", 2118 | "57 Article Summary:\\n> URL Source: https://en.wik... \n", 2119 | "58 Article Summary:\\n> URL Source: https://en.wik... \n", 2120 | "59 Article Summary:\\n> URL Source: https://en.wik... \n", 2121 | "60 Article Summary:\\n> URL Source: https://en.wik... \n", 2122 | "61 Article Summary:\\n> URL Source: https://en.wik... \n", 2123 | "62 Article Summary:\\n> URL Source: https://en.wik... \n", 2124 | "63 Article Summary:\\n> URL Source: https://en.wik... \n", 2125 | "\n", 2126 | " api_output \\\n", 2127 | "0 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2128 | "1 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2129 | "2 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2130 | "3 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2131 | "4 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2132 | "5 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2133 | "6 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2134 | "7 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2135 | "8 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2136 | "9 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2137 | "10 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2138 | "11 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2139 | "12 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2140 | "13 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2141 | "14 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2142 | "15 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2143 | "17 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2144 | "19 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2145 | "21 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2146 | "22 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2147 | "23 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2148 | "24 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2149 | "25 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2150 | "26 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2151 | "27 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2152 | "28 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2153 | "30 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2154 | "31 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2155 | "32 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2156 | "33 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2157 | "34 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2158 | "35 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2159 | "36 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2160 | "37 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2161 | "38 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2162 | "40 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2163 | "41 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2164 | "42 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2165 | "43 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2166 | "44 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2167 | "45 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2168 | "46 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2169 | "47 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2170 | "48 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2171 | "49 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2172 | "50 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2173 | "51 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2174 | "52 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2175 | "53 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2176 | "54 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2177 | "55 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2178 | "56 \\n{\\n \"nodes\": [\\n {\\n \"id\": ... \n", 2179 | "57 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2180 | "58 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2181 | "59 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2182 | "60 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2183 | "61 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2184 | "62 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2185 | "63 \\n{\\n \"nodes\": [\\n {\"id\": 1, \"labe... \n", 2186 | "\n", 2187 | " thinking_process error \\\n", 2188 | "0 Okay, let's start by analyzing the given text.... NaN \n", 2189 | "1 Okay, let's start by analyzing the given text.... NaN \n", 2190 | "2 Okay, let's start by reading through the provi... NaN \n", 2191 | "3 Okay, let's start by reading through the provi... NaN \n", 2192 | "4 Okay, let's start by analyzing the given text.... NaN \n", 2193 | "5 Okay, let's start by analyzing the given text.... NaN \n", 2194 | "6 \\nOkay, let's tackle this problem step by step... NaN \n", 2195 | "7 Okay, let's start by analyzing the given text.... NaN \n", 2196 | "8 Okay, let's start by analyzing the given text.... NaN \n", 2197 | "9 Okay, let's start by analyzing the given text.... NaN \n", 2198 | "10 Okay, let's tackle this. The user provided a c... NaN \n", 2199 | "11 Okay, let's start by reading through the provi... NaN \n", 2200 | "12 Okay, let's start by analyzing the given text.... NaN \n", 2201 | "13 Okay, let's start by reading through the provi... NaN \n", 2202 | "14 Okay, let's start by analyzing the given text.... NaN \n", 2203 | "15 Okay, let's start by reading through the provi... NaN \n", 2204 | "17 Okay, let's start by reading through the provi... NaN \n", 2205 | "19 Okay, let's start by reading the provided text... NaN \n", 2206 | "21 Okay, let's start by analyzing the given text.... NaN \n", 2207 | "22 Okay, let's start by analyzing the given text.... NaN \n", 2208 | "23 Okay, let's start by analyzing the given text.... NaN \n", 2209 | "24 \\nOkay, let me try to figure out how to approa... NaN \n", 2210 | "25 Okay, let's start by analyzing the given text.... NaN \n", 2211 | "26 \\nAlright, I need to tackle this problem where... NaN \n", 2212 | "27 \\nAlright, let's try to tackle this. The user ... NaN \n", 2213 | "28 \\nAlright, let me start by understanding the p... NaN \n", 2214 | "30 \\nAlright, let's try to parse this out. First,... NaN \n", 2215 | "31 \\nOkay, let's start by reading through the giv... NaN \n", 2216 | "32 Okay, let's start by reading through the provi... NaN \n", 2217 | "33 \\nOkay, let's start by analyzing the given tex... NaN \n", 2218 | "34 Okay, let's start by reading through the provi... NaN \n", 2219 | "35 Okay, let's start by analyzing the given text.... NaN \n", 2220 | "36 Okay, let's start by analyzing the given text.... NaN \n", 2221 | "37 Okay, let's start by reading through the provi... NaN \n", 2222 | "38 Okay, let's start by analyzing the given text.... NaN \n", 2223 | "40 Okay, let's start by understanding the task. I... NaN \n", 2224 | "41 Okay, let's start by analyzing the given text.... NaN \n", 2225 | "42 Okay, let's start by understanding the task. I... NaN \n", 2226 | "43 Okay, let's start by analyzing the given text.... NaN \n", 2227 | "44 Okay, let's start by analyzing the given text.... NaN \n", 2228 | "45 Okay, let's start by analyzing the given text.... NaN \n", 2229 | "46 Okay, let's start by reading through the provi... NaN \n", 2230 | "47 Okay, let's tackle this problem. The user prov... NaN \n", 2231 | "48 Okay, let's start by reading through the provi... NaN \n", 2232 | "49 Okay, let's start by reading the provided text... NaN \n", 2233 | "50 \\nOkay, let's start by analyzing the user's re... NaN \n", 2234 | "51 Okay, let's start by analyzing the given text.... NaN \n", 2235 | "52 Okay, let's start by reading the provided text... NaN \n", 2236 | "53 Okay, let's start by reading through the provi... NaN \n", 2237 | "54 Okay, let's start by reading through the provi... NaN \n", 2238 | "55 Okay, let's start by reading through the provi... NaN \n", 2239 | "56 \\nOkay, let me parse the given text and figure... NaN \n", 2240 | "57 Okay, let's start by reading through the provi... NaN \n", 2241 | "58 Okay, let's start by reading through the provi... NaN \n", 2242 | "59 Okay, let's start by reading through the provi... NaN \n", 2243 | "60 Okay, let's start by reading through the provi... NaN \n", 2244 | "61 Okay, let's start by analyzing the given text.... NaN \n", 2245 | "62 Okay, let's start by understanding the task. I... NaN \n", 2246 | "63 Okay, let's start by analyzing the given text.... NaN \n", 2247 | "\n", 2248 | " thinking_process_token_count bad_reasoning bad_extraction node_count \\\n", 2249 | "0 1053 False False 25.0 \n", 2250 | "1 988 False False 34.0 \n", 2251 | "2 2919 False False 32.0 \n", 2252 | "3 4959 False False 36.0 \n", 2253 | "4 1368 False False 17.0 \n", 2254 | "5 2717 False False 28.0 \n", 2255 | "6 1085 False False 17.0 \n", 2256 | "7 3960 False False 30.0 \n", 2257 | "8 1963 False False 40.0 \n", 2258 | "9 5365 False False 33.0 \n", 2259 | "10 3930 False False 42.0 \n", 2260 | "11 2952 False False 38.0 \n", 2261 | "12 3805 False False 6.0 \n", 2262 | "13 2525 False False 38.0 \n", 2263 | "14 1559 False False 48.0 \n", 2264 | "15 3812 False False 14.0 \n", 2265 | "17 1324 False False 29.0 \n", 2266 | "19 2788 False False 12.0 \n", 2267 | "21 3744 False False 20.0 \n", 2268 | "22 752 False False 26.0 \n", 2269 | "23 1748 False False 10.0 \n", 2270 | "24 3852 False False 45.0 \n", 2271 | "25 3065 False False 17.0 \n", 2272 | "26 1157 False False 35.0 \n", 2273 | "27 5858 False False 22.0 \n", 2274 | "28 3137 False False 36.0 \n", 2275 | "30 1737 False False 37.0 \n", 2276 | "31 497 False False 25.0 \n", 2277 | "32 748 False False 9.0 \n", 2278 | "33 2219 False False 21.0 \n", 2279 | "34 1117 False False 13.0 \n", 2280 | "35 1272 False False 12.0 \n", 2281 | "36 1348 False False 15.0 \n", 2282 | "37 2165 False False 21.0 \n", 2283 | "38 1530 False False 9.0 \n", 2284 | "40 3206 False False 16.0 \n", 2285 | "41 3441 False False 6.0 \n", 2286 | "42 4431 False False 39.0 \n", 2287 | "43 1246 False False 11.0 \n", 2288 | "44 2194 False False 10.0 \n", 2289 | "45 1392 False False 10.0 \n", 2290 | "46 4076 False False 33.0 \n", 2291 | "47 1189 False False 5.0 \n", 2292 | "48 5416 False False 16.0 \n", 2293 | "49 2175 False False 10.0 \n", 2294 | "50 5616 False False 11.0 \n", 2295 | "51 540 False False 13.0 \n", 2296 | "52 1889 False False 8.0 \n", 2297 | "53 4511 False False 15.0 \n", 2298 | "54 3601 False False 10.0 \n", 2299 | "55 1178 False False 21.0 \n", 2300 | "56 1265 False False 5.0 \n", 2301 | "57 653 False False 18.0 \n", 2302 | "58 3439 False False 19.0 \n", 2303 | "59 1036 False False 31.0 \n", 2304 | "60 5580 False False 20.0 \n", 2305 | "61 3388 False False 12.0 \n", 2306 | "62 5456 False False 24.0 \n", 2307 | "63 696 False False 32.0 \n", 2308 | "\n", 2309 | " edge_count \n", 2310 | "0 17.0 \n", 2311 | "1 23.0 \n", 2312 | "2 21.0 \n", 2313 | "3 23.0 \n", 2314 | "4 12.0 \n", 2315 | "5 18.0 \n", 2316 | "6 14.0 \n", 2317 | "7 19.0 \n", 2318 | "8 23.0 \n", 2319 | "9 21.0 \n", 2320 | "10 30.0 \n", 2321 | "11 26.0 \n", 2322 | "12 5.0 \n", 2323 | "13 27.0 \n", 2324 | "14 33.0 \n", 2325 | "15 10.0 \n", 2326 | "17 16.0 \n", 2327 | "19 9.0 \n", 2328 | "21 12.0 \n", 2329 | "22 16.0 \n", 2330 | "23 8.0 \n", 2331 | "24 33.0 \n", 2332 | "25 13.0 \n", 2333 | "26 22.0 \n", 2334 | "27 15.0 \n", 2335 | "28 25.0 \n", 2336 | "30 27.0 \n", 2337 | "31 23.0 \n", 2338 | "32 10.0 \n", 2339 | "33 20.0 \n", 2340 | "34 13.0 \n", 2341 | "35 10.0 \n", 2342 | "36 12.0 \n", 2343 | "37 19.0 \n", 2344 | "38 9.0 \n", 2345 | "40 16.0 \n", 2346 | "41 8.0 \n", 2347 | "42 55.0 \n", 2348 | "43 11.0 \n", 2349 | "44 12.0 \n", 2350 | "45 9.0 \n", 2351 | "46 26.0 \n", 2352 | "47 4.0 \n", 2353 | "48 14.0 \n", 2354 | "49 10.0 \n", 2355 | "50 10.0 \n", 2356 | "51 14.0 \n", 2357 | "52 8.0 \n", 2358 | "53 19.0 \n", 2359 | "54 10.0 \n", 2360 | "55 25.0 \n", 2361 | "56 4.0 \n", 2362 | "57 17.0 \n", 2363 | "58 19.0 \n", 2364 | "59 23.0 \n", 2365 | "60 15.0 \n", 2366 | "61 13.0 \n", 2367 | "62 26.0 \n", 2368 | "63 25.0 " 2369 | ] 2370 | }, 2371 | "execution_count": 28, 2372 | "metadata": {}, 2373 | "output_type": "execute_result" 2374 | } 2375 | ], 2376 | "source": [ 2377 | "filtered_df" 2378 | ] 2379 | }, 2380 | { 2381 | "cell_type": "code", 2382 | "execution_count": 31, 2383 | "id": "52e4b28b-1b68-474b-859d-4955ee4f3e88", 2384 | "metadata": {}, 2385 | "outputs": [], 2386 | "source": [ 2387 | "data = filtered_df.to_dict(orient='records')" 2388 | ] 2389 | }, 2390 | { 2391 | "cell_type": "code", 2392 | "execution_count": 33, 2393 | "id": "a8f3add5-0ef6-456a-bbd5-8c8e6cb7196d", 2394 | "metadata": {}, 2395 | "outputs": [], 2396 | "source": [ 2397 | "dataset = []\n", 2398 | "\n", 2399 | "\n", 2400 | "SYSTEM_PROMPT = \"\"\"\n", 2401 | "Respond in the following format:\n", 2402 | "\n", 2403 | "...\n", 2404 | "\n", 2405 | "\n", 2406 | "...\n", 2407 | "\n", 2408 | "\"\"\"\n", 2409 | "\n", 2410 | "XML_COT_FORMAT = \"\"\"\\\n", 2411 | "\n", 2412 | "{reasoning}\n", 2413 | "\n", 2414 | "\n", 2415 | "{answer}\n", 2416 | "\n", 2417 | "\"\"\"\n", 2418 | "\n", 2419 | "for row in data:\n", 2420 | " # Use the prompt column from your CSV as the user prompt.\n", 2421 | " user_prompt = row[\"prompt\"]\n", 2422 | " # Use the thinking_process and api_output to create the ground-truth answer.\n", 2423 | " reasoning = row[\"thinking_process\"]\n", 2424 | " final_answer = extract_json_from_answer(row[\"api_output\"])\n", 2425 | " \n", 2426 | " # Format the ground-truth answer using the XML_COT_FORMAT.\n", 2427 | " ground_truth = XML_COT_FORMAT.format(reasoning=reasoning, answer=final_answer)\n", 2428 | " \n", 2429 | " # Create the training example with a list of messages.\n", 2430 | " dataset.append({\n", 2431 | " \"prompt\": [\n", 2432 | " {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n", 2433 | " {\"role\": \"user\", \"content\": user_prompt}\n", 2434 | " ],\n", 2435 | " \"answer\": ground_truth\n", 2436 | " })" 2437 | ] 2438 | }, 2439 | { 2440 | "cell_type": "code", 2441 | "execution_count": null, 2442 | "id": "a3b90181-947f-4a61-a8cc-6fa0204dfb55", 2443 | "metadata": {}, 2444 | "outputs": [], 2445 | "source": [] 2446 | } 2447 | ], 2448 | "metadata": { 2449 | "kernelspec": { 2450 | "display_name": "Python 3 (ipykernel)", 2451 | "language": "python", 2452 | "name": "python3" 2453 | }, 2454 | "language_info": { 2455 | "codemirror_mode": { 2456 | "name": "ipython", 2457 | "version": 3 2458 | }, 2459 | "file_extension": ".py", 2460 | "mimetype": "text/x-python", 2461 | "name": "python", 2462 | "nbconvert_exporter": "python", 2463 | "pygments_lexer": "ipython3", 2464 | "version": "3.12.7" 2465 | } 2466 | }, 2467 | "nbformat": 4, 2468 | "nbformat_minor": 5 2469 | } 2470 | --------------------------------------------------------------------------------