1

我在python中使用markovify markov链生成器,当使用那里给出的示例代码时,它为我产生了很多重复的句子,我不知道为什么。

代码如下:

import markovify

# Get raw text as string.
with open("testtekst.txt") as f:
    text = f.read()

# Build the model.
text_model = markovify.Text(text)

# Print five randomly-generated sentences
for i in range(20):
    print(text_model.make_sentence())

这给了我以下输出:

Time included him on their list of the world's highest-paid athlete by ESPN from 2016 to 2019.
He assumed full captaincy of the world's most marketable and famous athletes, Ronaldo was named the best Portuguese player of all time by the Portuguese Football Federation.
The following year, he led Portugal to their first major tournament title at Euro 2004, where he helped Portugal reach the final.
The following year, he led Portugal to their first major tournament title at Euro 2004, where he helped Portugal reach the final.
He is the first footballer and the FIFA Club World Cup at age 23, he won his first season.
One of the tournament.
He also led them to victory in the world in 2014.
In 2015, Ronaldo was ranked the world's most famous athlete by ESPN from 2016 to 2019.
The following year, he led Portugal to their first major tournament title at Euro 2004, where he helped Portugal reach the final.
In 2015, Ronaldo was ranked the world's most famous athlete by ESPN from 2016 to 2019.
The following year, he led Portugal to their first major tournament title at Euro 2004, where he helped Portugal reach the final.
He is the first footballer and the FIFA Club World Cup at age 23, he won his first international goal at Euro 2004, where he helped Portugal reach the final.
The following year, he led Portugal to their first major tournament title at Euro 2004, where he helped Portugal reach the final.
One of the world's highest-paid athlete by ESPN from 2016 to 2019.
Time included him on their list of the national team in July 2008.
He is the first footballer and the FIFA Club World Cup at age 23, he won his first season.
Time included him on their list of the national team in July 2008.
He also led them to victory in the world in 2014.
The following year, he led Portugal to their first major tournament title at Euro 2004, where he helped Portugal reach the final.
One of the world's most marketable and famous athletes, Ronaldo was ranked the world's most famous athlete by Forbes in 2016 and 2017 and the FIFA Club World Cup at age 23, he won his first international goal at Euro 2016, and received the Silver Boot as top scorer of Euro 2020.

testtekst.txt 采用 ANSI 编码,具有以下语料库:

罗纳尔多在马德拉出生和长大,他的高级俱乐部生涯开始于葡萄牙体育,之后于 2003 年与曼联签约,年仅 18 岁,在他的第一个赛季就赢得了足总杯冠军。他还将在 23 岁时连续赢得三个英超联赛冠军,冠军联赛和 FIFA 俱乐部世界杯,他赢得了他的第一个金球奖。罗纳尔多在 2009 年以 9400 万欧元(8000 万英镑)的价格加盟皇家马德里时,成为当时最昂贵的足协转会对象,在那里他赢得了 15 个奖杯,包括两个西甲冠军、两个国王杯冠军和四次冠军联赛,并成为俱乐部历史上的最佳射手。他还三度获得金球奖亚军,仅次于莱昂内尔·梅西(他认为的职业对手),并在 2013 年和 2014 年连续赢得金球奖,2016 年和 2017 年又一次。2018 年,他以 1 亿欧元(8800 万英镑)的初始转会费加盟尤文图斯,这是意大利俱乐部最昂贵的转会,也是 30 岁以上球员最昂贵的转会。在 2021 年重返曼联之前,他赢得了两个意甲冠军、两个意大利超级杯和一个意大利杯冠军。2003 年,年仅 18 岁的罗纳尔多在葡萄牙完成了他的国家队处子秀,此后出场超过 180 次,使他成为葡萄牙最出色的球员。 - 封顶的球员。他在国际水平上打进了 100 多个进球,也是该国历史上的最佳射手。他参加了 11 场主要赛事并取得进球,他在 2004 年欧洲杯上打进了他的第一个国际进球,并帮助葡萄牙队打进了决赛。2008年7月担任国家队队长。2015年,罗纳尔多被葡萄牙足协评为有史以来最好的葡萄牙球员。次年,他带领葡萄牙队在 2016 年欧洲杯上获得了他们的第一个大满贯赛事冠军头衔,并获得了该赛事第二高射手的银靴奖。他还带领他们在 2019 年首届欧洲国家联赛中夺冠,随后获得了 2020 年欧洲杯最佳射手金靴奖。作为世界上最有市场和最著名的运动员之一,罗纳尔多被福布斯评为世界收入最高的运动员。 2016 年和 2017 年,以及 2016 年至 2019 年被 ESPN 评为世界上最著名的运动员。《时代》杂志将他列入了 2014 年全球 100 位最具影响力人物的名单。他是第一位足球运动员和第三位在其职业生涯中收入 10 亿美元的运动员。职业。次年,他带领葡萄牙队在 2016 年欧洲杯上获得了他们的第一个大满贯赛事冠军头衔,并获得了该赛事第二高射手的银靴奖。他还带领他们在 2019 年首届欧洲国家联赛中夺冠,随后获得了 2020 年欧洲杯最佳射手金靴奖。作为世界上最有市场和最著名的运动员之一,罗纳尔多被福布斯评为世界收入最高的运动员。 2016 年和 2017 年,以及 2016 年至 2019 年被 ESPN 评为世界上最著名的运动员。《时代》杂志将他列入了 2014 年全球 100 位最具影响力人物的名单。他是第一位足球运动员和第三位在其职业生涯中收入 10 亿美元的运动员。职业。次年,他带领葡萄牙队在 2016 年欧洲杯上获得了他们的第一个大满贯赛事冠军头衔,并获得了该赛事第二高射手的银靴奖。他还带领他们在 2019 年首届欧洲国家联赛中夺冠,随后获得了 2020 年欧洲杯最佳射手金靴奖。作为世界上最有市场和最著名的运动员之一,罗纳尔多被福布斯评为世界收入最高的运动员。 2016 年和 2017 年,以及 2016 年至 2019 年被 ESPN 评为世界上最著名的运动员。《时代》杂志将他列入了 2014 年全球 100 位最具影响力人物的名单。他是第一位足球运动员和第三位在其职业生涯中收入 10 亿美元的运动员。职业。

正如您在输出中看到的那样 - 打印了几个相同的句子,我不知道为什么。默认状态大小应为 2。

4

2 回答 2

1

答案是我的状态大小太大 - 将其设置为 1 后,它会产生独特的句子。我也不知道 Markovify 总是从语料库中句子的第一个单词开始生成新句子。

于 2021-12-02T16:54:15.550 回答
1

没错,Markovify 总是从语料库中句子的第一个词开始生成新句子。答案是您的州规模太大。你自己回答了。但是,你得到了一个很好的结果。我已经仔细阅读了关于罗纳尔多的文字。做得好

于 2021-12-02T16:58:55.623 回答