This commit is contained in:
2026-06-05 21:11:32 +08:00
parent d8cec42fa9
commit 9ba8306b8d
6 changed files with 550 additions and 144 deletions
+59 -7
View File
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"id": "259a585b",
"metadata": {},
"outputs": [],
@@ -30,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"id": "fe7bf6eb",
"metadata": {},
"outputs": [
@@ -58,7 +58,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 4,
"id": "4bddedb8",
"metadata": {},
"outputs": [
@@ -95,18 +95,70 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "b33dcb00",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"65\n",
"\n",
" !$&',-.3:;?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n"
]
}
],
"source": [
"set(text)"
"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",
"display_name": ".venv (3.12.10)",
"language": "python",
"name": "python3"
},