python - 为什么我的马尔可夫链会从语料库中产生相同的句子?

标签 python markov-chains markov markov-models markov-decision-process

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

代码如下:

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 编码,具有以下语料库:

Born and raised in Madeira, Ronaldo began his senior club career playing for Sporting CP, before signing with Manchester United in 2003, aged 18, winning the FA Cup in his first season. He would also go onto win three consecutive Premier League titles, the Champions League and the FIFA Club World Cup at age 23, he won his first Ballon d'Or. Ronaldo was the subject of the then-most expensive association football transfer when he signed for Real Madrid in 2009 in a transfer worth €94 million (£80 million), where he won 15 trophies, including two La Liga titles, two Copa del Rey and four Champions Leagues, and became the club's all-time top goalscorer. He also finished runner-up for the Ballon d'Or three times, behind Lionel Messi (his perceived career rival), and won back-to-back Ballons d'Or in 2013 and 2014, and again in 2016 and 2017. In 2018, he signed for Juventus in a transfer worth an initial €100 million (£88 million), the most expensive transfer for an Italian club and the most expensive transfer for a player over 30 years old. He won two Serie A titles, two Supercoppe Italiana and a Coppa Italia, before returning to Manchester United in 2021. Ronaldo made his senior international debut for Portugal in 2003 at the age of 18 and has since earned over 180 caps, making him Portugal's most-capped player. With more than 100 goals at international level, he is also the nation's all-time top goalscorer. He has played in and scored at 11 major tournaments, he scored his first international goal at Euro 2004, where he helped Portugal reach the final. He assumed full captaincy of the national team in July 2008. In 2015, 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 2016, and received the Silver Boot as the second-highest goalscorer of the tournament. He also led them to victory in the inaugural UEFA Nations League in 2019, and later received the Golden Boot as top scorer of Euro 2020. One of the world's most marketable and famous athletes, Ronaldo was ranked the world's highest-paid athlete by Forbes in 2016 and 2017 and the world's most famous athlete by ESPN from 2016 to 2019. Time included him on their list of the 100 most influential people in the world in 2014. He is the first footballer and the third sportsman to earn US $1 billion in his career.

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

最佳答案

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

关于python - 为什么我的马尔可夫链会从语料库中产生相同的句子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70201981/

相关文章:

python - 在 While 循环中使用随机 Once

python - 在 Ubuntu 上通过 virtualenv 中的设置工具安装 Numpy 时出错

python - 马尔可夫链蒙特卡罗模拟问题

python - 从转移矩阵生成马尔可夫链

uml - 有条件转移的有限状态机可以表示为马尔可夫链吗?

Python - 使用 alpha channel 在子图中使用 matplotlib 叠加 2 个图

python - 在python中计算指数移动平均线

python - GaussianHMM 中的解码序列

用于在线机器学习 MDP 的 Python 库

deep-learning - 为什么要在强化学习中引入马尔可夫性质?