{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Sid-GPT demo\n", "A 92M-parameter GPT built from scratch that rewrites weak PM resume bullets into quantified, action-led ones.\n", "\n", "Run the cells top to bottom (Runtime \u2192 Run all). The last cell gives you a public link to a small web app." ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "!pip -q install torch tokenizers huggingface_hub gradio" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import sys, torch\n", "from huggingface_hub import snapshot_download\n", "path = snapshot_download(\"Sidhartha-Rajput/sid-gpt-resume-llm\")\n", "sys.path.insert(0, path)\n", "from model import GPT\n", "from tokenizers import ByteLevelBPETokenizer\n", "\n", "tok = ByteLevelBPETokenizer(f\"{path}/tokenizer/vocab.json\", f\"{path}/tokenizer/merges.txt\")\n", "ckpt = torch.load(f\"{path}/sft.pt\", map_location=\"cpu\", weights_only=False)\n", "model = GPT(ckpt[\"config\"]); model.load_state_dict(ckpt[\"model\"]); model.eval()\n", "UID, AID, EOT = (tok.token_to_id(t) for t in (\"<|user|>\", \"<|assistant|>\", \"<|endoftext|>\"))\n", "TEMPLATE = \"Turn this into a strong, quantified PM resume bullet:\\n{}\"\n", "\n", "def rewrite(bullet, temperature=0.5, top_k=20, max_new_tokens=70):\n", " ids = [UID] + tok.encode(TEMPLATE.format(bullet.strip())).ids + [AID]\n", " with torch.no_grad():\n", " out = model.generate(torch.tensor([ids]), max_new_tokens=int(max_new_tokens),\n", " temperature=float(temperature), top_k=int(top_k))\n", " new = out[0, len(ids):].tolist()\n", " if EOT in new: new = new[:new.index(EOT)]\n", " return tok.decode(new).strip()\n", "\n", "print(rewrite(\"Responsible for managing the product roadmap for the mobile app.\"))" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import gradio as gr\n", "gr.Interface(\n", " fn=rewrite,\n", " inputs=[gr.Textbox(label=\"Your resume bullet\", lines=3),\n", " gr.Slider(0.2, 1.2, value=0.5, label=\"Temperature\"),\n", " gr.Slider(1, 100, value=20, step=1, label=\"Top-k\"),\n", " gr.Slider(20, 120, value=70, step=5, label=\"Max new tokens\")],\n", " outputs=gr.Textbox(label=\"Sid-GPT rewrite\", lines=4),\n", " title=\"Sid-GPT: PM resume bullet rewriter\",\n", ").launch(share=True)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }