TDM

How to Translate or Summarize a Book with Claude AI and Its Anthropic API

A few months ago, I started translating a Chinese book using the OpenAI API, I talked about it here. Upon reviewing the translation, I noticed a few errors. Since the model I used at the time wasn’t precise enough, I tested the latest models from ChatGPT, ClaudeAI, and their corresponding APIs.

Book Translation

ChatGPT 4 and ClaudeAI Sonnet now offer high-quality translations, but the responses are always very short, and for an entire book, I need many “next” prompts to finish a chapter.

So I preferred to go through the API. I had to split the text into chunks of 3000 Chinese characters at a time, to get responses under 8192 tokens per request.

The code was written by AI. I only fix the code (in PHP) to get a command-line executable program. The downside of the code written by ClaudeAI is that it contains quite a few errors (algorithmic) that you need to know how to fix, and it doesn’t know that a new API model has been released, so it made me use claude-3-opus-20240229 at the beginning.

However, at first, Anthropic’s API, with the same prompt, doesn’t give at all the same response as Claude AI. I use claude-3-sonnet-20240229 for the Anthropic API and it has a lot of trouble understanding my prompt. I lengthen the prompt for the Anthropic API by giving it translation examples that I like, but the result still isn’t up to par with Claude AI. Despite many attempts, I can’t find a prompt that gives me the same result as Claude AI. Then I realize that I’m not using the most recent model. The most recent is claude-3-5-sonnet-20241022. From now on, to ensure I have the best version, I’ll use claude-3-5-sonnet-latest. As soon as I use the most recent model, the translation quality improves dramatically.

Between ChatGPT 4 and ClaudeAI Sonnet, I find ClaudeAI Sonnet’s translation more accurate, especially in understanding expressions and context. Between the OpenAI API and the Anthropic API, the Anthropic API also yields a better translation.

While translating over 700 pages in one go, I encountered two errors:

Error translating 48: API request failed with status code: 429. Response: {“type”:”error”,”error”:{“type”:”rate_limit_error”,”message”:”Number of tokens has exceeded your per-minute rate limit (https://docs.anthropic.com/en/api/rate-limits); see the response headers for current usage. Please reduce the prompt length or the maximum tokens requested, or try again later. You may also contact sales at https://www.anthropic.com/contact-sales to discuss your options for a rate limit increase.”}}

Error translating 235: API request failed with status code: 529. Response: {“type”:”error”,”error”:{“type”:”overloaded_error”,”message”:”Overloaded”}}

As a Tier 1, I hit the per-minute and per-day limits too quickly.

I had to modify the code to make a request every 7 seconds. Then I started the translation in the evening when Anthropic was overloaded, hence the 529 error. I changed the code to retry the translation of the text that failed up to 20 times max, and if it still failed, to save it in a separate file to complete the translation later.

Starting November 20, the limits will be separated by input tokens/output tokens.

Book Summarization

Now, I’m going to switch to French so you can better appreciate the responses. To compare, I sent the entire novel “The Alchemist” by Paulo Coelho in French to the Anthropic API and Claude AI. I use the following prompt for both:

I would like you to analyze this novel and give me a lengthy response. Structure your analysis according to the following points: Detailed chronological summary of the story. Include the major plot twists. Here is the novel to analyze:

Here is the response given by ClaudeAI:

I will analyze “The Alchemist” by Paulo Coelho in a structured manner.

DETAILED CHRONOLOGICAL SUMMARY:

  1. The beginning of the journey:
  • Santiago is a young Spanish shepherd who has the same dream twice about a treasure near the Egyptian pyramids.
  • He meets a gypsy woman who interprets his dream, then a mysterious king Melchizedek who encourages him to follow his “Personal Legend.”
  • The king gives him two divinatory stones, Urim and Thummim, and advises him to follow the omens.
  1. First step – Tangier:
  • Santiago sells his flock and leaves for Africa.
  • In Tangier, he gets all his money stolen
  • He finds work at a crystal merchant’s where he stays for almost a year
  • He modernizes the shop and makes the business thrive

1. The crossing of the desert:

  • He joins a caravan to cross the Sahara
  • He meets an Englishman who is searching for a legendary alchemist
  • They arrive at the oasis of Al-Fayoum where they must stop due to a tribal war

2. The oasis and the encounter with Fatima:

  • Santiago falls in love with Fatima, a woman of the oasis
  • He meets the Alchemist who agrees to guide him
  • Fatima encourages him to pursue his quest despite their love

3. The trials with the Alchemist:

  • The Alchemist becomes his mentor and teaches him the “Language of the World”
  • Santiago must prove his abilities by transforming into the wind before warriors
  • He succeeds in the trial thanks to his communion with the Universe

4. The end of the journey:

  • Santiago arrives at the pyramids and digs
  • He is attacked by bandits
  • One of the thieves inadvertently reveals to him that the treasure is actually in the abandoned church in Spain where it all began
  • He returns to Spain and finds the treasure

MAIN PLOT TWISTS:

  1. The initial theft that forces Santiago to rethink his strategy
  2. The discovery that the Alchemist lives in the oasis while the Englishman had been searching for him for years
  3. The warriors’ ultimatum that forces Santiago to transform into the wind
  4. The final revelation: the treasure was from the beginning where it all started, in the abandoned church in Spain
  5. The discovery that the journey itself was more important than the treasure, because it allowed him to:
  • Learn the “Language of the World”
  • Find love
  • Discover himself
  • Understand the secrets of spiritual Alchemy

The novel is structured as an initiatory quest where each step and each encounter contributes to the transformation of the main character. The true “treasure” is not so much the material gold as the wisdom and knowledge acquired during the journey.


And here is the answer given by the Anthropic API:

Here is a detailed chronological analysis of The Alchemist by Paulo Coelho:

CHRONOLOGICAL SUMMARY:

1. The beginning of the journey

  • Santiago is a young Spanish shepherd who has the same dream twice of a treasure hidden near the pyramids of Egypt
  • He meets a Gypsy woman who interprets his dream and tells him to seek his treasure
  • He encounters a mysterious king, Melchizedek, who encourages him to follow his “Personal Legend”
  • He sells his flock and leaves for Africa

2. The first trials

  • Arriving in Tangier, he gets all his money stolen
  • He finds work with a crystal merchant and stays there for nearly a year
  • He makes the business thrive and saves money

3. Crossing the desert

  • He joins a caravan to cross the Sahara
  • He meets an Englishman who is looking for an alchemist
  • They arrive at the oasis of Fayoum where Santiago meets Fatima, whom he falls in love with

4. Meeting the Alchemist

  • The Alchemist takes Santiago under his wing to teach him his secrets
  • Santiago learns to communicate with the desert and the elements
  • A major trial: he must turn into the wind to escape from warriors

5. The fulfillment

  • The Alchemist leaves Santiago near the pyramids
  • Santiago finds the treasure’s location but is attacked by thieves
  • One of the thieves inadvertently reveals that the treasure is actually buried in Spain
  • Santiago returns to Spain and discovers the treasure in the abandoned church where it all began

MAIN PLOT TWISTS:

  1. The theft of the money in Tangier that forces Santiago to work for the crystal merchant
  2. Meeting Fatima, which creates a dilemma: pursuing his quest or staying with her
  3. The appearance of the Alchemist, who becomes his spiritual guide
  4. The trial of turning into the wind, which represents Santiago’s spiritual fulfillment
  5. The final revelation that the treasure was in Spain all along, which gives full meaning to the initiatory journey

This narrative structure gradually evolves the hero through physical and spiritual trials, until a final revelation shows that the true treasure was the journey itself and the lessons learned.


Conclusion : You can see that the API’s response is of better quality than its ClaudeAI chat. However, that’s not how a human would have summarized the book, at least not me 😀

Usage and pricing

In terms of consumption, for the summary of the novel The Alchemist, the input tokens of 81050 correspond to the novel (41223 words or 233874 characters) + prompt
And the output token of 886 corresponds to the given response, containing just over 400 words. Knowing that the limit of Anthropic’s API is 8192 output tokens per request, I find the response much too short despite my request to provide a “long answer”.

Thus, a summary of The Alchemist cost me 26 cents (input + output).

Here are the current rates for Anthropic’s API (look at the “unit price” column):

You can see that it’s a bit more expensive than OpenAI gpt-4o currently:

I am, for now, impressed by the results given by the APIs. If Anthropic’s older models are disappointing, the new model claude-3-5-sonnet-20241022 is powerful and truly useful.

From now on, I use Claude Code, more info here, and and there

Comments Off on How to Translate or Summarize a Book with Claude AI and Its Anthropic API