Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Easily turn large English text datasets into Japanese text datasets using open LLMs.

License

NotificationsYou must be signed in to change notification settings

llm-jp/text2dataset

Repository files navigation

pypi

Easily turn large English text datasets into Japanese text datasets using open LLMs.

Fig: Japanese translation of theAbirate/english_quotes dataset using thellm-jp/llm-jp-3-3.7b-instruct model.

Overview

text2dataset is a tool designed to convert datasets by translating the data in the "txt" column using an Open LLM, such as gemma2 with vLLM, and adding a new column called "txt_ja" that contains the translated text in Japanese.

By utilizing the fast LLM inference libraryvLLM, this tool enables the fast translation of large English datasets into Japanese.You can also use text2dataset for any translation tasks (e.g. paraphrase) by modifying the prompt template accordingly.

This tool is inspired byimg2dataset.

Features

  • Save the intermediate results in shards:
    • By setting thenumber_sample_per_shard parameter, the dataset can be saved in shards as specified by the number of samples per shard.
  • Resume from checkpoint:
    • By setting theresume_from_checkpoint parameter, the translation can be resumed from where it left off.
  • Logging with wandb:
    • By setting theuse_wandb parameter, the metrics such as examples_per_sec and count can be logged to wandb.
  • Push to Hugging Face Hub:
    • By setting thepush_to_hub parameter, the translated dataset can be pushed to the Hugging Face Hub.
  • Custom Prompt Template:
    • By specifying theprompt_template_path parameter, you can customize the prompt template for any translation task (e.g., paraphrasing, summarization etc.).

Installation

$ git clone https://github.com/llm-jp/text2dataset.git$cd text2dataset$ rye sync

Usage

Translation

$ python src/text2dataset/main.py \    --model_id llm-jp/llm-jp-3-3.7b-instruct \    --batch_size 16384 \    --input_path data/english_quotes.json \    --source_column text \    --target_column text_ja \    --push_to_hub True \    --push_to_hub_path speed/english_quotes_ja \    --output_dir data/english_quotes_ja \    --output_format json

Using thellm-jp/llm-jp-3-3.7b-instruct model on an A100 GPU, 2508 English quotes were translated into Japanese in just 21 seconds.

Fig: Japanese translation of theAbirate/english_quotes dataset using thellm-jp/llm-jp-3-3.7b-instruct model.

The result dataset is available atspeed/english_quotes_ja.

Paraphrasing

You can also use text2dataset to paraphrase texts by changing the prompt template with specifying theprompt_template_path parameter.

$ python src/text2dataset/main.py \    --model_id google/gemma-2-2b-it \    --batch_size 16384 \    --input_path data/english_quotes.json \    --source_column text \    --target_column text_paraphrase \    --push_to_hub True \    --push_to_hub_path speed/english_quotes_paraphrase \    --output_dir data/english_quotes_paraphrase \    --output_format json \    --prompt_template_path config/paraphrase.yaml

Fig: Paraphrase of theAbirate/english_quotes dataset using thegoogle/gemma-2-2b-it/ model.

The result dataset is available atspeed/english_quotes_paraphrase.

Translation ofneuralwork/arxiver dataset

You can directly translate datasets in Hugging Face by specifying the path name ininput_path.

In this example, theabstract column of theneuralwork/arxiver dataset is translated by specifying theinput_path asneuralwork/arxiver and thesource_column parameter asabstract.

$ python src/text2dataset/main.py \    --model_id google/gemma-2-2b-it \    --batch_size 16384 \    --input_path neuralwork/arxiver \    --source_column abstract \    --target_column abstract_ja \    --push_to_hub True \    --push_to_hub_path speed/arxiver_ja \    --output_dir data/arxiver_ja \    --output_format json \    --use_wandb True \    --wandb_run_name arxiver

neuralwork/arxiver dataset contains 138k rows of abstracts, and it took 2.5 hours to translate them into Japanese using thegoogle/gemma-2-2b-it model on a A100 GPU. The result dataset is available atspeed/arxiver_ja.

Fig: Translation of theneuralwork/arxiver dataset using thegoogle/gemma-2-2b-it/ model.

Fig: Wandb logs for the translation of theneuralwork/arxiver dataset using thegoogle/gemma-2-2b-it/ model.

Tips

  • Translation on Multiple GPUs in Parallel

To run translations on multiple GPUs concurrently, split the input dataset into several shards (directories) and execute the translation for each shard in parallel. Remember to set the gpu_id parameter to the corresponding GPU ID for each shard.

Areas for Improvement

Data Parallel Inference

Currently, we need to manually split the input dataset into shards and run the translation for each shard in parallel to utilize multiple GPUs. It would be great to have a built-in feature to automatically split the input dataset into shards and run the translation on multiple GPUs in parallel.If you have any ideas or suggestions, please feel free to open an issue or Pull Request.

Note

When using this tool, please pay attention to the license of both the dataset being translated and the LLM you use.

Development

Contribution

Welcome to any contributions!If you have any questions or suggestions, please feel free to open an issue or Pull Request.

PyPI Release

git tag -a v0.x.x -m"version 0.x.x"git push origin --tags

Lint and Format

$ rye lint$ rye format

References

About

Easily turn large English text datasets into Japanese text datasets using open LLMs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp