File size: 5,015 Bytes
710f241 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
{
"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
}
|