{ "cells": [ { "cell_type": "code", "execution_count": 3, "id": "499abdf6", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "# 设置 Hugging Face 镜像\n", "os.environ[\"HF_ENDPOINT\"] = \"https://hf-mirror.com\"\n", "\n", "# 如果是完全离线模式\n", "# os.environ[\"HF_HUB_OFFLINE\"] = \"1\"\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "08edf2a5", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "183e4df62da84c9389f36d6e011f6be0", "version_major": 2, "version_minor": 1 }, "text/plain": [ "EmbeddingAtlasWidget()" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from embedding_atlas.widget import EmbeddingAtlasWidget \n", "import pandas as pd \n", " \n", "df = pd.read_csv('data/drugbank_pre_filtered_mordred_qed_id_selfies.csv') \n", " \n", "# 计算投影 \n", "from embedding_atlas.projection import compute_text_projection \n", "compute_text_projection(df, text=\"smiles\", \n", " x=\"projection_x\", y=\"projection_y\", neighbors=\"neighbors\" \n", ") \n", " \n", "# 创建并显示 widget \n", "widget = EmbeddingAtlasWidget(df, text=\"smiles\", \n", " x=\"projection_x\", y=\"projection_y\", neighbors=\"neighbors\" \n", ") \n", " \n", "# 确保在单独的单元格中显示 \n", "widget" ] }, { "cell_type": "code", "execution_count": 5, "id": "be723d90", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b67dc99218614138bf6657716f3739f8", "version_major": 2, "version_minor": 1 }, "text/plain": [ "EmbeddingAtlasWidget()" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd \n", "from embedding_atlas.projection import compute_text_projection \n", "from embedding_atlas.widget import EmbeddingAtlasWidget \n", " \n", "# 读取您的数据 \n", "df = pd.read_csv('data/drugbank_pre_filtered_mordred_qed_id_selfies.csv') \n", " \n", "# 计算 SMILES 的文本嵌入和 2D 投影 \n", "compute_text_projection( \n", " df, \n", " text=\"smiles\", # 使用 SMILES 列作为文本输入 \n", " x=\"projection_x\", # X 坐标列名 \n", " y=\"projection_y\", # Y 坐标列名 \n", " neighbors=\"neighbors\" # 最近邻列名 \n", ") \n", "\n", "# 在 Jupyter 中显示可视化 \n", "EmbeddingAtlasWidget(df, text=\"smiles\", \n", " x=\"projection_x\", y=\"projection_y\", \n", " neighbors=\"neighbors\")\n", " \n" ] }, { "cell_type": "code", "execution_count": null, "id": "7e3bb412", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.11" } }, "nbformat": 4, "nbformat_minor": 5 }