Esempio n. 1
0
def print_map(s: int,
              z: int,
              a: 'np.array',
              pz: float,
              pa: 'np.array',
              e_corpus: Corpus,
              f_corpus: Corpus,
              ostream=sys.stdout):

    e_snt = e_corpus.sentence(s)
    f_snt = f_corpus.sentence(s)
    tokens = []
    for j, (i, p) in enumerate(zip(a, pa)):
        tokens.append('%d:%s|%d:%s|%.2f' % (j + 1, f_corpus.translate(
            f_snt[j]), i, e_corpus.translate(e_snt[i]), p))
    print('%d|%.2f ||| %s' % (z, pz, ' '.join(tokens)), file=ostream)
Esempio n. 2
0
def print_lola_format(sid, alignments, posterior, e_corpus: Corpus, f_corpus: Corpus, ostream):
    """
    Print alignment in a human readable format.

    :param e_corpus: data we condition on
    :param f_corpus: data we generate
    :param sid: sentence id
    :param alignments: alignments (sequence of a_j values for each j)
    :param posterior: posterior p(a_j|f,e)
    :param ostream: where to write alignments to
    :return:
    """
    e_snt = e_corpus.sentence(sid)
    f_snt = f_corpus.sentence(sid)
    # in printing we make the French sentence 1-based by convention
    # we keep the English sentence 0-based because of the NULL token
    print(' '.join(['{0}:{1}|{2}:{3}|{4:.2f}'.format(j + 1,
                                                 f_corpus.translate(f_snt[j]),
                                                 i,
                                                 e_corpus.translate(e_snt[i]),
                                                 p)
                    for j, (i, p) in enumerate(zip(alignments, posterior))]),
          file=ostream)
Esempio n. 3
0
def print_lola_format(sid, alignments, posterior, e_corpus: Corpus,
                      f_corpus: Corpus, ostream):
    """
    Print alignment in a human readable format.

    :param e_corpus: data we condition on
    :param f_corpus: data we generate
    :param sid: sentence id
    :param alignments: alignments (sequence of a_j values for each j)
    :param posterior: posterior p(a_j|f,e)
    :param ostream: where to write alignments to
    :return:
    """
    e_snt = e_corpus.sentence(sid)
    f_snt = f_corpus.sentence(sid)
    # in printing we make the French sentence 1-based by convention
    # we keep the English sentence 0-based because of the NULL token
    print(' '.join([
        '{0}:{1}|{2}:{3}|{4:.2f}'.format(j + 1, f_corpus.translate(f_snt[j]),
                                         i, e_corpus.translate(e_snt[i]), p)
        for j, (i, p) in enumerate(zip(alignments, posterior))
    ]),
          file=ostream)