{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Proofbird grammar model (French): quick start\n", "\n", "Run [`proofbird/gector-bert-fr`](https://huggingface.co/proofbird/gector-bert-fr) in a few lines. It is small (about 450 MB), runs on a CPU in about\n", "30 ms a sentence, and needs no API key." ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "!pip install -q onnxruntime tokenizers huggingface_hub" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Load the model and correct a sentence\n", "\n", "`quickstart.py`, published with the model, downloads it, runs it, and returns the corrected text plus one suggestion per\n", "change (character position, original, replacement)." ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import importlib.util\n", "from huggingface_hub import hf_hub_download\n", "\n", "path = hf_hub_download(\"proofbird/gector-bert-fr\", \"quickstart.py\")\n", "spec = importlib.util.spec_from_file_location(\"quickstart\", path)\n", "quickstart = importlib.util.module_from_spec(spec)\n", "spec.loader.exec_module(quickstart)\n", "\n", "model = quickstart.Gector(\"proofbird/gector-bert-fr\")\n", "corrected, suggestions = model.correct(\"Ma sœur sont très content.\")\n", "print(corrected)\n", "suggestions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. See every pass\n", "\n", "The model does not write text. For every word it picks one of 5 000 edits; the corrected sentence goes back in until\n", "nothing changes, so connected errors are fixed one after the other. `verbose=True` prints what each pass sent and got\n", "back." ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "corrected, suggestions = model.correct(\"Ma sœur sont très content.\", verbose=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Your own text\n", "\n", "`model.passes` holds the same per-pass detail as a list of dictionaries, if you want to build on it." ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "text = \"Les enfants joue dans le jardin.\"\n", "print(model.correct(text)[0])\n", "model.passes[0][\"words\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "Published by Patrick Andrew Hartnett. The [Proofbird](https://proofbird.app) writing assistant for Windows uses this\n", "model on-device and adds the guards in `gector-guards.json` and an explanation for each change. If you build on this\n", "model, a link back is appreciated." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" }, "colab": { "provenance": [] } }, "nbformat": 4, "nbformat_minor": 5 }