{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import random\n", "import numpy as np\n", "import pandas as pd\n", "\n", "def generate_random_dna_sequence(length):\n", " return ''.join(random.choices('ATGC', k=length))\n", "\n", "np.random.seed(42)\n", "\n", "# Generate 200 sequences of random DNA sequences with lengths ranging from 200 to 2000\n", "sequence_lengths = np.random.randint(200, 2001, size=2000)\n", "dna_sequences = [generate_random_dna_sequence(length) for length in sequence_lengths]\n", "labels1 = np.random.randint(0, 2, size=2000)\n", "labels2 = np.random.randint(0, 3, size=2000)\n", "labels3 = np.random.randint(0, 5, size=2000)\n", "\n", "# Create a DataFrame with the DNA sequences and random labels\n", "df_dna = pd.DataFrame({\n", " 'sequence': dna_sequences,\n", " 'label1': labels1,\n", " 'label2': labels2,\n", " 'label3': labels3\n", "})\n", "\n", "# Save to CSV\n", "csv_dna_path = \"/data/project/hf_tutorial/data/train.csv\"\n", "df_dna.to_csv(csv_dna_path, index=False)\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "\n", "# Generate 200 sequences of random DNA sequences with lengths ranging from 200 to 2000\n", "sequence_lengths = np.random.randint(200, 2001, size=200)\n", "dna_sequences = [generate_random_dna_sequence(length) for length in sequence_lengths]\n", "labels1 = np.random.randint(0, 2, size=200)\n", "labels2 = np.random.randint(0, 3, size=200)\n", "labels3 = np.random.randint(0, 5, size=200)\n", "\n", "# Create a DataFrame with the DNA sequences and random labels\n", "df_dna = pd.DataFrame({\n", " 'sequence': dna_sequences,\n", " 'label1': labels1,\n", " 'label2': labels2,\n", " 'label3': labels3\n", "})\n", "\n", "# Save to CSV\n", "csv_dna_path = \"/data/project/hf_tutorial/data/eval.csv\"\n", "df_dna.to_csv(csv_dna_path, index=False)\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# Function to generate a random string of a given length\n", "def generate_random_string(length):\n", " return ''.join(random.choices('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', k=length))\n", "\n", "# Generate random strings for each label category\n", "label1_strings = {0: generate_random_string(2), 1: generate_random_string(2)}\n", "label2_strings = {i: generate_random_string(3) for i in range(3)}\n", "label3_strings = {i: generate_random_string(5) for i in range(5)}\n", "\n", "# Save each string to a separate text file\n", "label1_path = \"/data/project/hf_tutorial/data/label1.txt\"\n", "label2_path = \"/data/project/hf_tutorial/data/label2.txt\"\n", "label3_path = \"/data/project/hf_tutorial/data/label3.txt\"\n", "\n", "def save_label_strings(label_strings, path):\n", " with open(path, 'w') as f:\n", " for label, string in label_strings.items():\n", " f.write(f\"{label}: {string}\\n\")\n", "\n", "save_label_strings(label1_strings, label1_path)\n", "save_label_strings(label2_strings, label2_path)\n", "save_label_strings(label3_strings, label3_path)\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "CommitInfo(commit_url='https://huggingface.co/datasets/ZJdog/hf_tutorial_dna/commit/8ebcb0406ec3cc2b6cbbdefac6b07ca720603508', commit_message='Initial commit', commit_description='', oid='8ebcb0406ec3cc2b6cbbdefac6b07ca720603508', pr_url=None, pr_revision=None, pr_num=None)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from huggingface_hub import HfApi, HfFolder\n", "\n", "dataset_path = \"/data/project/hf_tutorial/data\" # 你的数据集文件夹路径\n", "dataset_name = \"ZJdog/hf_tutorial_dna\" # 数据集名称\n", "\n", "api = HfApi()\n", "# api.create_repo(repo_id=dataset_name, repo_type=\"dataset\")\n", "api.upload_folder(\n", " repo_id=dataset_name,\n", " folder_path=dataset_path,\n", " repo_type=\"dataset\",\n", " commit_message=\"Initial commit\"\n", ")\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.13" } }, "nbformat": 4, "nbformat_minor": 2 }