Beispiel #1
0
def transliterate_bilstm_top3(sentence):
    """
    Transliterate signs using biLSTM
    :param sentence: signs to be transliterated
    :return: 3 top transliterations of the sentence with their scores
    """
    sentence = sanitize(sentence)

    model, predictor, sign_to_id, id_to_tran, test_texts = load_object_from_file(bilstm_path)

    tag_logits = predictor.predict(sentence_to_allen_format(sentence, sign_to_id, True))['tag_logits']
    prediction1, prediction2, prediction3, score1, score2, score3 = logits_to_trans(tag_logits, model, id_to_tran)
    return list_to_tran(prediction1), list_to_tran(prediction2), list_to_tran(prediction3)
Beispiel #2
0
def transliterate_bilstm(sentence):
    """
    Transliterate signs using biLSTM
    :param sentence: signs to be transliterated
    :return: transliteration of the sentence
    """
    sentence = sanitize(sentence)

    model, predictor, sign_to_id, id_to_tran, test_texts = load_object_from_file(bilstm_path)

    tag_logits = predictor.predict(sentence_to_allen_format(sentence, sign_to_id, True))['tag_logits']
    biLSTM_predicted_tags, _, _, _, _, _ = logits_to_trans(tag_logits, model, id_to_tran)
    return list_to_tran(biLSTM_predicted_tags)
Beispiel #3
0
def transliterate_memm(sentence):
    """
    Transliterate signs using MEMM
    :param sentence: signs to be transliterated
    :return: transliteration of the sentence
    """
    sentence = sanitize(sentence)

    logreg, vec, idx_to_tag_dict, test_texts = load_object_from_file(memm_path)

    MEMM_predicted_tags = memm_greedy(sentence_to_HMM_format(sentence), logreg, vec, idx_to_tag_dict)

    return list_to_tran(MEMM_predicted_tags)
Beispiel #4
0
def transliterate_memm(sentence):
    """
    Transliterate signs using MEMM
    :param sentence: signs to be transliterated
    :return: transliteration of the sentence
    """
    sentences = [sanitize(line) for line in sentence.splitlines() if len(sanitize(line)) > 0]

    logreg, vec, idx_to_tag_dict, test_texts = load_object_from_file(memm_path)

    MEMM_predicted_tags_list = [memm_greedy(sentence_to_HMM_format(s), logreg, vec, idx_to_tag_dict) for s in sentences]
    tran_list = [list_to_tran(MEMM_predicted_tags) for MEMM_predicted_tags in MEMM_predicted_tags_list]

    return ''.join(tran_list)
Beispiel #5
0
def transliterate_hmm(sentence):
    """
    Transliterate signs using HMM
    :param sentence: signs to be transliterated
    :return: transliteration of the sentence
    """
    sentence = sanitize(sentence)

    most_common_tag, possible_tags, q, e, S, total_tokens, q_bi_counts, q_uni_counts, lambda1, lambda2, test_texts = \
        load_object_from_file(hmm_path)

    HMM_predicted_tags = hmm_viterbi(sentence_to_HMM_format(sentence), total_tokens, q_bi_counts, q_uni_counts, q, e,
                           S, most_common_tag, possible_tags, lambda1, lambda2)
    return list_to_tran(HMM_predicted_tags)
Beispiel #6
0
def transliterate_hmm(sentence):
    """
    Transliterate signs using HMM
    :param sentence: signs to be transliterated
    :return: transliteration of the sentence
    """
    sentences = [sanitize(line) for line in sentence.splitlines() if len(sanitize(line)) > 0]

    most_common_tag, possible_tags, q, e, S, total_tokens, q_bi_counts, q_uni_counts, lambda1, lambda2, test_texts = \
        load_object_from_file(hmm_path)

    HMM_predicted_tags_list = [hmm_viterbi(sentence_to_HMM_format(s), total_tokens, q_bi_counts, q_uni_counts, q, e,
                           S, most_common_tag, possible_tags, lambda1, lambda2) for s in sentences]
    tran_list = [list_to_tran(HMM_predicted_tags) for HMM_predicted_tags in HMM_predicted_tags_list]

    return ''.join(tran_list)