{"id":21889468,"url":"https://github.com/darkalexwang/ai_couplet","last_synced_at":"2025-03-22T02:41:58.102Z","repository":{"id":91267725,"uuid":"425707091","full_name":"DarkAlexWang/ai_couplet","owner":"DarkAlexWang","description":"Machine Learning Trained Chinese Couplets / 用AI对对联","archived":false,"fork":false,"pushed_at":"2024-03-13T21:31:12.000Z","size":32530,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-26T20:46:44.873Z","etag":null,"topics":["couplet","encoder-decoder-attention","machine-learning","nlp","seq2seq","tensorflow2"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/DarkAlexWang.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":"2021-11-08T05:16:58.000Z","updated_at":"2024-02-29T04:57:00.000Z","dependencies_parsed_at":"2024-03-13T22:46:30.675Z","dependency_job_id":null,"html_url":"https://github.com/DarkAlexWang/ai_couplet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkAlexWang%2Fai_couplet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkAlexWang%2Fai_couplet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkAlexWang%2Fai_couplet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkAlexWang%2Fai_couplet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DarkAlexWang","download_url":"https://codeload.github.com/DarkAlexWang/ai_couplet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244898408,"owners_count":20528335,"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":["couplet","encoder-decoder-attention","machine-learning","nlp","seq2seq","tensorflow2"],"created_at":"2024-11-28T11:24:31.594Z","updated_at":"2025-03-22T02:41:58.080Z","avatar_url":"https://github.com/DarkAlexWang.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AI-couplet-writer\n\nWelcome! This is our fun project of using AI to write couplets (对对联). Please check out our website!\n\nhttps://ai-poet.com\n\n## Introduction\n- What is couplet (对联)\n  - Couplet is a two-liner poem with strict semantic and phoenetic rules\n  - See the [Wikipedia](https://en.wikipedia.org/wiki/Antithetical_couplet) (English) page for more details\n\n- What is this project for\n  - The model will predict the second line (下联) given the first line (上联)\n  - This project improves from similar ones (see Reference for their great work) on:\n    - This is the first of its kind written in TensorFlow 2, to the best of our knowledge\n    - This model improves from the reference models mostly on (i) emotional (意境) matching; (ii) repeated characters treatment (see the **Model** section below)\n\n## Examples\n\n|     Input     |     Output    |\n| ------------- | ------------- |\n| 欲把心事付瑶琴  |  且将笔墨书诗画  |\n| 半衾幽梦香初散  |  一曲清音韵未央  |\n| 应是飞鸿踏泥雪  |  何如落雁归故乡  |\n| 云破月来花弄影  |  雨停风送柳含烟  |\n| 别后相思空一水  |  愁中寂寞又几回  |\n| 书中自有黄金屋  |  笔下常留白玉簪  |\n| 花谢花飞花满天  |  鸟啼鸟语鸟鸣春  |\n| 杨柳岸晓风残月  |  芦苇春寒雨乱烟  |\n\n\n## Model\nThis is a sequence-to-sequence model with Encoder + Decoder + Attention, schematically shown as below.\n\n![The AI Couplet Model](/doc/schematics.png)\n\nNotable features\n- Embedding layer pretrained via Word2Vec\n- Beam search decoder\n- Format polishing to prevent repeated characters, etc.\n\n## Data \u0026 How to Run\n- Download the training data (~70k couplets) from [this](https://github.com/wb14123/couplet-dataset) repo\n- Set up the model hyperparameters and the file paths in the **baseconfig.ini**\n- Install the package dependencies\n  - **TensorFlow 2.7.0**\n  - Python 3.7.9\n  - Numpy 1.19.5\n  - Gensim 4.1.2\n  - Scikit-Learn 0.24.2\n- Train the model\n  - Run as ```python train.py```\n  - The model parameters will be written to the path set up in the config file\n  - Our model on the website was trained on Google Colab Pro for 12 epochs (~1 day)\n\n## Reference\n- Seq2seq-couplet by Bin Wang ([Github](https://github.com/wb14123/seq2seq-couplet), [website](https://ai.binwang.me/couplet))\n- Seq2seq chinese poetry generation by Simon and Vera ([Github](https://github.com/Disiok/poetry-seq2seq), [Related Paper](https://arxiv.org/abs/1610.09889))\n- Microsoft Research/微软亚洲研究院电脑对联系统 ([Website](https://duilian.msra.cn/app/couplet.aspx))\n- Open Couplet/中文对联AI ([Github](https://github.com/neoql/open_couplet), [Website](https://couplet.neoql.me/))\n- AICHPOEM.COM/诗三百-人工智能诗歌平台 ([Website](https://www.aichpoem.com/#/shisanbai/poem))\n- 清华九歌-人工智能诗歌写作系统 ([Website](http://jiuge.thunlp.org/jueju.html))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkalexwang%2Fai_couplet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarkalexwang%2Fai_couplet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkalexwang%2Fai_couplet/lists"}