当前位置: 首页>>代码示例>>Python>>正文


Python Trainer.calcPerplexicity方法代码示例

本文整理汇总了Python中trainer.Trainer.calcPerplexicity方法的典型用法代码示例。如果您正苦于以下问题:Python Trainer.calcPerplexicity方法的具体用法?Python Trainer.calcPerplexicity怎么用?Python Trainer.calcPerplexicity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trainer.Trainer的用法示例。


在下文中一共展示了Trainer.calcPerplexicity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestRNNTrainer

# 需要导入模块: from trainer import Trainer [as 别名]
# 或者: from trainer.Trainer import calcPerplexicity [as 别名]
class TestRNNTrainer(unittest.TestCase):

    def setUp(self):

        fname = 'friends.txt'
        f = open(fname, 'r')
        self.txt = f.read()
        f.close()


        c = Corpus(self.txt)
        c.brownInit(500)
        rnn = RNN(100, c.V, 50)
        rnn.load('rnn.save')

        self.trainer = Trainer(c,rnn, nepochs=50, alpha = 1.8)

    def tesT_TrainingOnSentances(self):

        c = Corpus(self.txt)
        rnn = RNN(100, c.V, 50)

        trainer = Trainer(c,rnn, nepochs=50, alpha = 1.8)
        trainer.train()

    def tesT_SentancePrintTest(self):

        # trainer.test_sentance(c.X[1], c.Y[1])
        self.trainer.fullDataTest()

    def test_perplexicity(self):

        c = Corpus("asdada asdaa asd adada dadada. asdas dasd.da ad.a d.sa da asd")
        c.brownInit(500,0)
        p = self.trainer.calcPerplexicity(c)
        print Fore.CYAN, p, "\n"

    def tesT_evaluating_sentance(self):
        
        sentances = [
            "I love my son",
            "This food makes no sense",
            "The president loves to eat food",
            "love stock bullet is are am",
            "sense I of am since is",
            "the number of voters and the size of this city",
            "considering the widespread election",
            "implementation of the law",
            "on horse race betting",
            "He is willing to stake his political career on it",
            "He is willing to stake her political career on it",
            "He willing to stake her political career on it",
            "He is willing to stake political career it",
            "I'm willing to stake my political career on it",
            "I'm willing to stake my political career on this",
            "all the voters are willing to stake their political career on it",
            "all the voters am willing to stake my political career on it",
        
        ]

        for s in sentances:

            p = self.trainer.findProbabilityOfSentance(s)
            print Fore.CYAN, "%s -> %f\n\r" % (s,p)

    def tesT_generating_sentance(self):

        self.trainer.generate_sequence()

    def tesT_saving_model(self):
        c = Corpus(self.txt)
        rnn = RNN(100, c.V, 50)
        rnn.save()
开发者ID:liuhy0908,项目名称:rnnlm-1,代码行数:75,代码来源:trainer_test.py


注:本文中的trainer.Trainer.calcPerplexicity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。