How to use the smt.decoder.stackdecoder.TransPhraseProb function in smt

To help you get started, we’ve selected a few smt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kenkov / smt / test / test_stackdecoder.py View on Github external
(5, 8): -3.6999999999999997,
               (5, 9): -3.6999999999999997,
               (6, 6): -1.0,
               (6, 7): -1.3,
               (6, 8): -2.3,
               (6, 9): -2.3,
               (7, 7): -1.0,
               (7, 8): -2.2,
               (7, 9): -2.3,
               (8, 8): -1.9,
               (8, 9): -2.4,
               (9, 9): -1.6,
               }

        with DBSetup(db) as dbobj:
            dbobj.session.add_all(TransPhraseProb(lang1p=item[0],
                                                  lang2p=item[1],
                                                  p2_1=item[2],
                                                  p1_2=item[3])
                                  for item in dataset)
            dbobj.session.add_all(Phrase(lang1p=item[0],
                                         lang2p=item[1])
                                  for item in dataset)
            dbobj.session.commit()

            ans = future_cost_estimate(sentences,
                                       transfrom=transfrom,
                                       transto=transto,
                                       init_val=init_val,
                                       db=db)
        # assert
        self.assertEqual(ans, val)
github kenkov / smt / test / test_stackdecoder.py View on Github external
(5, 8): -3.6999999999999997,
               (5, 9): -3.6999999999999997,
               (6, 6): -1.0,
               (6, 7): -1.3,
               (6, 8): -2.3,
               (6, 9): -2.3,
               (7, 7): -1.0,
               (7, 8): -2.2,
               (7, 9): -2.3,
               (8, 8): -1.9,
               (8, 9): -2.4,
               (9, 9): -1.6,
               }

        with DBSetup(db) as dbobj:
            dbobj.session.add_all(TransPhraseProb(lang2p=item[0],
                                                  lang1p=item[1],
                                                  p1_2=item[2],
                                                  p2_1=item[3])
                                  for item in dataset)
            dbobj.session.add_all(Phrase(lang1p=item[0],
                                         lang2p=item[1])
                                  for item in dataset)
            dbobj.session.commit()

            ans = future_cost_estimate(sentences,
                                       transfrom=transfrom,
                                       transto=transto,
                                       init_val=init_val,
                                       db=db)
        # assert
        self.assertEqual(ans, val)
github kenkov / smt / test / test_stackdecoder.py View on Github external
(5, 8): -4.6,
               (5, 9): -4.8,
               (6, 6): -1.0,
               (6, 7): -1.3,
               (6, 8): -2.3,
               (6, 9): -2.3,
               (7, 7): -1.0,
               (7, 8): -2.2,
               (7, 9): -2.3,
               (8, 8): -1.9,
               (8, 9): -2.4,
               (9, 9): -1.6,
               }

        with DBSetup(db) as dbobj:
            dbobj.session.add_all(TransPhraseProb(lang1p=item[0],
                                                  lang2p=item[1],
                                                  p2_1=item[2],
                                                  p1_2=item[3])
                                  for item in dataset)
            dbobj.session.add_all(Phrase(lang1p=item[0],
                                         lang2p=item[1])
                                  for item in dataset)
            dbobj.session.commit()

            ans = future_cost_estimate(sentences,
                                       transfrom=transfrom,
                                       transto=transto,
                                       init_val=init_val,
                                       db=db)

        # assert
github kenkov / smt / smt / decoder / stackdecoder.py View on Github external
transfrom=2,
                                   transto=1,
                                   db=db)
    stacks[0].add_hyp(hyp0)

    # main loop
    for i, stack in enumerate(stacks):
        for hyp in stack:
            for phrase in hyp.remain_phrases:
                phrase_str = u" ".join(zip(*phrase)[1])
                if transfrom == 2 and transto == 1:
                    query = session.query(TransPhraseProb).filter_by(
                        lang2p=phrase_str).order_by(
                            sqlalchemy.desc(TransPhraseProb.p2_1))[:searchsize]
                elif transfrom == 1 and transto == 2:
                    query = session.query(TransPhraseProb).filter_by(
                        lang1p=phrase_str).order_by(
                            sqlalchemy.desc(TransPhraseProb.p1_2))[:searchsize]
                query = list(query)
                for item in query:
                    if transfrom == 2 and transto == 1:
                        outputp = item.lang1p
                    elif transfrom == 1 and transto == 2:
                        outputp = item.lang2p
                    #print(u"calculating\n {0} = {1}\n in stack {2}".format(
                    #      phrase, outputp, i))
                    if transfrom == 2 and transto == 1:
                        outputps = lang1method(outputp).split()
                    elif transfrom == 1 and transto == 2:
                        outputps = lang2method(outputp).split()
                    # place in stack
                    # and recombine with existing hypothesis if possible
github kenkov / smt / smt / decoder / stackdecoder.py View on Github external
cost_dict=cost_dict,
                                   ngram=3,
                                   transfrom=2,
                                   transto=1,
                                   db=db)
    stacks[0].add_hyp(hyp0)

    # main loop
    for i, stack in enumerate(stacks):
        for hyp in stack:
            for phrase in hyp.remain_phrases:
                phrase_str = u" ".join(zip(*phrase)[1])
                if transfrom == 2 and transto == 1:
                    query = session.query(TransPhraseProb).filter_by(
                        lang2p=phrase_str).order_by(
                            sqlalchemy.desc(TransPhraseProb.p2_1))[:searchsize]
                elif transfrom == 1 and transto == 2:
                    query = session.query(TransPhraseProb).filter_by(
                        lang1p=phrase_str).order_by(
                            sqlalchemy.desc(TransPhraseProb.p1_2))[:searchsize]
                query = list(query)
                for item in query:
                    if transfrom == 2 and transto == 1:
                        outputp = item.lang1p
                    elif transfrom == 1 and transto == 2:
                        outputp = item.lang2p
                    #print(u"calculating\n {0} = {1}\n in stack {2}".format(
                    #      phrase, outputp, i))
                    if transfrom == 2 and transto == 1:
                        outputps = lang1method(outputp).split()
                    elif transfrom == 1 and transto == 2:
                        outputps = lang2method(outputp).split()
github kenkov / smt / smt / decoder / stackdecoder.py View on Github external
db=db)
    stacks[0].add_hyp(hyp0)

    # main loop
    for i, stack in enumerate(stacks):
        for hyp in stack:
            for phrase in hyp.remain_phrases:
                phrase_str = u" ".join(zip(*phrase)[1])
                if transfrom == 2 and transto == 1:
                    query = session.query(TransPhraseProb).filter_by(
                        lang2p=phrase_str).order_by(
                            sqlalchemy.desc(TransPhraseProb.p2_1))[:searchsize]
                elif transfrom == 1 and transto == 2:
                    query = session.query(TransPhraseProb).filter_by(
                        lang1p=phrase_str).order_by(
                            sqlalchemy.desc(TransPhraseProb.p1_2))[:searchsize]
                query = list(query)
                for item in query:
                    if transfrom == 2 and transto == 1:
                        outputp = item.lang1p
                    elif transfrom == 1 and transto == 2:
                        outputp = item.lang2p
                    #print(u"calculating\n {0} = {1}\n in stack {2}".format(
                    #      phrase, outputp, i))
                    if transfrom == 2 and transto == 1:
                        outputps = lang1method(outputp).split()
                    elif transfrom == 1 and transto == 2:
                        outputps = lang2method(outputp).split()
                    # place in stack
                    # and recombine with existing hypothesis if possible
                    new_hyp = Hypothesis(prev_hypo=hyp,
                                         inputps_with_index=phrase,