{"id":21428302,"url":"https://github.com/mlverse/tok","last_synced_at":"2025-04-09T15:09:43.515Z","repository":{"id":154218307,"uuid":"630640283","full_name":"mlverse/tok","owner":"mlverse","description":"Tokenizers from HuggingFace","archived":false,"fork":false,"pushed_at":"2024-10-23T18:10:22.000Z","size":142341,"stargazers_count":42,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T15:09:37.690Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlverse.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-20T20:25:27.000Z","updated_at":"2024-11-13T15:54:31.000Z","dependencies_parsed_at":"2024-06-25T13:34:23.517Z","dependency_job_id":"ba777df9-ea07-4329-88a4-eedadaa420ff","html_url":"https://github.com/mlverse/tok","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":"extendr/helloextendr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlverse%2Ftok","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlverse%2Ftok/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlverse%2Ftok/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlverse%2Ftok/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlverse","download_url":"https://codeload.github.com/mlverse/tok/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055282,"owners_count":21040157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T22:12:34.266Z","updated_at":"2025-04-09T15:09:43.494Z","avatar_url":"https://github.com/mlverse.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# tok\n\n\u003c!-- badges: start --\u003e\n[![R build status](https://github.com/mlverse/tok/workflows/R-CMD-check/badge.svg)](https://github.com/mlverse/tok/actions)\n[![CRAN status](https://www.r-pkg.org/badges/version/tok)](https://CRAN.R-project.org/package=tok)\n[![](https://cranlogs.r-pkg.org/badges/tok)](https://cran.r-project.org/package=tok)\n\u003c!-- badges: end --\u003e\n\ntok provides bindings to the [🤗tokenizers](https://huggingface.co/docs/tokenizers/v0.13.3/en/index) library. It uses the same Rust libraries that powers the Python implementation.\n\nWe still don't provide the full API of tokenizers. Please open a issue if there's\na feature you are missing.\n\n## Installation\n\nYou can install tok from CRAN using:\n\n```\ninstall.packages(\"tok\")\n```\n\nInstalling tok from source requires working Rust toolchain. We recommend using [rustup.](https://rustup.rs/)\n\nOn Windows, you'll also have to add the `i686-pc-windows-gnu` and `x86_64-pc-windows-gnu` targets:\n\n    rustup target add x86_64-pc-windows-gnu\n    rustup target add i686-pc-windows-gnu\n\nOnce Rust is working, you can install this package via:\n\n``` r\nremotes::install_github(\"dfalbel/tok\")\n```\n\n## Features\n\nWe still don't have complete support for the 🤗tokenizers API. Please open an issue\nif you need a feature that is currently not implemented.\n\n## Loading tokenizers\n\n`tok` can be used to load and use tokenizers that have been previously serialized.\nFor example, HuggingFace model weights are usually accompanied by a 'tokenizer.json' \nfile that can be loaded with this library.\n\nTo load a pre-trained tokenizer from a json file, use:\n\n```{r}\npath \u003c- testthat::test_path(\"assets/tokenizer.json\")\ntok \u003c- tok::tokenizer$from_file(path)\n```\n\nUse the `encode` method to tokenize sentendes and `decode` to transform them back.\n\n```{r}\nenc \u003c- tok$encode(\"hello world\")\ntok$decode(enc$ids)\n```\n\n## Using pre-trained tokenizers\n\nYou can also load any tokenizer available in HuggingFace hub by using the `from_pretrained`\nstatic method. For example, let's load the GPT2 tokenizer with:\n\n```{r}\ntok \u003c- tok::tokenizer$from_pretrained(\"gpt2\")\nenc \u003c- tok$encode(\"hello world\")\ntok$decode(enc$ids)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlverse%2Ftok","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlverse%2Ftok","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlverse%2Ftok/lists"}