Giter Site home page Giter Site logo

minaxixi / ai-couplet Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 5.0 77 KB

use an AI model to write couplet with TensorFlow 2 / 用AI对对联

Home Page: https://ai-poet.com

License: MIT License

Python 100.00%
couplet seq2seq-attn tensorflow2 poetry-generator seq2seq chinese-nlp nlp encoder-decoder-attention

ai-couplet's Introduction

AI-couplet-writer

Welcome! This is our fun project of using AI to write couplets (对对联). Please check out our website!

https://ai-poet.com

Introduction

  • What is couplet (对联)

    • Couplet is a two-liner poem with strict semantic and phoenetic rules
    • See the Wikipedia (English) page for more details
  • What is this project for

    • The model will predict the second line (下联) given the first line (上联)
    • We are a Chinese couple living in California and we love traditional Chinese poems!
    • This project improves from similar ones (see Reference for their great work) on:
      • This is the first of its kind written in TensorFlow 2, to the best of our knowledge
      • This model improves from the reference models mostly on (i) emotional (意境) matching; (ii) repeated characters treatment (see the Model section below)

Examples

Input Output
欲把心事付瑶琴 且将笔墨书诗画
半衾幽梦香初散 一曲清音韵未央
应是飞鸿踏泥雪 何如落雁归故乡
云破月来花弄影 雨停风送柳含烟
别后相思空一水 愁中寂寞又几回
书中自有黄金屋 笔下常留白玉簪
花谢花飞花满天 鸟啼鸟语鸟鸣春
杨柳岸晓风残月 芦苇春寒雨乱烟

Model

This is a sequence-to-sequence model with Encoder + Decoder + Attention, schematically shown as below.

The AI Couplet Model

Notable features

  • Embedding layer pretrained via Word2Vec
  • Beam search decoder
  • Format polishing to prevent repeated characters, etc.

Data & How to Run

  • Download the training data (~70k couplets) from this repo
  • Set up the model hyperparameters and the file paths in the baseconfig.ini
  • Install the package dependencies
    • TensorFlow 2.2.0
    • Python 3.6.9
    • Numpy 1.18.5
    • Gensim 3.6.0
    • Scikit-Learn 0.22.0
  • Train the model
    • Run as python train.py
    • The model parameters will be written to the path set up in the config file
    • Our model on the website was trained on Google Colab Pro for 12 epochs (~1 day)

Reference

  • Seq2seq-couplet by Bin Wang (Github, website)
  • Seq2seq chinese poetry generation by Simon and Vera (Github, Related Paper)
  • Microsoft Research/微软亚洲研究院电脑对联系统 (Website)
  • Open Couplet/中文对联AI (Github, Website)
  • AICHPOEM.COM/诗三百-人工智能诗歌平台 (Website)
  • 清华九歌-人工智能诗歌写作系统 (Website)

ai-couplet's People

Contributors

minaxixi avatar qile-paul-chen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.