181 lines
3.4 KiB
Plaintext
181 lines
3.4 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "259a585b",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"### heloo"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "e18c006e",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"hello world\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(\"hello world\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "fe7bf6eb",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"True\n",
|
|
"cuda\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import torch\n",
|
|
"from torch._C import device\n",
|
|
"import torch.nn as nn\n",
|
|
"from torch.nn import functional as F\n",
|
|
"print(torch.cuda.is_available())\n",
|
|
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
|
|
"print(device)\n",
|
|
"\n",
|
|
"if device == \"cuda\":\n",
|
|
" print(\"gpu\", torch.cuda.get_device_name(0))\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "4bddedb8",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"1115394\n",
|
|
"First Citizen:\n",
|
|
"Before we proceed any further, hear me speak.\n",
|
|
"\n",
|
|
"All:\n",
|
|
"Speak, speak.\n",
|
|
"\n",
|
|
"First Citizen:\n",
|
|
"You are all resolved rather to die than to famish?\n",
|
|
"\n",
|
|
"All:\n",
|
|
"Resolved. resolved.\n",
|
|
"\n",
|
|
"First Citizen:\n",
|
|
"First, you know Caius Marcius is chief enemy to the people.\n",
|
|
"\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"with open(\"input.txt\", \"r\", encoding = \"utf-8\") as f:\n",
|
|
" text = f.read()\n",
|
|
"\n",
|
|
"print(len(text))\n",
|
|
"print(text[:250])\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "b33dcb00",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"65\n",
|
|
"\n",
|
|
" !$&',-.3:;?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"chars = sorted(list(set(text)))\n",
|
|
"vocab_size = len(chars)\n",
|
|
"print(vocab_size\n",
|
|
")\n",
|
|
"print(\"\".join(chars\n",
|
|
"))\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "7c84058a",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"'!'"
|
|
]
|
|
},
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"stoi = {char:i for i, char in enumerate(chars)}\n",
|
|
"itos = {i:char for i, char in enumerate(chars)}\n",
|
|
"# print (itos)\n",
|
|
"\n",
|
|
"stoi['a'] # 0\n",
|
|
"itos[2]\n",
|
|
"\n",
|
|
"encode = lambda s: \n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "4f43742c",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": ".venv (3.12.10)",
|
|
"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.10"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|