Beispiel #1
0
def test_visualize_word_emeddings():

    with open('./resources/visual/snippet.txt') as f:
        sentences = [x for x in f.read().split('\n') if x]

    sentences = [Sentence(x) for x in sentences]

    charlm_embedding_forward = CharLMEmbeddings('news-forward')

    visualizer = Visualizer()
    visualizer.visualize_char_emeddings(
        charlm_embedding_forward, sentences,
        './resources/visual/sentence_embeddings.html')

    # clean up directory
    os.remove('./resources/visual/sentence_embeddings.html')
Beispiel #2
0
def test_visualize_word_emeddings(resources_path):

    with open(resources_path / 'visual/snippet.txt') as f:
        sentences = [x for x in f.read().split('\n') if x]

    sentences = [Sentence(x) for x in sentences]

    charlm_embedding_forward = CharLMEmbeddings('news-forward')

    visualizer = Visualizer()
    visualizer.visualize_char_emeddings(
        charlm_embedding_forward, sentences,
        str(resources_path / 'visual/sentence_embeddings.html'))

    # clean up directory
    (resources_path / 'visual/sentence_embeddings.html').unlink()
Beispiel #3
0
def test_visualize():

    with open('./resources/visual/snippet.txt') as f:
        sentences = [x for x in f.read().split('\n') if x]

    sentences = [Sentence(x) for x in sentences]

    embeddings = CharLMEmbeddings('news-forward')

    visualizer = Visualizer()

    X_forward = visualizer.prepare_char_embeddings(embeddings, sentences)

    embeddings = CharLMEmbeddings('news-backward')

    X_backward = visualizer.prepare_char_embeddings(embeddings, sentences)

    X = numpy.concatenate([X_forward, X_backward], axis=1)

    contexts = visualizer.char_contexts(sentences)

    trans_ = tSNE()
    reduced = trans_.fit(X)

    visualizer.visualize(reduced, contexts,
                         './resources/visual/char_embeddings.html')

    # clean up directory
    os.remove('./resources/visual/char_embeddings.html')
Beispiel #4
0
def test_visualize_word_emeddings(resources_path):

    with open(resources_path / 'visual/snippet.txt') as f:
        sentences = [x for x in f.read().split('\n') if x]

    sentences = [Sentence(x) for x in sentences]

    charlm_embedding_forward = CharLMEmbeddings('news-forward')
    charlm_embedding_backward = CharLMEmbeddings('news-backward')

    embeddings = StackedEmbeddings(
        [charlm_embedding_backward, charlm_embedding_forward])

    visualizer = Visualizer()
    visualizer.visualize_word_emeddings(
        embeddings, sentences,
        str(resources_path / 'visual/sentence_embeddings.html'))

    # clean up directory
    os.remove(resources_path / 'visual/sentence_embeddings.html')