简体   繁体   English

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

[英]Why does my markov chain produce identical sentences from corpus?

I am using markovify markov chain generator in python and when using the example code given there it produces a lot of duplicate sentences for me and I don't know why.我在 python 中使用markovify 马尔可夫链生成器,当使用那里给出的示例代码时,它会为我产生很多重复的句子,我不知道为什么。

The code is as follows:代码如下:

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())

This gives me output of:这给了我 output 的:

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.

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

As you can see in the output - there are several identical sentences printed out and I have no idea why.正如您在 output 中看到的那样 - 打印了几个相同的句子,我不知道为什么。 The default state size should be 2.默认 state 大小应为 2。

The answer is that my state size was too big - after setting it to be 1 it produced unique sentences.答案是我的 state 尺寸太大 - 将其设置为 1 后会产生独特的句子。 I also did not know that Markovify always starts generating new sentences with the first words of the sentences in corpus.我也不知道 Markovify 总是从语料库中句子的第一个单词开始生成新句子。

That's right, Markovify always starts generating new sentences with the first words of sentences in the corpus.没错,Markovify 总是从语料库中句子的第一个词开始生成新句子。 The answer is that your state size was too big.答案是您的 state 尺寸太大。 You answered yourself.你自己回答了。 However, you got a good result.但是,你得到了一个很好的结果。 I have carefully read the text on Ronaldo.我已经仔细阅读了关于罗纳尔多的文字。 Well done做得好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM