{"id":28163924,"url":"https://github.com/naidezhujimo/three-search-algorithms-based-on-prm","last_synced_at":"2025-05-15T11:15:04.671Z","repository":{"id":286370703,"uuid":"961211355","full_name":"naidezhujimo/Three-search-algorithms-based-on-PRM","owner":"naidezhujimo","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-06T02:19:19.000Z","size":220,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T03:20:12.259Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/naidezhujimo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-04-06T02:12:09.000Z","updated_at":"2025-04-06T02:19:22.000Z","dependencies_parsed_at":"2025-04-06T03:20:13.801Z","dependency_job_id":"66174675-4d35-4e19-a4aa-d23f9b3073e7","html_url":"https://github.com/naidezhujimo/Three-search-algorithms-based-on-PRM","commit_stats":null,"previous_names":["naidezhujimo/three-search-algorithms-based-on-prm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naidezhujimo%2FThree-search-algorithms-based-on-PRM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naidezhujimo%2FThree-search-algorithms-based-on-PRM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naidezhujimo%2FThree-search-algorithms-based-on-PRM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naidezhujimo%2FThree-search-algorithms-based-on-PRM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naidezhujimo","download_url":"https://codeload.github.com/naidezhujimo/Three-search-algorithms-based-on-PRM/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328395,"owners_count":22052634,"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":[],"created_at":"2025-05-15T11:14:47.307Z","updated_at":"2025-05-15T11:15:04.652Z","avatar_url":"https://github.com/naidezhujimo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Text Generation with MiniLM and Search Algorithms\n\nThis repository demonstrates text generation using a simple language model (MiniLM) combined with different search algorithms (Best-of-N, Beam Search, Lookahead Search) and a reward model (PRM). The implementation includes visualization of the search processes.\nThe associated mathematical formula can be found here:\n## Features\n\n- **MiniLM**: A lightweight language model with LSTM layers for sequence generation.\n- **PRM (Proximal Reward Model)**: A neural network that scores generated sequences based on learned rewards.\n- **Search Algorithms**:\n  - **Best-of-N Sampling**: Selects the best candidate from N generated samples.\n  - **Beam Search**: Maintains multiple top candidates during generation.\n  - **Lookahead Search**: Simulates future steps to optimize token selection.\n- **Visualization**: Generates PNG images showing search decision processes.\n\n## Requirements\n\n- Python 3.7+\n- PyTorch\n- NumPy\n- Matplotlib\n- NetworkX\n\nInstall dependencies:\n```bash\npip install torch numpy matplotlib networkx\n```\n\n## Code Structure\n\n- `MiniLM` class: Implements the language model.\n- `PRM` class: Implements the reward model.\n- Test functions:\n  - `test_prm_training()`: Trains the PRM model.\n  - `test_best_of_n()`: Demonstrates Best-of-N sampling.\n  - `beam_search()`: Visualizes beam search.\n  - `lookahead_search()`: Demonstrates multi-step lookahead.\n\n## Example Outputs\n\n![Best-of-N Sampling](best_of_n.png)  \n*Comparison of candidate tokens using PRM scores*\n\n![Beam Search Tree](beam_search_tree.png)  \n*Beam search visualization (width=2)*\n\n![Lookahead Search](lookahead_decision.png)  \n*Decision points in lookahead search (horizon=2)*\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request.\n\n\n## Blog\nhttps://blog.csdn.net/2303_79071981/article/details/147016903?spm=1001.2014.3001.5502\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaidezhujimo%2Fthree-search-algorithms-based-on-prm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaidezhujimo%2Fthree-search-algorithms-based-on-prm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaidezhujimo%2Fthree-search-algorithms-based-on-prm/lists"}