<jupyter_start><jupyter_text>Visualize BioRxiv Document Embeddings This notebook is designed to visualize umap and tsne representations of bioRxiv document embeddings.Each document embedding is generated via an average of every word in a given article.<jupyter_code>import itertools
from pathlib import Path
import re

import pandas as pd
import plotnine as p9
journal_map_df = pd.read_csv(
    "../exploratory_data_analysis/output/biorxiv_article_metadata.tsv", sep="\t"
)
journal_map_df.head()
# Keep only current versions of articles
biorxiv_umap_models_latest = {
    "original": (
        pd.read_csv("output/embedding_output/umap/biorxiv_umap_300.tsv", sep="\t")
        .groupby("doi")
        .agg(
            {
                "doi": "last",
                "document": "last",
                "umap1": "last",
                "umap2": "last",
                "category": "last",
            }
        )
        .reset_index(drop=True)
    ),
    "doc2vec": (
        pd.read_csv(
            "output/embedding_output/umap/biorxiv_umap_300_doc2vec.tsv", sep="\t"
        )
        .groupby("doi")
        .agg(
            {
                "doi": "last",
                "document": "last",
                "umap1": "last",
                "umap2": "last",
                "category": "last",
            }
        )
        .reset_index(drop=True)
    ),
}
# Keep only current versions of articles
biorxiv_pca_models_latest = {
    "original": (
        pd.read_csv("output/embedding_output/pca/biorxiv_pca_300.tsv", sep="\t")
        .groupby("doi")
        .agg(
            {
                "doi": "last",
                "document": "last",
                "pca1": "last",
                "pca2": "last",
                "category": "last",
            }
        )
        .reset_index(drop=True)
    ),
    "doc2vec": (
        pd.read_csv("output/embedding_output/pca/biorxiv_pca_300_doc2vec.tsv", sep="\t")
        .groupby("doi")
        .agg(
            {
                "doi": "last",
                "document": "last",
                "pca1": "last",
                "pca2": "last",
                "category": "last",
            }
        )
        .reset_index(drop=True)
    ),
}<jupyter_output><empty_output><jupyter_text>UMAP of the Documents<jupyter_code>g = (
    p9.ggplot(biorxiv_umap_models_latest["original"])
    + p9.aes(x="umap1", y="umap2", color="factor(category)")
    + p9.geom_point()
    + p9.labs(title="UMAP of BioRxiv (Word dim: 300)", color="Article Category")
)
g.save("output/embedding_output/umap/figures/biorxiv_umap_300.png", dpi=500)
print(g)
g = (
    p9.ggplot(biorxiv_umap_models_latest["doc2vec"])
    + p9.aes(x="umap1", y="umap2", color="factor(category)")
    + p9.geom_point()
    + p9.labs(title="UMAP of BioRxiv (Doc2vec Word dim: 300)", color="Article Category")
)
g.save("output/embedding_output/umap/figures/biorxiv_umap_300_doc2vec.png", dpi=500)
print(g)<jupyter_output>/home/danich1/anaconda3/envs/annorxiver/lib/python3.7/site-packages/plotnine/ggplot.py:729: PlotnineWarning: Saving 6.4 x 4.8 in image.
/home/danich1/anaconda3/envs/annorxiver/lib/python3.7/site-packages/plotnine/ggplot.py:730: PlotnineWarning: Filename: output/embedding_output/umap/figures/biorxiv_umap_300_doc2vec.png<jupyter_text>PCA of the Documents<jupyter_code>g = (
    p9.ggplot(biorxiv_pca_models_latest["original"])
    + p9.aes(x="pca1", y="pca2", color="factor(category)")
    + p9.geom_point()
    + p9.labs(title="PCA of BioRxiv (Word dim: 300)", color="Article Category")
)
g.save("output/embedding_output/pca/figures/biorxiv_pca_300.png", dpi=500)
print(g)
g = (
    p9.ggplot(biorxiv_pca_models_latest["doc2vec"])
    + p9.aes(x="pca1", y="pca2", color="factor(category)")
    + p9.geom_point()
    + p9.labs(title="PCA of BioRxiv (Doc2vec Word dim: 300)", color="Article Category")
)
g.save("output/embedding_output/pca/figures/biorxiv_pca_300_doc2vec.png", dpi=500)
print(g)<jupyter_output>/home/danich1/anaconda3/envs/annorxiver/lib/python3.7/site-packages/plotnine/ggplot.py:729: PlotnineWarning: Saving 6.4 x 4.8 in image.
/home/danich1/anaconda3/envs/annorxiver/lib/python3.7/site-packages/plotnine/ggplot.py:730: PlotnineWarning: Filename: output/embedding_output/pca/figures/biorxiv_pca_300_doc2vec.png
{'fraction_non_alphanumeric': 0.14656988995551393, 'fraction_numerical': 0.031608522594240226, 'mean_word_length': 2.767195767195767, 'pattern_counts': {'":': 24, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '482814', 'license': 'CC0-1.0', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1557, 'n_words': 228, 'path': 'biorxiv/word_vector_experiment/04_biorxiv_visualize_embeddings_doc2vec.ipynb', 'repo_name': 'danich1/annorxiver', 'size': '4271'}