Exemplo n.º 1
0
def token_emotion_mat(vocab: Vocab):
    """pass"""
    emotion_mat = np.zeros(shape=(vocab.size()))
    emotion_mat[vocab.get_group(vocab.postive_name)] = 1
    emotion_mat[vocab.get_group(vocab.negtive_name)] = -1

    return emotion_mat
Exemplo n.º 2
0
def doc_onehot_mat(doc_tokens: List[List[Text]], vocab: Vocab):
    """pass"""

    tk2idx = vocab.tk2idx
    all_tks = list(tk2idx.keys())

    onehot_mat = np.zeros(shape=(vocab.size() + 1, len(doc_tokens)),
                          dtype=np.int8)

    for id, doc in enumerate(doc_tokens):
        tks = list(map(lambda tk: tk2idx[tk] if tk in doc else -1, all_tks))
        onehot_mat[tks, id] = 1

    return onehot_mat