<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Jiajun's AI Notebook]]></title><description><![CDATA[Jiajun's AI Notebook]]></description><link>https://berkshirehathaway.ai</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 04:03:21 GMT</lastBuildDate><atom:link href="https://berkshirehathaway.ai/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Dissertation Content: What does the fixing of broken bridge have to do with Chinese Civil Service Examination system?]]></title><description><![CDATA[One of the most enduring historical puzzles in the history of the Chinese civil service examination system can be illuminated by my geographic analysis in Chapter 3, using the case of Fujian as a key example.
The Wanan Bridge—also known as the Luoyan...]]></description><link>https://berkshirehathaway.ai/dissertation-content-what-does-the-fixing-of-broken-bridge-have-to-do-with-chinese-civil-service-examination-system</link><guid isPermaLink="true">https://berkshirehathaway.ai/dissertation-content-what-does-the-fixing-of-broken-bridge-have-to-do-with-chinese-civil-service-examination-system</guid><dc:creator><![CDATA[Jiajun Zou]]></dc:creator><pubDate>Sat, 22 Mar 2025 06:46:47 GMT</pubDate><content:encoded><![CDATA[<p>One of the most enduring historical puzzles in the history of the Chinese civil service examination system can be illuminated by my geographic analysis in Chapter 3, using the case of Fujian as a key example.</p>
<p>The Wanan Bridge—also known as the Luoyang Bridge, shown below—was a vital infrastructural link connecting the southern and eastern regions of Fujian province. Eastern Fujian, home to the provincial capital Fuzhou, was the mandated site for provincial-level examinations over the past five centuries. By contrast, Southern Fujian—comprising today’s Quanzhou and Zhangzhou, also known as Minnan and the ancestral homeland of many Taiwanese—was notably underrepresented in the early Ming examination records, particularly before 1430.</p>
<p>What remains perplexing to historians is the sudden and sustained rise in examination success from Southern Fujian beginning in the mid-15th century, especially after 1500. Existing explanations tend to invoke vague notions: improved teaching quality, better schools, or general economic growth. Yet these arguments are based primarily on correlation rather than demonstrable causation, and none sufficiently explain the abrupt regional transformation.</p>
<p>The more plausible and empirically grounded explanation may lie in the repair and reopening of the Wanan Bridge. Once this critical piece of infrastructure was restored, access to the examination center in Fuzhou dramatically improved for residents of Southern Fujian. This facilitated a broader and more equitable participation in the provincial exams, which likely accounts for the region’s sudden academic ascendancy.</p>
<p>This temporal alignment between infrastructural development and examination success is unlikely to be coincidental—and Fujian is not the only province where such patterns emerge. This case underscores the power of a geographic framework to resolve long-standing historiographical ambiguities. It suggests that the rise of Southern Fujian was less about an intrinsic surge in intelligence or scholastic culture, and more about improved access: far more people were simply able to participate than in earlier decades.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742625627428/9928725c-0df8-454e-9931-5a968e8e5662.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742625578841/d5997e61-6ab9-48db-a7d4-3671ed6cc388.png" alt class="image--center mx-auto" /></p>
]]></content:encoded></item><item><title><![CDATA[AI Tips: Using Qwen-VL-Max for Chinese OCR of Classical Books]]></title><description><![CDATA[Most AI Models Struggle with OCR for Classical Chinese Texts—But Qwen VL Max Shows Promise
Optical Character Recognition (OCR) remains one of the most difficult tasks for AI when it comes to classical Chinese texts—especially those written in vertica...]]></description><link>https://berkshirehathaway.ai/ai-tips-using-qwen-vl-max-for-chinese-ocr-of-classical-books</link><guid isPermaLink="true">https://berkshirehathaway.ai/ai-tips-using-qwen-vl-max-for-chinese-ocr-of-classical-books</guid><dc:creator><![CDATA[Jiajun Zou]]></dc:creator><pubDate>Sat, 22 Mar 2025 06:28:47 GMT</pubDate><content:encoded><![CDATA[<p><strong>Most AI Models Struggle with OCR for Classical Chinese Texts—But Qwen VL Max Shows Promise</strong></p>
<p>Optical Character Recognition (OCR) remains one of the most difficult tasks for AI when it comes to classical Chinese texts—especially those written in vertical, top-to-bottom and right-to-left formats. This difficulty is further compounded when the source material is handwritten or uses classical fonts.</p>
<p>In China, several specialized OCR companies have emerged that focus specifically on classical Chinese prints. These firms often rely on proprietary models that deliver high accuracy, but their services can be quite costly. Based on my own experience, I’ve spent between $200 and $300 using one such provider.</p>
<p>Is there an alternative? Fortunately, the answer is yes—and potentially a game-changer. With recent advances in AI, models like <strong>Qwen VL Max</strong> are beginning to perform impressively in this niche domain. You can explore its capabilities on the official testing page: <a target="_blank" href="https://huggingface.co/spaces/Qwen/Qwen-VL-Max">https://huggingface.co/spaces/Qwen/Qwen-VL-Max</a></p>
<p>To illustrate, I tested the model on an image from the <strong>Chinese imperial civil service examination</strong>. While the model initially failed, it achieved near-perfect accuracy once prompted with clear instructions—specifically, to interpret the text vertically and read from right to left. This kind of instruction-based adaptability is crucial when working with complex historical texts.</p>
<p>I'm currently working on an automated solution to integrate Qwen’s OCR functionality via API, and I plan to publish the code on GitHub. However, it's worth noting that the Qwen API is currently not very accessible to users based in the United States, which could be a limitation for Western researchers.</p>
<p>Nevertheless, the potential here is enormous. A capable and low-cost alternative to traditional OCR services could significantly reduce the barrier to entry for digital humanities projects focused on Chinese history and literature.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742624787672/949feeee-e392-489c-a82e-049297c0f322.jpeg" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742624773631/74358f9f-7876-4e5a-a0b9-32a5b13f1d25.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742624778770/d1a5c994-a818-4ecc-a16e-d57133745980.png" alt class="image--center mx-auto" /></p>
]]></content:encoded></item><item><title><![CDATA[AI Tip: Is MiniMax the Next DeepSeek?]]></title><description><![CDATA[One of the most impressive AI developments to come out of China in recent memory was the release of DeepSeek’s Reasoning Model, which rattled the U.S. AI sector and even contributed to one of the most significant drawdowns in Nvidia’s stock price. De...]]></description><link>https://berkshirehathaway.ai/ai-tip-is-minimax-the-next-deepseek</link><guid isPermaLink="true">https://berkshirehathaway.ai/ai-tip-is-minimax-the-next-deepseek</guid><dc:creator><![CDATA[Jiajun Zou]]></dc:creator><pubDate>Sat, 22 Mar 2025 05:20:52 GMT</pubDate><content:encoded><![CDATA[<p>One of the most impressive AI developments to come out of China in recent memory was the release of <strong>DeepSeek’s Reasoning Model</strong>, which rattled the U.S. AI sector and even contributed to one of the most significant drawdowns in Nvidia’s stock price. DeepSeek’s success illustrates that China is not only a fast follower but also an emerging innovator in the foundational model space.</p>
<p>But while DeepSeek captured headlines, there may be another contender—<em>MiniMax</em>—poised to disrupt the AI landscape even further. Despite operating largely under the radar, MiniMax has made a bold claim: their model supports a <strong>4 million token context window</strong>. If true, this technological achievement could be far more consequential than many currently appreciate.</p>
<blockquote>
<p>🌐 <strong>Website</strong>: <a target="_blank" href="https://www.minimax.io">https://www.minimax.io</a></p>
</blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742620843945/6abe8d3c-2a3a-46e0-8bf9-dbb850b201b4.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-why-context-window-matters">Why Context Window Matters</h2>
<p>To appreciate the implications of a 4 million token context window, consider what that enables. A typical 400-page book is approximately 800,000 to 1 million tokens. MiniMax’s model, in theory, can process <strong>entire books, massive HTML structures, extensive code repositories, or large datasets</strong> in a single pass—without needing to chunk or truncate content.</p>
<p>This stands in stark contrast to Retrieval-Augmented Generation (RAG), which works by retrieving and injecting only a few relevant passages based on semantic similarity. While RAG is a powerful workaround, it has a key limitation: it can <strong>miss critical but non-obvious context</strong>. If a section of the source material is relevant but not semantically similar, RAG may never surface it.</p>
<p>By comparison, long-context models like MiniMax can ingest everything <em>up front</em>, ensuring <strong>contextually holistic understanding</strong>—especially useful when:</p>
<ul>
<li><p>Auditing the structure of a complex website</p>
</li>
<li><p>Analyzing long legal documents or academic papers</p>
</li>
<li><p>Reading and summarizing entire books</p>
</li>
<li><p>Reviewing multi-thousand-line codebases on GitHub</p>
</li>
</ul>
<p>With short context models, attention degrades over long sequences, and the model’s coherence drops. MiniMax avoids this pitfall by maintaining full attention across far larger token windows.</p>
<hr />
<h2 id="heading-early-impressions-of-minimax">Early Impressions of MiniMax</h2>
<p>MiniMax is not without trade-offs. Based on hands-on testing, its <strong>coding capabilities appear roughly on par with GPT-3.5</strong>, which is competent but not best-in-class. Moreover, its responses tend to be concise, even when fed large volumes of data. However, these shorter responses should not be confused with poor comprehension—the model clearly digests the content and provides coherent answers.</p>
<p>What MiniMax lacks in generative verbosity or top-tier reasoning (for now), it compensates for with <strong>unprecedented input capacity</strong>. In practical use cases—such as technical audits, deep document reviews, or learning how an entire system works—the ability to feed an entire context without summarization or segmentation can make a world of difference.</p>
<hr />
<h2 id="heading-looking-ahead-will-us-companies-catch-up">Looking Ahead: Will U.S. Companies Catch Up?</h2>
<p>MiniMax’s claim of a 4 million token window, if independently verified and scalable, represents a substantial leap forward. While OpenAI, Anthropic, Google, and Mistral have all pushed the context frontier recently, none have publicly achieved this scale.</p>
<p>The implications are profound. With long-context models, individual learners can study entire textbooks, reverse engineer codebases, or perform high-level analyses—<strong>at speed and depth never before possible</strong>. We could be on the verge of an explosion in autodidactic talent—individuals who learn by consuming vast technical materials directly through machines.</p>
<p>Whether American firms can match or exceed this development remains to be seen. But the direction is clear: context size is no longer just a technical specification—it is a <strong>defining competitive frontier</strong> in AI.</p>
]]></content:encoded></item><item><title><![CDATA[Dissertation Content: What Does China’s Diverse Topography Imply About Geographic Thesis for Civil Service Examination in Ming China?]]></title><description><![CDATA[Topography and Travel: Rethinking Transportation in Premodern China
For historians and enthusiasts of China’s geography and cultural history, traditional administrative maps can be deceptively simple. These maps often give the impression that travel ...]]></description><link>https://berkshirehathaway.ai/dissertation-content-what-does-chinas-diverse-topography-imply-about-geographic-thesis-for-civil-service-examination-in-ming-china</link><guid isPermaLink="true">https://berkshirehathaway.ai/dissertation-content-what-does-chinas-diverse-topography-imply-about-geographic-thesis-for-civil-service-examination-in-ming-china</guid><dc:creator><![CDATA[Jiajun Zou]]></dc:creator><pubDate>Sat, 22 Mar 2025 05:02:50 GMT</pubDate><content:encoded><![CDATA[<h3 id="heading-topography-and-travel-rethinking-transportation-in-premodern-china">Topography and Travel: Rethinking Transportation in Premodern China</h3>
<p>For historians and enthusiasts of China’s geography and cultural history, traditional administrative maps can be deceptively simple. These maps often give the impression that travel between regions in premodern China was primarily a matter of distance—one city to the next, measured in straight lines. However, when we overlay elevation data onto these maps, a far more complex and revealing picture emerges. The stark contrast between northern and southern China’s topography challenges that simplistic view and opens up deeper insights into how geography shaped historical development.</p>
<p>This elevation-based perspective offers explanatory power for several of China’s long-debated historical questions. One such case is the imperial examination system during the 15th century, a key institution in Chinese governance and social mobility. My dissertation argues that the success or failure of candidates across regions had less to do with innate ability or cultural investment in education, and far more to do with <strong>accessibility</strong>—specifically, the ease or difficulty of traveling to the examination capitals.</p>
<p>Regions with high success rates in the examinations often coincided with areas that had relatively flat terrain, navigable waterways, or direct routes to the capital cities where examinations were held. In contrast, those areas that produced very few successful candidates were typically isolated by natural barriers—rugged mountains, dense forests, or winding rivers that made multi-day travel arduous and expensive. These topographical constraints served as de facto filters, limiting participation not by merit, but by geography.</p>
<p>Take <strong>Fujian Province</strong> as a case study. Fujian is one of the most topographically challenging provinces in China, marked by steep mountains and a deeply indented coastline. Unsurprisingly, it also exhibits some of the most severe regional disparities in examination participation during the Ming dynasty. The vast majority of successful candidates came from coastal prefectures such as <strong>Fuzhou</strong> and <strong>Xinghua</strong>, both of which had relatively direct routes to the capital. In contrast, inland and southern areas of Fujian—though home to equally capable individuals—saw much lower levels of participation and success. The reason? Their mountainous terrain made travel to the examination centers logistically and physically prohibitive.</p>
<p>Below is a visualization of Fujian’s elevation profile. Due to image size constraints, only a few representative samples are shown, but the contrast is clear: coastal regions are low-lying and accessible, while the inland and western areas are mountainous and isolated.</p>
<ol>
<li><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742619186911/3c12dd0d-b599-4762-b019-c8f5af6a3a00.png" alt class="image--center mx-auto" /></p>
<ol start="2">
<li><p>Similarly, <strong>Zhejiang Province</strong> demonstrates a comparable pattern of geographic disparity in civil service examination outcomes. The <strong>southern and western regions</strong> of the province—characterized by rugged hills and complex river systems—produced <strong>negligible numbers of successful examination candidates</strong>. In contrast, the <strong>northeastern lowland areas</strong>, which are flatter, more accessible, and economically vibrant, saw a disproportionately high concentration of examination success.</p>
<p> This spatial inequality cannot be explained merely by population size or educational investment alone. While the northeastern region is indeed the most populous, what stands out is its <strong>geographic proximity to Renhe County</strong>—the provincial capital of Zhejiang during the Ming dynasty (modern-day Hangzhou). The correlation between low elevation, transport accessibility, and administrative centrality suggests that <strong>ease of travel, not just talent or ambition, played a defining role</strong> in determining who could realistically compete in the examination system.</p>
<p> This supports the broader thesis that the civil service examination system, though formally meritocratic, was in practice <strong>filtered through the lens of geography</strong>—privileging those regions with infrastructural and topographical advantages while marginalizing those hindered by natural barriers.</p>
</li>
</ol>
</li>
</ol>
<p>    <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742619286075/82673122-70b3-4faf-acff-5c8dfa81367f.png" alt class="image--center mx-auto" /></p>
<ol start="3">
<li><p>Rethinking Northern China's Examination Legacy: The Case of Shandong</p>
<p> Why, then, has <strong>northern China</strong> historically underperformed in the civil service examinations over the past five hundred years? A common—but deeply flawed—narrative attributes this to cultural, intellectual, or even economic inferiority compared to the south. These assumptions, unfortunately, are found not only in historical sources but are still echoed—often implicitly—by some modern historians.</p>
<p> However, such explanations collapse under closer geographic scrutiny.</p>
<p> Take <strong>Shandong Province</strong> as a representative case. Shandong, like much of northern China, is characterized by <strong>flat terrain</strong> and relatively easy transportation networks. Aside from some central highland regions—which predictably underperform in exam success due to their elevation—<strong>most of the province is open and well-connected</strong>, both in terms of physical geography and infrastructure.</p>
<p> This topography has significant implications: <strong>Shandong's examination winners are remarkably evenly distributed across the province</strong>. Unlike southern provinces where examination success is concentrated in specific lowland corridors, Shandong exhibits no such spatial clustering. This evenness reflects a basic geographic truth—<strong>when travel is easy, participation is democratized</strong>. Regardless of whether a candidate lived in the east, west, or coastal edge of the province, they had comparable access to the examination centers.</p>
<p> The implication is profound: <strong>it is geography—not culture, nor learning, nor some intrinsic intellectual quality—that shapes regional disparities in civil service examination success</strong>. This finding is supported by data and statistical modeling, yet remains underappreciated in the field of historical studies, which still leans heavily on humanistic narratives and source-based interpretations. These traditional approaches, while valuable, often carry embedded cultural biases that obscure structural explanations like geography.</p>
<p> Reframing the imperial examination system through the lens of <strong>topographical access</strong> helps us see regional inequality not as a reflection of human differences, but as a consequence of infrastructural and environmental constraints. It also challenges us to reconsider how we interpret historical outcomes: <strong>what appears to be meritocratic may, in fact, be geographically deterministic</strong>.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742619469629/199c7a46-7bcd-4210-b0af-50001328eeeb.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[AI Tip: How to do OCR using Gemni Vision Model]]></title><description><![CDATA[If you’re an academic who regularly works with printed sources, you know how crucial OCR (Optical Character Recognition) is. Whether you’re trying to make a scanned document searchable or feeding it into a more advanced RAG (Retrieval-Augmented Gener...]]></description><link>https://berkshirehathaway.ai/ai-tip-how-to-do-ocr-using-gemni-vision-model</link><guid isPermaLink="true">https://berkshirehathaway.ai/ai-tip-how-to-do-ocr-using-gemni-vision-model</guid><dc:creator><![CDATA[Jiajun Zou]]></dc:creator><pubDate>Sat, 22 Mar 2025 04:43:02 GMT</pubDate><content:encoded><![CDATA[<p>If you’re an academic who regularly works with printed sources, you know how crucial OCR (Optical Character Recognition) is. Whether you’re trying to make a scanned document searchable or feeding it into a more advanced RAG (Retrieval-Augmented Generation) system, the quality of the OCR makes or breaks the workflow.</p>
<p>Unfortunately, traditional tools like Adobe Acrobat or ABBYY FineReader often fall short—especially when high precision is needed. The good news? There are now two much more effective approaches that leave those legacy options behind.</p>
<p>In this post, we’ll explore the first of those: using <strong>Gemini’s vision model</strong> to achieve high-accuracy OCR that’s ready for modern research workflows.</p>
<p>To see the code depository, visit my github at <a target="_blank" href="https://github.com/jzou19957/Automatic_OCR_Through_Gemni_Vision">https://github.com/jzou19957/Automatic_OCR_Through_Gemni_Vision</a></p>
<p>Below is an instruction about how to use it:</p>
<h3 id="heading-how-to-use-automaticocrthroughgeminivision">📘 How to Use: <em>Automatic_OCR_Through_Gemini_Vision</em></h3>
<p>If you're a non-programmer looking for a convenient way to perform high-quality OCR on PDFs using Gemini’s Vision model, this tool is designed for you. Here's how to get started:</p>
<h4 id="heading-step-1-get-a-gemini-api-key">Step 1: Get a Gemini API Key</h4>
<ol>
<li><p>Visit the official Gemini API page:<br /> 👉 <a target="_blank" href="https://aistudio.google.com/app/apikey">https://aistudio.google.com/app/apikey</a></p>
</li>
<li><p><a target="_blank" href="https://aistudio.google.com/app/apikey">Request an API key by following</a> the instructio<a target="_blank" href="https://aistudio.google.com/app/apikey">ns on the page.</a></p>
</li>
</ol>
<blockquote>
<p><a target="_blank" href="https://aistudio.google.com/app/apikey">⚠️ <strong>Important Note</strong></a> <strong>on Billing:</strong><br />You can use the API for free without linking it to a billing account. However, in that case, requests will be much slower due to r<a target="_blank" href="https://aistudio.google.com/app/apikey">ate limits.<br />If you link the API key to a billing account, you'll get f</a>aster performance, but usage will incur aut<a target="_blank" href="https://aistudio.google.com/app/apikey">omatic charges.</a></p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742617851348/59183d04-8ec2-40e2-9f87-842308dce5a8.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p>To use the tool, simply <strong>replace the placeholder API key in the script</strong> with your own key, which you can obtain from:</p>
<p> 👉 <a target="_blank" href="https://aistudio.google.com/app/apikey">https://aistudio.google.com/app/apikey</a></p>
<blockquote>
<p><a target="_blank" href="https://aistudio.google.com/app/apikey">⚠️ <strong>Tip:</strong> If you're not linking to a</a> billing account, expect slower performance due to free-tier rate limits. For fa<a target="_blank" href="https://aistudio.google.com/app/apikey">ster results, linking a billing accoun</a>t will <a target="_blank" href="https://aistudio.google.com/app/apikey">automatically enable priority access—</a>but this will incur usage-based charges.</p>
</blockquote>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742617860960/3211e7e3-0ea6-4a46-8d49-4bc592261b6d.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p>To get started, place the <strong>PDF files</strong> you want to convert in the <strong>same folder</strong> as the Python script. For example, if you’re working with a book called <code>example_book.pdf</code>, your project directory should look something like this:</p>
<pre><code class="lang-plaintext"> bashCopyEdit/your-project-folder
 ├── example_book.pdf
 ├── Automatic_OCR_Through_Gemini_Vision.py
</code></pre>
<p> Once everything is in place, here’s what the code does under the hood:</p>
<ol>
<li><p><strong>PDF to Image Conversion:</strong><br /> The script uses the <strong>Pillow (PIL)</strong> library to split your PDF into individual page images. Each page is converted into a high-resolution <code>.png</code> or <code>.jpg</code> image—this prepares it for accurate OCR processing.</p>
</li>
<li><p><strong>OCR via Gemini Vision API:</strong><br /> Each image is then automatically sent to <strong>Google’s Gemini Vision model</strong> via API. The script processes the pages <strong>sequentially</strong>, ensuring that each page receives dedicated attention for optimal OCR accuracy.</p>
</li>
<li><p><strong>Markdown Output:</strong><br /> The text content extracted from each image is saved as individual <strong>Markdown (</strong><code>.md</code>) files—one per page. A <strong>combined Markdown file</strong> is also generated for easier full-text querying.</p>
</li>
</ol>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742617966054/96f13305-3036-4fdf-9c4d-68d997d1e8ef.jpeg" alt class="image--center mx-auto" /></p>
<h3 id="heading-running-the-code-in-visual-studio-code">▶️ Running the Code in Visual Studio Code</h3>
<ol>
<li><p>To run the tool, simply open the Python script in <strong>Visual Studio Code</strong> and execute it. The script is designed to be user-friendly and self-contained:</p>
<ul>
<li><p>It <strong>automatically installs all required dependencies</strong> on first run (no manual setup needed).</p>
</li>
<li><p>It <strong>converts the input PDF into OCR-ready content</strong> using high-accuracy image-to-text processing via the Gemini Vision API.</p>
</li>
<li><p>Each page of the PDF is:</p>
<ul>
<li><p>Converted to a high-resolution image,</p>
</li>
<li><p>Passed through the Gemini OCR model,</p>
</li>
<li><p>And saved as a <strong>Markdown (</strong><code>.md</code>) file.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<p>    The output includes:</p>
<ul>
<li><p><strong>One Markdown file per page</strong>, and</p>
</li>
<li><p><strong>A combined Markdown file</strong> containing the full content for convenience.</p>
</li>
</ul>
<p>    This process effectively creates a <strong>digitized, query-ready version of the book</strong> that’s ideal for:</p>
<ul>
<li><p>Full-text search,</p>
</li>
<li><p>Personal knowledge management systems,</p>
</li>
<li><p>Academic research, and</p>
</li>
<li><p><strong>RAG (Retrieval-Augmented Generation)</strong> pipelines.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[AI Tip: How to Get Claude to Continuously Write Long Code Using a System Prompt]]></title><description><![CDATA[When working with Claude Sonnet 3.5 for code generation, a common challenge arises: the model frequently exceeds the context window when producing long code. Once this happens, asking Claude to “fix” or “continue” the code often leads to an unexpecte...]]></description><link>https://berkshirehathaway.ai/ai-tip-how-to-get-claude-to-continuously-write-long-code-using-a-system-prompt</link><guid isPermaLink="true">https://berkshirehathaway.ai/ai-tip-how-to-get-claude-to-continuously-write-long-code-using-a-system-prompt</guid><dc:creator><![CDATA[Jiajun Zou]]></dc:creator><pubDate>Sat, 22 Mar 2025 04:07:31 GMT</pubDate><content:encoded><![CDATA[<p>When working with <strong>Claude Sonnet 3.5</strong> for code generation, a common challenge arises: the model frequently exceeds the context window when producing long code. Once this happens, asking Claude to “fix” or “continue” the code often leads to an unexpected outcome — it starts <strong>rewriting the entire codebase from scratch</strong>.</p>
<p>This behavior becomes especially frustrating when you're working with a large project, say 1000+ lines of code. Each time you try to continue, Claude may interpret your instruction as a cue to start over, causing you to get stuck in a never-ending loop of incomplete rewrites.</p>
<h3 id="heading-why-this-happens">Why This Happens</h3>
<p>This issue stems from the <strong>autocomplete-driven nature of language models</strong>. AI models like Claude operate by predicting the next most likely token in a sequence. When your prompt is too vague or lacks continuity cues, the model may default to restarting the task because that’s what it probabilistically deems appropriate in such contexts.</p>
<p>In essence, unless you’re <em>explicitly clear</em> in your instructions about what action the AI should take, it will often revert to the beginning — a behavior that makes large code completions impractical.</p>
<h3 id="heading-the-fix-use-a-persistent-system-prompt">The Fix: Use a Persistent System Prompt</h3>
<p>To overcome this, I created a <strong>system prompt</strong> designed to guide Claude’s behavior consistently throughout a session. This prompt can be pasted into a Claude project as a persistent instruction. Once in place, Claude will remember to <strong>continue editing the same code artifact</strong> instead of starting from scratch.</p>
<p>The result? You can now push through lengthy codebases — even those exceeding 1000 lines — with confidence that the model will build on the existing work rather than wipe it clean.</p>
<h3 id="heading-why-this-works">Why This Works</h3>
<p>The key insight is that <strong>AI models need explicit behavioral scaffolding</strong>. If you tell them, <em>“Continue editing the existing code rather than restarting,”</em> you influence the probability distribution of next-token predictions, steering the model toward iterative refinement rather than reset.</p>
<p>This subtle prompt engineering hack essentially exploits the model’s natural tendencies — helping you finish long code projects without interruption.</p>
<pre><code class="lang-plaintext">    &lt;Universal_System_Prompt_For_Full_Continuous_Code_Output&gt;
    &lt;Purpose&gt;Ensure all code requests are delivered in one single artifact, without abbreviation, omission, or placeholders.&lt;/Purpose&gt;
    &lt;Code_Generation_Rules&gt;
        &lt;Requirement&gt;Always provide the full, complete, executable and unabridged implementation in one artifact.&lt;/Requirement&gt;
        &lt;Requirement&gt;Include every function, every class, and every required component in full.&lt;/Requirement&gt;
        &lt;Requirement&gt;Provide the entire codebase in a single artifact. Do not split it across multiple responses.&lt;/Requirement&gt;
        &lt;Requirement&gt;Write the full implementation without omitting any sections.&lt;/Requirement&gt;
        &lt;Requirement&gt;Use a modular and structured format, but include all code in one place.&lt;/Requirement&gt;
        &lt;Requirement&gt;Ensure that the provided code is immediately executable without requiring additional completion.&lt;/Requirement&gt;
        &lt;Requirement&gt;All placeholders, comments, and instructions must be replaced with actual, working code.&lt;/Requirement&gt;
        &lt;Requirement&gt;If a project requires multiple files, simulate a single-file representation with inline comments explaining separation.&lt;/Requirement&gt;
        &lt;Requirement&gt;Continue the code exactly from where it left off in the same artifact.&lt;/Requirement&gt;
    &lt;/Code_Generation_Rules&gt;

    &lt;Strict_Prohibitions&gt;
        &lt;DoNotUse&gt;‘...rest of the code remains the same.’&lt;/DoNotUse&gt;
        &lt;DoNotUse&gt;Summarizing or omitting any function, event handler, or logic.&lt;/DoNotUse&gt;
        &lt;DoNotUse&gt;Generating partial code requiring user expansion.&lt;/DoNotUse&gt;
        &lt;DoNotUse&gt;Assuming the user will "fill in the gaps"—every detail must be included.&lt;/DoNotUse&gt;
        &lt;DoNotUse&gt;Splitting the code across responses.&lt;/DoNotUse&gt;
    &lt;/Strict_Prohibitions&gt;

    &lt;Execution_Requirement&gt;
        &lt;Instruction&gt;The generated code must be complete, standalone, and executable as-is.&lt;/Instruction&gt;
        &lt;Instruction&gt;The user should be able to run it immediately without modifications.&lt;/Instruction&gt;
    &lt;/Execution_Requirement&gt;
    &lt;/Universal_System_Prompt_For_Full_Continuous_Code_Output&gt;
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742616218180/1c8c56a4-dd33-4111-8316-6ce409c00a60.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742616228841/10c7a868-6361-49d0-b1aa-ed107d399eb0.png" alt class="image--center mx-auto" /></p>
]]></content:encoded></item></channel></rss>