Exemple #1
0
def test(docs, allpairs, kernelpairs, classifiers=[SLK_PRED, SST_PRED],
         dditype=type, tag="", backup=False, printstd=False):
    #expects: ddi_sentences.md
    #data =  ddi_train_slk.model, ddi_train_sst.model
    tempfiles = []
    excludesentences = []

    if SLK_PRED in classifiers:
        logging.info("**Testing SLK classifier %s ..." % (tag,))
        #testpairdic = ddi_kernels.fromddiDic(testdocs)
        kernelmodels.generatejSREdata(kernelpairs, docs, tag + "ddi_test_jsre.txt", dditype=dditype,
                                      excludesentences=excludesentences)
        kernelmodels.testjSRE(tag + "ddi_test_jsre.txt", tag + "ddi_test_result.txt",
                              model=tag + "ddi_train_slk.model")
        allpairs = kernelmodels.getjSREPredicitons(tag + "ddi_test_jsre.txt", tag + "ddi_test_result.txt",
                                                   allpairs, kernelpairs, dditype=dditype)
        tempfiles.append(kernelmodels.basedir + tag + "ddi_test_jsre.txt")
        tempfiles.append(kernelmodels.basedir + tag + "ddi_test_result.txt")

    if SST_PRED in classifiers:
        logging.info("****Testing SST classifier %s ..." % (tag,))
        allpairs = kernelmodels.testSVMTK(docs, kernelpairs, allpairs, dditype=dditype,
                                          model=tag + "ddi_train_sst.model", tag=tag,
                                          excludesentences=excludesentences)
    return tempfiles, allpairs
Exemple #2
0
def train(docs, kernelpairs, classifiers, dditype="all", tag="", backup=False):
    tempfiles = []
    excludesentences = []
    #data = ddi_sentences.build_data_frame(docs)


    #logging.info("excluding %s/%s sentences from the train data",
    #             len(excludesentences), len(docs))

    if SLK_PRED in classifiers:
        logging.info("**Training SLK classifier %s ..." % (tag,))
        #trainpairdic = ddi_kernels.fromddiDic(traindocs)

        kernelmodels.generatejSREdata(kernelpairs, docs, tag + "ddi_train_jsre.txt",
                                      dditype=dditype, excludesentences=excludesentences,
                                      train=True)
        kernelmodels.trainjSRE(tag + "ddi_train_jsre.txt", tag + "ddi_train_slk.model")
        logging.info("done.")
        #logging.info("pred: %s \ntest_y: %s", labels, test_y)
        #tempfiles.append(ddi_kernels.basedir + tag + "ddi_train_jsre.txt")
        #tempfiles.append(ddi_kernels.basedir + tag + "ddi_train_slk.model")
    if SST_PRED in classifiers:
        logging.info("****Training SST classifier %s ..." % (tag,))
        kernelmodels.trainSVMTK(docs, kernelpairs, model=tag + "ddi_train_sst.model",
                                dditype=dditype, excludesentences=excludesentences)
        tempfiles.append("ddi_models/" + tag + "ddi_train_sst.model")
        logging.info("done.")
    print tag + " training complete"
    if backup:
        print "backing up these files:", tempfiles
        backupFiles("train_results_", tempfiles)
    return tempfiles
Exemple #3
0
def test(docs,
         allpairs,
         kernelpairs,
         classifiers=[SLK_PRED, SST_PRED],
         dditype=type,
         tag="",
         backup=False,
         printstd=False):
    #expects: ddi_sentences.md
    #data =  ddi_train_slk.model, ddi_train_sst.model
    tempfiles = []
    excludesentences = []

    if SLK_PRED in classifiers:
        logging.info("**Testing SLK classifier %s ..." % (tag, ))
        #testpairdic = ddi_kernels.fromddiDic(testdocs)
        kernelmodels.generatejSREdata(kernelpairs,
                                      docs,
                                      tag + "ddi_test_jsre.txt",
                                      dditype=dditype,
                                      excludesentences=excludesentences)
        kernelmodels.testjSRE(tag + "ddi_test_jsre.txt",
                              tag + "ddi_test_result.txt",
                              model=tag + "ddi_train_slk.model")
        allpairs = kernelmodels.getjSREPredicitons(tag + "ddi_test_jsre.txt",
                                                   tag + "ddi_test_result.txt",
                                                   allpairs,
                                                   kernelpairs,
                                                   dditype=dditype)
        tempfiles.append(kernelmodels.basedir + tag + "ddi_test_jsre.txt")
        tempfiles.append(kernelmodels.basedir + tag + "ddi_test_result.txt")

    if SST_PRED in classifiers:
        logging.info("****Testing SST classifier %s ..." % (tag, ))
        allpairs = kernelmodels.testSVMTK(docs,
                                          kernelpairs,
                                          allpairs,
                                          dditype=dditype,
                                          model=tag + "ddi_train_sst.model",
                                          tag=tag,
                                          excludesentences=excludesentences)
    return tempfiles, allpairs
Exemple #4
0
def train(docs, kernelpairs, classifiers, dditype="all", tag="", backup=False):
    tempfiles = []
    excludesentences = []
    #data = ddi_sentences.build_data_frame(docs)

    #logging.info("excluding %s/%s sentences from the train data",
    #             len(excludesentences), len(docs))

    if SLK_PRED in classifiers:
        logging.info("**Training SLK classifier %s ..." % (tag, ))
        #trainpairdic = ddi_kernels.fromddiDic(traindocs)

        kernelmodels.generatejSREdata(kernelpairs,
                                      docs,
                                      tag + "ddi_train_jsre.txt",
                                      dditype=dditype,
                                      excludesentences=excludesentences,
                                      train=True)
        kernelmodels.trainjSRE(tag + "ddi_train_jsre.txt",
                               tag + "ddi_train_slk.model")
        logging.info("done.")
        #logging.info("pred: %s \ntest_y: %s", labels, test_y)
        #tempfiles.append(ddi_kernels.basedir + tag + "ddi_train_jsre.txt")
        #tempfiles.append(ddi_kernels.basedir + tag + "ddi_train_slk.model")
    if SST_PRED in classifiers:
        logging.info("****Training SST classifier %s ..." % (tag, ))
        kernelmodels.trainSVMTK(docs,
                                kernelpairs,
                                model=tag + "ddi_train_sst.model",
                                dditype=dditype,
                                excludesentences=excludesentences)
        tempfiles.append("ddi_models/" + tag + "ddi_train_sst.model")
        logging.info("done.")
    print tag + " training complete"
    if backup:
        print "backing up these files:", tempfiles
        backupFiles("train_results_", tempfiles)
    return tempfiles