{ "nbformat": 4, "nbformat_minor": 5, "metadata": { "colab": { "name": "Chandassu inference", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" }, "license": "LicenseRef-Chandassu-Citation" }, "cells": [ { "cell_type": "markdown", "id": "introduction", "metadata": {}, "source": [ "# Chandassu: Telugu poem meter recognition\n", "\n", "Use a fresh Colab runtime and run the two code cells below. This notebook uses\n", "Colab's preinstalled packages; there is no installation cell.\n", "CNN is selected by default and works on CPU. Choose `byt5` to use the original ByT5 model.\n", "\n", "If you ran the earlier notebook that installed older PyTorch/Transformers packages,\n", "first select **Runtime → Disconnect and delete runtime**, then reconnect.\n", "Restarting Python alone does not undo those package installations.\n", "[Colab runtime reset documentation](https://research.google.com/colaboratory/faq.html)\n", "\n", "The model predicts **ఉత్పలమాల, చంపకమాల, మత్తేభము, శార్దూలం**.\n", "Paste one line or a complete four-line poem into the prediction cell.\n" ] }, { "cell_type": "code", "id": "load-model", "metadata": {}, "source": [ "#@title Load a model\n", "model_type = \"cnn\" #@param [\"cnn\", \"byt5\"]\n", "\n", "import torch\n", "import transformers\n", "from transformers import AutoModelForSequenceClassification, AutoTokenizer\n", "\n", "repo = \"sprx7767/chandassu-recognition\"\n", "options = {\n", " \"subfolder\": model_type,\n", " \"trust_remote_code\": True,\n", "}\n", "device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n", "tokenizer = AutoTokenizer.from_pretrained(repo, **options)\n", "model = AutoModelForSequenceClassification.from_pretrained(\n", " repo, use_safetensors=True, **options\n", ").to(device).eval()\n", "print(f\"Loaded {model_type.upper()} seed {model.config.seed} on {device.upper()}\")\n", "print(f\"PyTorch {torch.__version__}; Transformers {transformers.__version__}\")\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "id": "predict-poem", "metadata": {}, "source": [ "# Edit the text below, keeping each poem line on its own line, then run this cell.\n", "poem = \"\"\"శ్రీ కైవల్య పదంబుఁ జేరుటకునై చింతించెదన్ లోక ర\n", "క్షైకారంభకు, భక్త పాలన కళా సంరంభకున్, దానవో\n", "ద్రేకస్తంభకుఁ, గేళి లోల విలసద్దృగ్జాల సంభూత నా\n", "నా కంజాత భవాండ కుంభకు, మహానందాంగనాడింభకున్.\"\"\"\n", "\n", "lines = [line.strip() for line in poem.splitlines() if line.strip()]\n", "if len(lines) not in (1, 4):\n", " raise ValueError(\"Supply one line or a complete four-line poem\")\n", "inputs = tokenizer(lines, padding=True, return_tensors=\"pt\").to(device)\n", "with torch.inference_mode():\n", " logits = model(**inputs).logits\n", " line_scores = (logits.double() / model.config.calibration_temperature).softmax(dim=-1)\n", " scores = line_scores.mean(dim=0)\n", "\n", "winner = int(scores.argmax().item())\n", "print(f\"Predicted meter: {model.config.id2label[winner]} ({scores[winner].item():.2%})\")\n", "print(\"\\nClass probabilities:\")\n", "for index, score in enumerate(scores):\n", " print(f\" {model.config.id2label[index]}: {score.item():.2%}\")\n", "print(\"\\nLine predictions:\")\n", "for number, probabilities in enumerate(line_scores, start=1):\n", " index = int(probabilities.argmax().item())\n", " print(f\" Line {number}: {model.config.id2label[index]} ({probabilities[index].item():.2%})\")\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "id": "limits-citation", "metadata": {}, "source": [ "`trust_remote_code=True` loads the current published custom tokenizer and classifier.\n", "It does not install or replace Python packages.\n", "\n", "Predictions divide line logits by the model's saved calibration temperature, then\n", "average line probabilities for a four-line poem. A generic pipeline's softmax does\n", "not perform this calibration and poem aggregation.\n", "\n", "CNN accepts up to 256 characters per line. ByT5 accepts up to 1,024 UTF-8 byte tokens,\n", "including the end token. The tokenizer rejects overlong input.\n", "Scores are class probabilities, not confidence intervals. These models cover only\n", "the four listed meters and do not generate prosodic explanations.\n", "\n", "See the [model card](https://huggingface.co/sprx7767/chandassu-recognition) for results,\n", "provenance, and licensing. Cite Pranav Surampudi,\n", "*Chandassu Recognition: Telugu Poetic Meter Classification* (2026).\n", "[Project code](https://github.com/Pranav-20186017/chandassu_recognition) ·\n", "[Citation metadata](https://huggingface.co/sprx7767/chandassu-recognition/blob/main/cnn/CITATION.cff)\n" ] } ] }