Notebooks
G
Google Gemini
Translate A Public Domain Book

Translate A Public Domain Book

gemini-cookbookgemini-apiexamplesgemini
Copyright 2025 Google LLC.
[ ]

Gemini API: Translate a public domain book

In this notebook, you will explore Gemini model as a translation tool, demonstrating how to prepare data, create effective prompts, and save results into a .txt file.

This approach significantly improves knowledge accessibility. Various sources provide open-source books. In this notebook, you will use Project Gutenberg as a resource.

This platform provides access to a wide range of books available for free download in PDF, eBook, TXT formats and more.

[1]
[2]

Configure your API key

To run the following cell, your API key must be stored in a Colab Secret named GOOGLE_API_KEY. If you don't already have an API key, or you're not sure how to create a Colab Secret, see Authentication for an example.

[3]

Data preparation

You will translate a well-known book written by Arthur Conan Doyle from Polish (trans. Eugenia Żmijewska) to English about the detective Sherlock Holmes. Here are the titles in Polish and English:

  • Polish Title: Tajemnica Baskerville'ów: dziwne przygody Sherlocka Holmes

  • English Title: The Hound of the Baskervilles

[4]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  277k  100  277k    0     0   324k      0 --:--:-- --:--:-- --:--:--  324k
[5]

Books contain all sorts of fictional or historical descriptions, some of them rather literal and might cause the model to stop from performing translation query. To prevent some of those exceptions users are able to change safety_setting from default to more open approach.

[6]

Go ahead and initialize the Gemini Flash model for this task.

[7]
MODEL_ID

Begin by counting how many tokens are in the book to know if you need to proceed with the next step (split text into smaller chunks).

Token Information

LLMs are constrained by token limits. In order to stay within the limit of Gemini Flash, it's important to ensure the following:

  • Input token limit should not exceed: 1,048,576 tokens
  • Output token limit should not exceed: 8,192 tokens

Since input chunks of post-translation text will serve as outputs, it's advisable to split them into smaller segments.

As you will see in the example, there are over 1000 small chunks. Calling API for the token count of each one would take a long time. Because of this estimate 1 token is equal to 4 characters will be used.

To account for the possible miscalculation of tokens and output potentially being longer than input each chunk will use up to 4*5000 characters. Remember to adjust the maximum to your needs.

For more details on tokens in Gemini models, refer to the documentation here.

Split text into chunks

Adjust the number of whitespace characters used for splitting based on the book you are working with.

Then, ensure to consider token limitations to receive complete responses from the model.

[8]
Number of chunks: 1802
[9]
[134.5, 16.25, 6.5, 7.25, 25.0, 4.0, 58.25, 26.0, 50.25, 148.0, 10.25, 11.0, 7.5, 8.5, 10.0, 9.5, 9.25, 7.75, 9.25, 9.5, 7.25, 11.25, 0.75, 5.0, 136.75, 22.25, 37.0, 12.5, 73.25, 45.0, 11.5, 24.25, 8.5, 45.5, 11.75, 31.75, 50.0, 48.0, 45.25, 22.0, 38.25, 52.25, 6.75, 6.25, 3.75, 54.25, 19.5, 15.75, 24.25, 45.25, 4.5, 152.75, 22.0, 72.0, 135.0, 91.5, 9.75, 53.5, 38.0, 5.25, 120.0, 128.0, 37.5, 9.25, 3.5, 10.25, 15.75, 11.25, 15.5, 27.75, 31.25, 16.5, 13.75, 10.25, 73.25, 44.5, 66.0, 13.5, 28.0, 11.25, 43.0, 33.5, 1.0, 7.5, 14.5, 17.5, 6.25, 5.5, 4.0, 78.5, 16.5, 9.0, 111.0, 17.75, 35.75, 34.5, 15.5, 21.0, 30.5, 57.5, 33.75, 21.75, 158.75, 60.5, 39.0, 110.0, 125.75, 124.5, 66.0, 55.75, 40.25, 63.0, 54.5, 84.75, 45.0, 33.5, 90.5, 138.25, 37.75, 10.0, 38.75, 5.5, 10.25, 12.25, 10.0, 66.0, 19.5, 125.75, 62.5, 50.25, 59.25, 44.5, 131.25, 65.75, 20.25, 9.0, 65.5, 32.0, 50.75, 52.75, 68.5, 60.25, 48.25, 54.25, 10.0, 15.5, 8.5, 92.75, 1.75, 17.0, 24.25, 150.75, 29.75, 106.75, 103.75, 76.25, 59.75, 44.75, 76.25, 126.25, 82.75, 5.0, 1.75, 5.75, 21.25, 14.25, 1.25, 2.0, 26.0, 9.75, 14.75, 6.25, 2.25, 12.0, 31.5, 7.0, 18.75, 8.0, 1.75, 5.5, 7.25, 6.0, 1.75, 5.25, 28.0, 10.75, 14.75, 12.0, 8.0, 5.75, 2.25, 20.0, 14.75, 9.75, 12.75, 39.5, 9.75, 12.5, 5.25, 20.0, 9.0, 4.75, 5.5, 9.0, 1.75, 10.75, 10.0, 9.75, 5.75, 10.0, 22.25, 4.75, 12.25, 23.5, 15.0, 9.5, 83.25, 42.25, 6.5, 23.75, 18.25, 7.75, 9.25, 22.75, 3.5, 95.75, 16.75, 77.75, 88.75, 5.25, 10.25, 42.25, 7.0, 62.0, 10.25, 149.25, 15.25, 154.5, 9.0, 36.0, 10.5, 45.5, 70.75, 32.5, 2.75, 18.5, 10.75, 49.25, 6.5, 20.75, 30.75, 5.25, 9.25, 3.0, 7.25, 14.75, 8.0, 8.25, 78.5, 77.75, 81.5, 7.25, 8.0, 14.5, 8.25, 21.5, 12.25, 7.25, 2.25, 71.0, 9.0, 1.75, 8.25, 14.5, 3.75, 118.25, 6.0, 11.0, 15.75, 136.5, 11.5, 18.0, 20.25, 47.0, 6.0, 22.5, 3.5, 94.75, 9.0, 51.0, 10.0, 88.0, 0.75, 5.75, 51.0, 75.25, 15.25, 37.0, 24.75, 13.0, 62.0, 28.75, 20.5, 11.0, 35.5, 10.75, 31.25, 12.5, 20.75, 33.75, 25.5, 26.75, 33.0, 62.5, 3.5, 19.25, 7.75, 21.75, 64.25, 34.5, 22.25, 27.5, 23.0, 27.0, 40.25, 11.25, 40.0, 66.25, 20.25, 13.5, 61.75, 16.5, 23.5, 15.5, 6.5, 19.0, 198.25, 16.75, 34.75, 4.75, 140.75, 24.25, 24.5, 3.25, 10.5, 15.5, 10.25, 12.5, 9.75, 33.25, 19.5, 45.5, 15.75, 18.25, 17.25, 85.75, 20.0, 32.5, 36.25, 25.5, 22.75, 127.75, 26.75, 30.25, 17.0, 44.25, 5.25, 12.5, 26.75, 7.0, 39.5, 36.5, 70.25, 11.0, 5.5, 13.5, 16.75, 50.75, 12.0, 32.5, 124.25, 11.0, 53.25, 43.0, 21.5, 6.75, 4.75, 4.5, 88.75, 4.75, 113.25, 25.75, 119.25, 25.25, 44.5, 7.0, 19.25, 17.0, 28.5, 14.5, 29.5, 6.75, 22.75, 32.0, 31.5, 3.5, 8.75, 4.25, 19.5, 4.25, 39.75, 4.75, 38.75, 2.5, 151.25, 0.75, 4.25, 64.0, 15.25, 19.0, 15.25, 3.0, 47.25, 27.25, 23.5, 9.25, 16.5, 37.5, 26.25, 17.5, 11.0, 48.25, 28.5, 31.0, 6.0, 9.0, 9.25, 52.25, 11.75, 22.0, 27.25, 10.75, 28.0, 8.0, 16.5, 83.75, 35.25, 10.5, 2.25, 5.0, 101.25, 7.0, 5.75, 37.5, 22.25, 9.0, 4.5, 12.75, 4.25, 48.75, 2.75, 66.0, 25.5, 43.75, 31.75, 3.25, 19.25, 11.0, 10.75, 20.0, 7.5, 42.25, 6.75, 28.25, 3.75, 7.5, 8.75, 14.25, 38.75, 64.0, 56.5, 21.5, 54.25, 21.5, 16.75, 12.25, 89.0, 44.75, 8.0, 61.75, 12.5, 52.5, 11.0, 8.75, 27.0, 29.5, 34.25, 29.75, 9.5, 45.0, 10.0, 22.0, 25.5, 7.5, 22.0, 26.5, 10.25, 5.75, 15.75, 25.5, 88.25, 57.75, 18.75, 11.25, 12.25, 9.75, 21.0, 12.0, 31.25, 14.25, 25.75, 16.25, 71.75, 43.75, 20.0, 15.0, 24.5, 8.25, 42.5, 10.75, 37.0, 48.25, 5.0, 7.0, 6.0, 7.75, 1.75, 10.0, 14.75, 4.75, 28.75, 25.25, 1.75, 20.0, 97.5, 5.75, 128.75, 8.0, 1.75, 10.5, 7.75, 48.5, 4.75, 3.0, 7.75, 1.75, 22.5, 7.0, 8.0, 132.0, 1.0, 4.25, 47.0, 48.0, 12.25, 116.5, 17.5, 134.5, 8.0, 7.5, 11.5, 17.5, 20.0, 66.0, 12.75, 31.25, 44.75, 5.75, 41.25, 10.0, 35.75, 52.75, 26.25, 40.5, 90.5, 78.5, 9.25, 17.0, 36.75, 19.5, 35.0, 66.0, 48.75, 72.5, 19.25, 16.75, 14.5, 9.25, 44.5, 24.0, 27.75, 4.75, 19.25, 71.25, 39.0, 70.0, 8.75, 18.75, 41.75, 32.0, 11.25, 19.0, 50.25, 20.75, 30.5, 18.5, 36.25, 24.5, 9.75, 49.5, 20.0, 64.5, 50.25, 34.75, 26.75, 11.75, 3.25, 38.25, 7.25, 39.75, 46.75, 17.5, 49.25, 6.75, 35.5, 73.0, 112.25, 39.5, 28.25, 70.5, 67.5, 16.75, 34.5, 40.0, 1.25, 6.75, 61.25, 60.75, 22.5, 32.0, 18.0, 12.0, 32.0, 35.0, 7.0, 46.5, 31.75, 105.75, 43.0, 35.5, 32.75, 26.5, 4.5, 29.5, 3.5, 8.0, 34.75, 8.0, 13.0, 15.5, 43.25, 53.75, 15.0, 37.0, 41.75, 13.25, 34.75, 23.25, 25.5, 58.0, 72.0, 31.75, 35.5, 4.0, 67.75, 6.75, 20.0, 3.25, 28.25, 25.5, 29.0, 4.25, 55.25, 9.0, 10.25, 22.25, 10.25, 9.75, 16.5, 37.0, 98.25, 11.5, 10.0, 21.5, 55.75, 23.5, 44.25, 36.5, 29.25, 64.25, 67.75, 5.0, 77.75, 10.75, 32.75, 11.75, 27.75, 7.0, 6.0, 112.5, 40.0, 30.5, 13.0, 16.5, 10.75, 38.0, 4.25, 8.0, 40.5, 8.75, 23.5, 13.75, 12.5, 7.5, 36.5, 12.0, 30.75, 16.5, 10.75, 16.5, 1.75, 41.0, 15.75, 24.5, 13.25, 7.5, 53.75, 4.5, 6.0, 6.0, 37.75, 29.75, 44.25, 219.5, 18.75, 18.5, 8.75, 39.75, 8.75, 91.0, 11.5, 12.0, 10.5, 20.25, 14.5, 20.0, 18.75, 6.0, 13.5, 20.75, 16.25, 9.75, 26.0, 34.5, 51.5, 67.5, 43.5, 12.75, 188.0, 26.75, 9.0, 75.0, 9.25, 58.5, 91.75, 40.0, 39.25, 53.75, 35.25, 115.0, 15.75, 112.25, 11.0, 8.0, 6.75, 45.25, 45.75, 16.25, 35.0, 80.0, 17.5, 1.5, 9.25, 41.5, 16.25, 34.75, 53.5, 65.25, 65.5, 57.25, 47.0, 83.0, 128.5, 148.0, 120.25, 92.5, 211.5, 40.25, 52.0, 39.5, 81.0, 127.5, 160.5, 17.75, 43.0, 111.25, 53.0, 29.0, 65.25, 14.0, 8.5, 23.75, 8.0, 9.5, 13.75, 26.75, 33.5, 111.25, 28.75, 10.0, 30.0, 88.5, 69.5, 49.0, 56.25, 21.25, 47.25, 60.0, 28.75, 1.0, 9.5, 4.5, 17.5, 4.0, 20.75, 86.25, 97.0, 41.5, 73.25, 21.75, 44.75, 32.25, 9.0, 38.25, 30.75, 23.0, 19.5, 48.25, 19.25, 34.25, 26.5, 16.75, 17.5, 19.25, 5.75, 30.75, 9.75, 61.0, 26.0, 22.75, 11.5, 12.75, 48.0, 35.75, 23.0, 8.75, 25.75, 65.25, 63.75, 21.5, 38.0, 53.0, 27.25, 19.75, 34.0, 21.75, 35.0, 44.25, 7.75, 13.25, 4.0, 10.25, 1.75, 80.0, 7.75, 50.0, 5.5, 241.0, 31.0, 30.5, 36.75, 34.0, 22.75, 54.5, 36.25, 30.5, 38.0, 48.0, 8.75, 216.5, 26.25, 34.75, 37.0, 27.25, 27.0, 39.25, 33.0, 36.75, 26.0, 16.75, 78.25, 39.75, 11.25, 5.0, 13.5, 27.25, 54.0, 12.75, 16.25, 6.75, 39.5, 19.5, 19.25, 51.0, 7.25, 25.25, 57.75, 12.75, 16.5, 11.25, 8.75, 37.0, 6.25, 25.0, 19.5, 36.5, 15.0, 51.5, 6.75, 10.75, 45.25, 16.0, 41.5, 272.75, 7.0, 13.5, 7.25, 28.0, 33.75, 19.75, 15.5, 10.0, 21.0, 27.0, 107.25, 16.0, 8.0, 47.25, 19.75, 35.0, 5.5, 8.5, 10.5, 26.5, 39.25, 69.5, 15.25, 24.0, 26.5, 15.25, 9.5, 19.5, 12.5, 7.75, 3.5, 15.0, 3.5, 22.75, 10.0, 32.75, 26.25, 40.75, 6.25, 87.75, 5.75, 17.75, 19.25, 4.5, 29.5, 49.5, 71.0, 8.75, 17.5, 71.5, 21.75, 52.75, 80.0, 32.5, 36.5, 62.0, 51.5, 67.0, 52.75, 42.25, 47.0, 59.5, 24.75, 21.75, 33.75, 59.75, 28.0, 41.0, 0.75, 9.0, 62.75, 16.75, 37.25, 45.75, 73.25, 70.0, 52.25, 20.25, 44.0, 25.0, 107.0, 68.0, 46.5, 51.5, 66.25, 37.75, 22.5, 64.75, 54.0, 14.25, 65.0, 60.0, 15.25, 5.25, 25.75, 18.75, 39.5, 14.5, 37.25, 41.0, 26.0, 57.0, 12.5, 13.5, 9.0, 3.0, 17.0, 5.25, 3.5, 6.0, 14.5, 7.0, 68.0, 3.0, 91.5, 9.0, 10.5, 17.75, 28.25, 9.75, 30.25, 18.75, 63.5, 13.0, 26.75, 10.0, 17.75, 13.25, 14.5, 64.75, 36.0, 21.75, 73.25, 16.75, 126.0, 55.75, 119.25, 13.5, 6.5, 17.75, 4.25, 69.25, 7.0, 7.0, 8.75, 48.75, 6.5, 92.25, 34.5, 126.0, 34.75, 40.25, 20.25, 27.5, 7.0, 18.0, 6.75, 14.25, 10.25, 13.5, 5.0, 4.75, 1.75, 5.0, 39.5, 29.5, 22.75, 29.25, 6.0, 52.25, 34.0, 49.5, 10.25, 25.5, 6.5, 25.25, 11.25, 79.0, 1.0, 9.25, 69.5, 81.0, 24.25, 60.0, 57.75, 79.0, 98.5, 14.75, 54.75, 19.75, 8.25, 20.0, 5.75, 32.0, 8.25, 9.5, 10.75, 30.0, 15.75, 12.75, 17.0, 23.5, 10.75, 1.75, 8.0, 29.0, 48.0, 7.5, 53.0, 25.0, 26.5, 6.5, 12.75, 9.5, 12.75, 15.25, 45.75, 52.5, 12.25, 16.25, 38.25, 62.75, 8.5, 42.0, 17.75, 23.25, 12.25, 6.5, 9.75, 29.75, 3.5, 13.25, 44.0, 4.0, 19.0, 85.0, 27.0, 19.0, 15.0, 9.25, 10.5, 50.5, 7.25, 18.0, 38.75, 3.25, 120.25, 13.25, 9.75, 13.25, 23.75, 43.5, 47.75, 56.0, 34.0, 35.5, 158.0, 33.5, 17.25, 42.5, 71.5, 7.0, 236.0, 50.0, 14.75, 24.5, 4.5, 12.25, 64.75, 8.0, 18.75, 16.75, 34.25, 68.5, 25.25, 72.25, 30.0, 87.25, 28.0, 57.75, 21.5, 32.75, 23.5, 15.5, 62.75, 11.5, 27.75, 28.75, 7.75, 46.5, 57.75, 24.5, 75.25, 218.25, 10.5, 61.25, 123.5, 81.0, 37.75, 31.75, 1.25, 4.25, 61.75, 6.5, 13.25, 71.0, 15.75, 9.5, 5.25, 51.0, 8.25, 92.25, 3.0, 47.5, 18.0, 41.5, 6.75, 21.75, 17.25, 35.0, 6.5, 28.5, 1.75, 10.25, 3.5, 30.25, 58.0, 7.5, 31.0, 157.25, 9.5, 99.5, 9.75, 6.75, 48.25, 36.25, 71.25, 36.75, 43.75, 4.5, 49.5, 2.0, 37.5, 19.5, 62.0, 6.5, 20.25, 42.0, 23.25, 10.0, 11.5, 19.5, 174.25, 20.0, 41.0, 10.25, 55.0, 11.25, 31.5, 4.75, 100.75, 14.0, 7.75, 16.25, 7.5, 15.75, 11.5, 14.75, 6.5, 22.25, 17.75, 37.25, 16.5, 40.0, 18.0, 11.5, 4.75, 9.25, 67.25, 31.5, 39.5, 16.5, 74.5, 52.0, 128.5, 70.25, 35.25, 9.5, 54.5, 6.75, 22.5, 19.0, 30.0, 28.75, 12.75, 6.5, 12.25, 37.25, 103.5, 78.25, 8.25, 57.75, 55.5, 22.5, 18.0, 58.25, 37.75, 51.75, 24.75, 8.75, 12.25, 37.0, 13.25, 29.0, 24.0, 12.5, 61.5, 8.0, 3.0, 7.25, 38.75, 9.0, 12.5, 86.25, 38.0, 10.75, 26.75, 41.25, 6.0, 4.75, 27.25, 53.75, 15.5, 42.0, 35.25, 64.75, 6.5, 15.5, 17.75, 45.25, 9.25, 85.5, 5.75, 33.0, 12.75, 113.5, 15.75, 64.75, 5.0, 22.5, 24.25, 7.5, 43.0, 4.5, 36.75, 1.5, 4.5, 94.25, 88.5, 15.25, 72.5, 34.0, 11.0, 35.5, 8.75, 74.0, 46.5, 39.5, 55.0, 21.25, 14.25, 12.25, 3.0, 35.5, 30.75, 11.25, 35.0, 65.75, 55.25, 60.5, 4.5, 7.25, 23.5, 11.5, 44.5, 14.75, 43.75, 12.0, 39.25, 22.25, 43.5, 19.5, 7.25, 61.75, 17.0, 14.0, 6.5, 23.25, 7.75, 11.25, 48.25, 26.5, 49.5, 8.25, 60.75, 11.5, 22.25, 27.75, 5.75, 68.25, 3.25, 10.0, 34.75, 11.25, 8.75, 12.5, 29.25, 11.0, 3.5, 14.5, 36.0, 65.0, 7.25, 24.0, 10.75, 53.75, 16.5, 23.0, 7.25, 32.5, 5.75, 1.75, 36.0, 39.25, 4.25, 29.75, 5.5, 21.0, 75.5, 40.5, 9.5, 54.5, 4.0, 11.5, 19.0, 21.25, 53.75, 47.0, 23.25, 6.5, 34.75, 50.25, 5.0, 52.25, 9.5, 66.75, 9.25, 7.5, 26.75, 24.25, 16.0, 20.0, 28.75, 137.5, 19.0, 137.5, 61.25, 5.0, 23.25, 3.5, 17.5, 47.5, 17.0, 1.75, 21.75, 33.5, 9.75, 8.0, 20.0, 43.75, 10.0, 132.0, 49.25, 8.25, 89.0, 1.25, 4.5, 110.25, 65.75, 52.5, 9.5, 35.25, 16.0, 5.25, 2.5, 32.0, 29.75, 14.25, 50.5, 4.0, 7.75, 6.5, 34.5, 23.25, 17.25, 58.25, 126.5, 14.25, 20.5, 7.75, 16.25, 37.25, 62.75, 115.0, 28.0, 8.75, 12.0, 45.75, 26.0, 9.75, 96.5, 69.75, 15.5, 58.25, 30.5, 34.0, 92.75, 34.5, 52.75, 10.5, 20.0, 39.75, 17.25, 5.5, 71.0, 6.25, 19.0, 28.75, 23.75, 23.0, 32.5, 15.0, 26.75, 26.75, 58.0, 59.0, 12.0, 20.0, 33.5, 21.0, 110.75, 33.5, 36.25, 3.75, 12.5, 6.0, 14.0, 1.75, 2.5, 3.0, 5.5, 17.5, 11.75, 48.5, 4.25, 35.5, 45.0, 7.75, 20.75, 8.75, 51.5, 45.0, 61.25, 42.75, 10.0, 36.25, 37.25, 47.5, 73.75, 59.5, 20.5, 12.25, 59.25, 90.25, 24.25, 57.5, 249.5, 1.0, 4.0, 62.5, 29.25, 70.75, 12.5, 235.5, 31.0, 111.75, 40.75, 73.0, 40.0, 133.25, 57.25, 66.75, 129.25, 93.0, 43.75, 54.75, 53.25, 39.5, 162.25, 20.75, 56.5, 64.0, 65.5, 39.5, 37.5, 27.25, 66.75, 65.25, 63.0, 75.0, 27.5, 105.25, 99.5, 73.0, 67.0, 25.25, 63.5, 88.5, 61.0, 47.5, 40.5, 36.75, 169.5, 89.5, 88.5, 80.75, 48.25, 30.75, 94.0, 30.25, 76.0, 120.75, 66.75, 9.25, 2.25, 7.5, 3.25, 67.5, 51.25, 8.25, 45.25, 120.25, 17.0, 10.5, 74.0, 15.5, 18.75, 25.25, 6.5, 9.5, 12.0, 28.0, 7.75, 16.0, 21.5, 26.25, 26.0, 21.25, 25.0, 23.25, 26.75, 20.25, 24.25, 24.75, 22.5, 23.5, 24.0, 25.0, 19.0, 21.75, 22.25, 16.5, 24.25, 23.0, 23.0, 19.0, 23.5, 31.25, 22.25, 17.5, 18.0, 24.75, 19.0, 25.5, 20.0, 25.25, 23.5, 17.25, 24.75, 21.25, 27.75, 17.0, 22.25, 21.25, 16.0, 24.5, 21.25, 18.5, 20.25, 19.5, 18.5, 1.0]

Identify the largest number of tokens in a chunk to check if any exceed your token limitations. In this case, the chunks are very small, so this should not be an issue.

If you encounter this problem, consider splitting the text into even smaller chunks.

[10]
272.75

Group smaller chunks together

As observed above, certain chunks contain very few tokens. While the LLM can translate these sentences accurately, providing larger context can enhance its understanding of the content.

Let's combine smaller chunks into larger ones for improved results.

[11]
13

The last step of splitting is checking if the non-estimated token counts are acceptable.

[12]
[6309, 6465, 6603, 6371, 6761, 6534, 6271, 7111, 6392, 6718, 6821, 5670, 3242]

Despite using estimates, this split minimizes the calls necessary to translate the book well, and most chunks are of similar token counts to each other.

Translation

Your book is ready for translations! The selected book has been divided into 13 larger chunks.

Prompt

Specify the original language of your book and the language you would like it to be translated into.

[13]

Translate chunks

The translation time depends on the amount of text being processed. Our selected book was 318 KB and the entire translation took 20 minutes.

Please note that larger texts may take several hours to complete.

[15]
100%|██████████| 13/13 [04:54<00:00, 22.64s/it]

All done, now you can print the chunk before and after translation to see the results.

You can see, that translation effectively maintains the narrative's novel quality, proper grammar and sentence structure.

Next step will be joining chunks together and saving the translated book.

[16]
[17]
[18]

Next steps

Now you know how to properly prepare data, check token limitations and translate each chunk to obtain your results. Feel free to try this process with a book that interests you!