{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "d9cf9cf5-48d9-4264-9b54-831746b1760e", "metadata": {}, "outputs": [], "source": [ "import torch" ] }, { "cell_type": "code", "execution_count": 2, "id": "c3ae56b5-57a8-40b1-a08f-2f9ebf223832", "metadata": {}, "outputs": [], "source": [ "path1 = \"/home/suresh/SATURN/protein_embeddings_export/ESM2/frog_embedding.torch\"" ] }, { "cell_type": "code", "execution_count": 3, "id": "09debba6-72d6-4db2-9e2d-1ab37090f9a9", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_3839716/71590555.py:1: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.\n", " model = torch.load(path1)\n" ] } ], "source": [ "model = torch.load(path1) " ] }, { "cell_type": "code", "execution_count": 5, "id": "704228d4-a1b4-44d9-b05d-861909a277f0", "metadata": {}, "outputs": [], "source": [ "# model" ] }, { "cell_type": "code", "execution_count": 17, "id": "5dc7570b-cda7-4434-a0df-2bf8fe69a159", "metadata": {}, "outputs": [], "source": [ "path2 = '/home/suresh/septation/ProtT5/turtle_embeddings.csv'" ] }, { "cell_type": "code", "execution_count": 18, "id": "36213bb9-012b-4787-a52d-ec2b07c2dc60", "metadata": {}, "outputs": [], "source": [ "import csv\n", "import torch\n", "\n", "def csv_to_tensor_dict(csv_filepath):\n", " \"\"\"\n", " Converts each row of a CSV file to a tensor and stores them in a dictionary.\n", "\n", " Args:\n", " csv_filepath (str): The path to the CSV file.\n", "\n", " Returns:\n", " dict: A dictionary where keys are row indices and values are tensors.\n", " \"\"\"\n", " tensor_dict = {}\n", " with open(csv_filepath, 'r') as file:\n", " reader = csv.reader(file)\n", " header = next(reader) # Skip header row if it exists\n", " for i, row in enumerate(reader):\n", " key = row[0]\n", " # Convert each element in the row to float and create a tensor\n", " tensor_row = torch.tensor([float(x) for x in row[1:]])\n", " tensor_dict[key] = tensor_row\n", " return tensor_dict\n", "\n", "# Example usage:\n", "result_dict = csv_to_tensor_dict(path2)" ] }, { "cell_type": "code", "execution_count": 19, "id": "a8d6d27a-c300-44a4-aa2d-40eb7c626036", "metadata": {}, "outputs": [], "source": [ "torch.save(result_dict, 'turtle_embed.torch')" ] }, { "cell_type": "code", "execution_count": null, "id": "76c2465a-e679-4fd2-a02d-f3bc89892129", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 7, "id": "1309e113-d4be-48bd-be52-483c8e931c52", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_3841063/3268938189.py:1: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.\n", " model = torch.load('chicken_embed.torch')\n" ] } ], "source": [ "model = torch.load('chicken_embed.torch') " ] }, { "cell_type": "code", "execution_count": null, "id": "4beb6257-21dd-4129-9d55-bcfd6cf61eb9", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.14" } }, "nbformat": 4, "nbformat_minor": 5 }