{"id":17668359,"url":"https://github.com/jacoblincool/wft","last_synced_at":"2025-04-15T11:08:26.656Z","repository":{"id":259220476,"uuid":"877422658","full_name":"JacobLinCool/wft","owner":"JacobLinCool","description":"Run Whisper fine-tuning with ease—it works on MPS, CUDA, and CPU without code changes.","archived":false,"fork":false,"pushed_at":"2025-01-14T16:45:36.000Z","size":62,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T11:08:13.521Z","etag":null,"topics":["fine-tuning","whisper"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/wft","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JacobLinCool.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-23T16:11:58.000Z","updated_at":"2025-04-14T08:25:37.000Z","dependencies_parsed_at":"2024-10-23T16:36:41.054Z","dependency_job_id":"4ab3935b-c803-4621-9ef8-592b0039b1b4","html_url":"https://github.com/JacobLinCool/wft","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"5f018a75151bf4800e5f7082cb1e5d039c402865"},"previous_names":["jacoblincool/wft"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fwft","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fwft/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fwft/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fwft/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JacobLinCool","download_url":"https://codeload.github.com/JacobLinCool/wft/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249058370,"owners_count":21205910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fine-tuning","whisper"],"created_at":"2024-10-23T23:07:56.259Z","updated_at":"2025-04-15T11:08:26.649Z","avatar_url":"https://github.com/JacobLinCool.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🗣️ Whisper Fine-Tuning (WFT)\n\n**WFT** is a 🐍 Python library designed to streamline the fine-tuning process of 🤖 OpenAI's Whisper models on custom datasets. It simplifies 📦 dataset preparation, model 🛠️ fine-tuning, and result 💾 saving.\n\n## ✨ Features\n\n- **🤗 Hugging Face Integration**: Set your organization (or user) name, and everything syncs automatically to the 🤗 Hugging Face hub.\n- **📄 Easy Dataset Preparation and Preprocessing**: Quickly prepare and preprocess datasets for 🛠️ fine-tuning.\n- **🔧 Fine-Tuning Using LoRA (Low-Rank Adaptation)**: Fine-tune Whisper models with efficient LoRA techniques.\n- **⚙️ Flexible Configuration Options**: Customize various aspects of the fine-tuning process.\n- **📊 Evaluation Metrics**: Supports Character Error Rate (CER) or Word Error Rate (WER) for model evaluation.\n- **📈 TensorBoard Logging**: Track your training progress in real-time with TensorBoard.\n- **🤖 Automatic Model Merging and Saving**: Automatically merge fine-tuned weights and save the final model.\n- **🔄 Resume Training**: Resume training seamlessly from interrupted runs.\n\n## 🛠️ Installation\n\nInstall WFT using 🐍 pip:\n\n```bash\npip install wft\n```\n\n## 🚀 Quick Start\n\nFine-tune a Whisper model on a custom dataset with just a few steps:\n\n1. **🧩 Select a Baseline Model**: Choose a pre-trained Whisper model.\n2. **🎵 Select a Dataset**: Use a dataset that includes 🎧 audio and ✍️ transcription columns.\n3. **🏋️‍♂️ Start Training**: Use default training arguments to quickly fine-tune the model.\n\nHere's an example:\n\n```python\nfrom wft import WhisperFineTuner\n\nid = \"whisper-large-v3-turbo-zh-TW-test-1\"\n\nft = (\n    WhisperFineTuner(id)\n    .set_baseline(\"openai/whisper-large-v3-turbo\", language=\"zh\", task=\"transcribe\")\n    .prepare_dataset(\n        \"mozilla-foundation/common_voice_16_1\",\n        src_subset=\"zh-TW\",\n        src_audio_column=\"audio\",\n        src_transcription_column=\"sentence\",\n    )\n    .set_metric(\"wer\")\n    .train()  # Use default training arguments\n)\n```\n\nThat's it! 🎉 You can now fine-tune your Whisper model easily.\n\nTo enable 🤗 Hugging Face integration and push your training log and model to Hugging Face, set the `org` parameter when initializing `WhisperFineTuner`:\n\n```python\nid = \"whisper-large-v3-turbo-zh-TW-test-1\"\norg = \"JacobLinCool\"  # Organization to push the model to Hugging Face\n\nft = (\n    WhisperFineTuner(id, org)\n    .set_baseline(\"openai/whisper-large-v3-turbo\", language=\"zh\", task=\"transcribe\")\n    .prepare_dataset(\n        \"mozilla-foundation/common_voice_16_1\",\n        src_subset=\"zh-TW\",\n        src_audio_column=\"audio\",\n        src_transcription_column=\"sentence\",\n    )\n    .set_metric(\"wer\")\n    .train()  # Use default training arguments\n    .merge_and_push()  # Merge the model and push it to Hugging Face\n)\n```\n\nThis will automatically push your training logs 📜 and the fine-tuned model 🤖 to your Hugging Face account under the specified organization.\n\n## 📚 Usage Guide\n\n### 1️⃣ Set Baseline Model and Prepare Dataset\n\nYou can use a local dataset or a dataset from 🤗 Hugging Face:\n\n```python\nft = (\n    WhisperFineTuner(id)\n    .set_baseline(\"openai/whisper-large-v3-turbo\", language=\"zh\", task=\"transcribe\")\n    .prepare_dataset(\n        \"mozilla-foundation/common_voice_16_1\",\n        src_subset=\"zh-TW\",\n        src_audio_column=\"audio\",\n        src_transcription_column=\"sentence\",\n    )\n)\n```\n\nTo upload the preprocessed dataset to Hugging Face:\n\n```python\nft.push_dataset(\"username/dataset_name\")\n```\n\nYou can also prepare or load an already processed dataset:\n\n```python\nft = (\n    WhisperFineTuner(id)\n    .set_baseline(\"openai/whisper-large-v3-turbo\", language=\"zh\", task=\"transcribe\")\n    .prepare_dataset(\n        \"username/preprocessed_dataset\",\n        \"mozilla-foundation/common_voice_16_1\",\n        src_subset=\"zh-TW\",\n        src_audio_column=\"audio\",\n        src_transcription_column=\"sentence\",\n    )\n)\n```\n\n### 2️⃣ Configure Fine-Tuning\n\nSet the evaluation metric and 🔧 LoRA configuration:\n\n```python\nft.set_metric(\"cer\")  # Use CER (Character Error Rate) for evaluation\n\n# Custom LoRA configuration to fine-tune different parts of the model\nfrom peft import LoraConfig\n\ncustom_lora_config = LoraConfig(\n    r=32,\n    lora_alpha=16,\n    target_modules=[\"q_proj\", \"v_proj\"],\n    lora_dropout=0.05,\n    bias=\"none\",\n)\n\nft.set_lora_config(custom_lora_config)\n```\n\nYou can also set custom 🛠️ training arguments:\n\n```python\nfrom transformers import Seq2SeqTrainingArguments\n\ncustom_training_args = Seq2SeqTrainingArguments(\n    output_dir=ft.dir,\n    per_device_train_batch_size=8,\n    gradient_accumulation_steps=2,\n    learning_rate=1e-4,\n    num_train_epochs=3,\n)\n\nft.set_training_args(custom_training_args)\n```\n\n### 3️⃣ Train the Model\n\nTo begin 🏋️‍♂️ fine-tuning:\n\n```python\nft.train()\n```\n\n### 4️⃣ Save or Push the Fine-Tuned Model\n\nMerge 🔧 LoRA weights with the baseline model and save it:\n\n```python\nft.merge_and_save(f\"{ft.dir}/merged_model\")\n\n# Or push to Hugging Face\nft.merge_and_push(\"username/merged_model\")\n```\n\n## 🔬 Advanced Usage\n\n### 🔧 Custom LoRA Configuration\n\nAdjust the LoRA configuration to fine-tune different model parts:\n\n```python\ncustom_lora_config = LoraConfig(\n    r=32,\n    lora_alpha=16,\n    target_modules=[\"q_proj\", \"v_proj\"],\n    lora_dropout=0.05,\n    bias=\"none\",\n)\n\nft.set_lora_config(custom_lora_config)\n```\n\n### ⚙️ Custom Training Arguments\n\nSpecify custom 🛠️ training settings:\n\n```python\nfrom transformers import Seq2SeqTrainingArguments\n\ncustom_training_args = Seq2SeqTrainingArguments(\n    output_dir=ft.dir,\n    per_device_train_batch_size=8,\n    gradient_accumulation_steps=2,\n    learning_rate=1e-4,\n    num_train_epochs=3,\n)\n\nft.set_training_args(custom_training_args)\n```\n\n### 🔁 Run Custom Actions After Steps Using `.then()`\n\nAdd actions to be executed after each step:\n\n```python\nft = (\n    WhisperFineTuner(id)\n    .set_baseline(\"openai/whisper-large-v3-turbo\", language=\"zh\", task=\"transcribe\")\n    .then(lambda ft: print(f\"{ft.baseline_model=}\"))\n    .prepare_dataset(\n        \"mozilla-foundation/common_voice_16_1\",\n        src_subset=\"zh-TW\",\n        src_audio_column=\"audio\",\n        src_transcription_column=\"sentence\",\n    )\n    .then(lambda ft: print(f\"{ft.dataset=}\"))\n    .set_metric(\"cer\")\n    .then(lambda ft: setattr(ft.training_args, \"num_train_epochs\", 5))\n    .train()\n)\n```\n\n### 🔄 Resume Training From a Checkpoint\n\nIf training is interrupted, you can resume:\n\n```python\nft = (\n    WhisperFineTuner(id)\n    .set_baseline(\"openai/whisper-large-v3-turbo\", language=\"zh\", task=\"transcribe\")\n    .prepare_dataset(\n        \"mozilla-foundation/common_voice_16_1\",\n        src_subset=\"zh-TW\",\n        src_audio_column=\"audio\",\n        src_transcription_column=\"sentence\",\n    )\n    .set_metric(\"cer\")\n    .train(resume=True)\n)\n```\n\n\u003e **ℹ️ Note**: If no checkpoint is found, training will start from scratch without failure.\n\n## 🤝 Contributing\n\nWe welcome contributions! 🎉 Feel free to submit a pull request.\n\n## 📜 License\n\nThis project is licensed under the MIT License.\n\n## Why there are so many emojis in this README?\n\nBecause ChatGPT told me to do so. 🤖📝\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacoblincool%2Fwft","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacoblincool%2Fwft","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacoblincool%2Fwft/lists"}