微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Chatterbot如何获得多个回复

如何解决Chatterbot如何获得多个回复

python chatterbot库提供了convo.txt下面的数据集

output.txt

hey
hey 1
hey
hey 2
hey
hey 3

或在对此数据集进行训练时,与下面的数据集(yml)配合使用

- - hey
  - hey 1
- - hey
  - hey 2
- - hey
  - hey 3

调用get_response('hey')时,仅给出1和2,为什么呢?以及当用户键入“嘿”时如何获得多个响应,我希望它随机生成“嘿1嘿2”和“嘿3”之间

解决方法

使用语料库训练器,它比文本文件要好得多,并且每次都要删除数据库以确保获得正确的输出。

print("We have the following genres,choose one: hip-hop,alt-rock,indie rock,electronic")
hiphop = input("Do you want to listen to hip-hop? (yes/no)")
altrock = input("Do you want to listen to alt-rock? (yes/no)")
indierock = input("Do you want to listen to indie-rock? (yes/no)")
electronic = input("Do you want to listen to electronic? (yes/no)")
hhsongs = ("Jay-Z - Feelin' It","Notorious B.I.G. - Big Poppa","Ice Cube - Today Was a Good Day","Eazy-E - Boyz-n-the-Hood","Dr. Dre - Nuthin' but a G Thang")
arsongs = ("Radiohead - Karma Police","Beck - Loser","Cage the Elephant - Ain't No Rest for the Wicked","The Killers - Mr. Brightside")
irsongs = ("The Strokes - Hard to Explain","The Spinto Band - Oh Mandy","The Pixies - Here Comes Your Man","Vampire Weekend - A Punk")
esongs = ("Daft Punk - One More Time","Justice - Genesis","Deadmau5 - Animal","Flyring Lotus - GNG BNG")
if hiphop == "yes":
    import random
    print("Suggested: " + random.choice(hhsongs))
elif altrock == "alt-rock":
    import random
    print("Suggested: " + random.choice(arsongs))
elif indierock == "indie rock":
    import random
    print("Suggested: " + random.choice(irsongs))
elif electronic:
    import random
    print("Suggested: " + random.choice(esongs))

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。