最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

基于馬爾科夫鏈的隨機文章生成

2023-03-29 10:26 作者:Feishiko  | 我要投稿

這幾天在玩Caves of Qud,這是一個傳統(tǒng)Roguelike游戲,游戲的背景是末日后,人們用水作為一般等價物進行交易,同時用水進行水儀式,可以促進不同派系之間的好感度。游戲中的書本內(nèi)容是隨機生成的,聽群友說是隱馬爾科夫鏈,之后出于好奇自己搜了一些資料,并且嘗試用馬爾科夫鏈生成一些內(nèi)容,以下內(nèi)容是我基于自己寫的模型,并且用Soul Music作為語料庫生成的內(nèi)容:

You are certain if you can be an immortal and took the Death of his own, and took the Discworld, or Mort for the Discworld, on the Discworld, someone she'd known to become sixteen but she knew how to his own, and took the dimensions. But if it were, well, nothing against horses, or later had Eg and took the Death started to become real sorry. Or what, for the Death started to his home yet. Er. Got it!' he believed in the Discworld, or later and took the Discworld, on business of the Discworld, someone married then rolled up a story about sex and this much to become accustomed and took the dimensions. And another tooth.'

And then, eventually, and this shows that he later hired and this silliness.'

And another one, and this much can hardly existed at age of his own, once been then rolled his home between the Death sat under the Discworld, someone she'd already circling the Death which was probably safe from the Discworld, or Mort was an apprentice but it were, well, nothing here,' said that the dimensions. But first thing regardless then got up a story or Mort lost in the Death of his own, and still sitting there are interviewing or Mort was probably true. But the Discworld, or later take a story about memory. And then, in the Discworld, then said, ' I did Miss Butts shuffled the Death of his home between the dimensions. And another direction. His brow or later take a story but it is a story about sex and took her feel better. It doesn't take an apprentice then glanced at the Discworld, then said, rolling fields, and took the dimensions. But first thing regardless or later another river that you ran smoothly or later another direction.

看著像是一點都不正經(jīng)的胡說八道,不過如果你有需要生成一些胡說八道隨機文章的地方,這篇文章或許能幫助到你。

原理

馬爾科夫鏈,今天發(fā)生的事情只和昨天有關(guān)系,明天發(fā)生的事情只和今天有關(guān)系。比如現(xiàn)在只有一個詞I,然后I能和很多可能性的詞連接,比如and/am等等,假如我選擇and,那么現(xiàn)在的內(nèi)容就是I and,接著是and,能和and連接的詞比如有you/him/her,這時可能連接的詞和I就沒有任何關(guān)系了,然后假如我們選擇you,現(xiàn)在的內(nèi)容就是I and you,之后我們再去找可以和you連接的詞。

接著是語料庫的收集,要生成東西就需要一些原有的素材,比如有這樣一段話“I am Feishiko, I like play games.”,我們可以按空格拆分,讓這句話拆成I/am/Feishiko,/like/play/games.

然后輸入給我們的模型,以I為開頭,可能會生成:I like play games.

代碼

還是以lua為例,因為模型我是用lua寫的(

我們首先要創(chuàng)建一個函數(shù),我們需要一個文本源,用來生成語料庫,輸出多少個單詞,以及我們的第一個關(guān)鍵詞是什么。

下面我們要拆分出文本源的關(guān)鍵詞,并且把它傳給listKey這個table,也就是把所有單詞拆分成一個一維數(shù)組的一個個元素。

下面這段代碼用來把關(guān)鍵詞插入到一個新的table里面,相當(dāng)于其他語言的字典,key是一個字符串,value是一個數(shù)組,數(shù)組里的各個元素是可能與key連接的詞 (還是在這個函數(shù)里面寫代碼)

下面這段代碼用來基于剛才訓(xùn)練的語料庫生成文章

那么函數(shù)部分就寫好了,接下來需要把我們的文章傳進來

調(diào)用一下函數(shù)

重新整理一下,就是以下代碼:

你站什么時候支持支持markdown,在你站傳文章真是折磨

基于馬爾科夫鏈的隨機文章生成的評論 (共 條)

分享到微博請遵守國家法律
永川市| 宣威市| 常德市| 玉林市| 清苑县| 界首市| 田东县| 边坝县| 青龙| 金山区| 兰考县| 大竹县| 张掖市| 吉木乃县| 宝坻区| 稷山县| 闵行区| 上虞市| 庆元县| 四平市| 隆尧县| 竹北市| 洛浦县| 遵义县| 大埔区| 白银市| 南阳市| 东海县| 安国市| 江源县| 三江| 西乌珠穆沁旗| 三台县| 驻马店市| 保亭| 兴文县| 密山市| 神木县| 财经| 郸城县| 手机|