Code Monkey home page Code Monkey logo

acrosticpoem's Introduction

簡介

本程式可以自動產生藏頭詩。

本程式以Ngram為語言模型,先從兩萬首全唐詩中算出Ngram的統計數值,再用Viterbi演算法拼湊出藏頭詩中的每個字, 得出的藏頭詩,看起來很像詩詞但語意未必通順。

##用法:

執行本程式需安裝python 2.7版本。

到終端機輸入以下指令啟動本程式:

> python AcrosticPoem.py

接著,輸入想要藏頭的字,例如:

> 藏頭詩自動產生器

則會產生出藏頭詩:

藏衱戎河泯 
頭夜浮梁買 
詩贈汨羅幃 
自將奈何之
動盈虛無邊
產遺鴛坡訇
生不重問客
器動如衫絹

參數設定:

> words [-h] [-l {5,7}] [-s SEED] [-v {simple,medium,hard}]
        [-p {1,2,3,4,5,6,lr,rl}]

###必要參數:

words, 想要藏頭的字

###其他參數 :

-h, --help, 顯示help

-l {5,7}, 每句幾個字(五言或七言)

-s SEED, 隨機種子

-v {simple,medium,hard}, 用詞深淺度(若選擇hard則會出現罕見字)

-p {1,2,3,4,5,6,lr,rl}, 藏字的位置(第幾個字,或左右斜下)

##範例:

例如,要產生七言的藏頭詩,藏在第三字,方法如下:

> 藏頭詩自動產生器 -l 7 -p 3

中行藏海山人人
時人頭花已自奔
君來詩酒聲入天
歸不自朝日無恩
鐘聲動日應不似
山陰產海月沉沉
竟不生欲何事空
禹廟器道今何紛

相關研究

1.由fumin所做的Neural Turing Machines可產生較符合語意的藏頭詩。

2.由XingxingZhang所做的rnnpg也是用RNN,但做出來的效果比fumin的更好。

2.若要產生有對偶句的藏頭詩,可參考以下兩篇研究論文,用統計式機器翻譯的演算法。

Ming Zhou, Long Jiang, Jing He: Generating Chinese Couplets and Quatrain Using a Statistical Approach. PACLIC 2009: 43-52

Long Jiang, Ming Zhou: Generating Chinese Couplets using a Statistical MT Approach. COLING 20

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.