Пример #1
0
import sys

sys.path.append('..')
from common.trainer import Trainer
from common.optimizer import Adam
from simple_cbow import SimpleCBOW
from common.util import preprocess, create_contexts_target, convert_one_hot

window_size = 1
hidden_size = 5
batch_size = 3
max_epoch = 1000

text = 'You say goodbye and I say hello.'
corpus, word_to_id, id_to_word = preprocess(text)

vocab_size = len(word_to_id)
contexts, target = create_contexts_target(corpus, window_size)
target = convert_one_hot(target, vocab_size)
contexts = convert_one_hot(contexts, vocab_size)

model = SimpleCBOW(vocab_size, hidden_size)
optimizer = Adam()
trainer = Trainer(model, optimizer)

trainer.fit(contexts, target, max_epoch, batch_size)
trainer.plot()
     [4 5]
     [1 6]]
    """
    print(contexts)


def check_target():
    """
    >>> check_target()
    [1 2 3 4 1 5]
    """
    print(target)


vocabulary_size = len(word_to_id)
target_one_hot = convert_one_hot(target, vocabulary_size)


def check_target_one_hot():
    """
    >>> check_target_one_hot()
    [[0 1 0 0 0 0 0]
     [0 0 1 0 0 0 0]
     [0 0 0 1 0 0 0]
     [0 0 0 0 1 0 0]
     [0 1 0 0 0 0 0]
     [0 0 0 0 0 1 0]]
    """
    print(target_one_hot)