{"id":31211530,"url":"https://github.com/cyberagentailab/regularized-bon","last_synced_at":"2025-09-21T05:30:45.993Z","repository":{"id":230886538,"uuid":"779956743","full_name":"CyberAgentAILab/regularized-bon","owner":"CyberAgentAILab","description":"Code of \"Regularized Best-of-N Sampling with Minimum Bayes Risk Objective for Language Model Alignment\" (2025).","archived":false,"fork":false,"pushed_at":"2025-04-04T04:05:14.000Z","size":57,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-10T07:42:49.454Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2404.01054","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/CyberAgentAILab.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-03-31T09:19:59.000Z","updated_at":"2025-04-04T04:05:17.000Z","dependencies_parsed_at":"2024-04-01T11:47:39.925Z","dependency_job_id":"e252d163-2155-4508-a504-65420ecbd084","html_url":"https://github.com/CyberAgentAILab/regularized-bon","commit_stats":null,"previous_names":["cyberagentailab/regularized-bon"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CyberAgentAILab/regularized-bon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberAgentAILab%2Fregularized-bon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberAgentAILab%2Fregularized-bon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberAgentAILab%2Fregularized-bon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberAgentAILab%2Fregularized-bon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CyberAgentAILab","download_url":"https://codeload.github.com/CyberAgentAILab/regularized-bon/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CyberAgentAILab%2Fregularized-bon/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276195627,"owners_count":25601152,"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","status":"online","status_checked_at":"2025-09-21T02:00:07.055Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-09-21T05:30:43.018Z","updated_at":"2025-09-21T05:30:45.981Z","avatar_url":"https://github.com/CyberAgentAILab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Regularized Best-of-N\n\nImplementation of [Regularized Best-of-N (RBoN)](https://arxiv.org/abs/2404.01054).\n\nThe code is tested on Ubuntu 20.04 using Python 3.8 and CUDA 11.0 (Docker image nvidia/cuda:11.0.3-cudnn8-devel-ubuntu20.04).\n\n\n```\ngit clone git@github.com:CyberAgentAILab/regularized-bon\ncd regularized-bon\npip install -r requirements.txt\n```\n\n## Usage\n\nRunning RBoN takes multiple steps. \n\n1. First you generate a set of responses using sample.sh. We use the same set of samples generated for all the algorithms for fair comparison.\n2. Compute Wasserstein distance and KL divergence using compute_wd.sh and compute_logprob.sh. \n3. Compute the reward of the responses.\n3. Run mbr/compute_rbon.py to compute MBR-BoN (RBoN-WD) and RBoN-KL.\n\nYou get the CSV file in the results/ directory.\n\n### Sampling candidates\n\nBy default, it runs using [openai-community/gpt2](https://huggingface.co/openai-community/gpt2). Add `-m [MODEL NAME IN HUGGINGFACE HUB]` to change the language model.\n\n```\n./experiments/sample.sh -d alpaca -s [NUMBER OF SAMPLES] \n```\n\nDue to the backward compatibility in my codebase, sample.py has to select a prompt file even for tasks like AlpacaFarm that don't have a prompt shared prompt for the task.\nTo this end, we have a [dummy.txt](https://github.com/CyberAgentAILab/regularized-bon/blob/master/prompts/dummy.txt) which is a blank file so that we can select this blank file to say that we don't have a shared prompt for the task.\n\n\n### Computing Wasserstein distance\n\n```\n./experiments/compute_wd.sh -d alpaca -s [NUMBER OF SAMPLES] \n```\n\n### Computing log probability\n\n```\n./experiments/compute_logprob.sh -d alpaca -s [NUMBER OF SAMPLES] \n```\n\n### Computing the reward of the samples\n\n```\n./experiments/compute_reward.sh -d alpaca -s [NUMBER OF SAMPLES] -i stanfordnlp/SteamSHP-flan-t5-large\n./experiments/compute_reward.sh -d alpaca -s [NUMBER OF SAMPLES] -i OpenAssistant/reward-model-deberta-v3-large-v2\n```\n\n\n### Computing MBR-BoN and RBoN_KL\n```\npython3 mbr/compute_rbon.py --dataset alpaca --ncandidates [NUMBER OF SAMPLES]\n```\n\n\n## Reference\n\nJinnai, Y., Morimura, T., Ariu, K., and Abe, K. Regularized Best-of-N Sampling with Minimum Bayes Risk Objective for Language Model Alignment. 2025.\n\nBibtex:\n```\n@misc{jinnai2025regularizedbestofnsamplingminimum,\n      title={Regularized Best-of-N Sampling with Minimum Bayes Risk Objective for Language Model Alignment}, \n      author={Yuu Jinnai and Tetsuro Morimura and Kaito Ariu and Kenshi Abe},\n      year={2025},\n      eprint={2404.01054},\n      archivePrefix={arXiv},\n      primaryClass={cs.CL},\n      url={https://arxiv.org/abs/2404.01054}, \n}\n```\n\n## Contact\nFor any questions, feel free to raise an issue or contact me at jinnai_yu@cyberagent.co.jp.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyberagentailab%2Fregularized-bon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcyberagentailab%2Fregularized-bon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyberagentailab%2Fregularized-bon/lists"}