{"id":13706696,"url":"https://github.com/bnosac/sentencepiece","last_synced_at":"2026-02-09T22:05:13.330Z","repository":{"id":39695745,"uuid":"226341678","full_name":"bnosac/sentencepiece","owner":"bnosac","description":"R package for Byte Pair Encoding / Unigram modelling based on Sentencepiece","archived":false,"fork":false,"pushed_at":"2025-11-27T21:16:59.000Z","size":4789,"stargazers_count":27,"open_issues_count":2,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-12-09T16:07:20.900Z","etag":null,"topics":["byte","natural-language-processing","sentencepiece","word-segmentation"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bnosac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-06T13:59:59.000Z","updated_at":"2025-12-04T11:58:41.000Z","dependencies_parsed_at":"2023-01-21T02:46:20.183Z","dependency_job_id":null,"html_url":"https://github.com/bnosac/sentencepiece","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/bnosac/sentencepiece","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnosac%2Fsentencepiece","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnosac%2Fsentencepiece/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnosac%2Fsentencepiece/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnosac%2Fsentencepiece/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bnosac","download_url":"https://codeload.github.com/bnosac/sentencepiece/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnosac%2Fsentencepiece/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29283033,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T21:57:15.303Z","status":"ssl_error","status_checked_at":"2026-02-09T21:57:11.537Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["byte","natural-language-processing","sentencepiece","word-segmentation"],"created_at":"2024-08-02T22:01:05.639Z","updated_at":"2026-02-09T22:05:13.307Z","avatar_url":"https://github.com/bnosac.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# sentencepiece \n\nThis repository contains an R package which is an Rcpp wrapper around the sentencepiece C++ library\n\n- sentencepiece is an unsupervised tokeniser which allows to execute text tokenization using \n    - Byte Pair Encoding \n    - Unigrams\n    - Words\n    - Characters\n- It is based on the paper *SentencePiece: A simple and language independent subword tokenizer and detokenizer for Neural Text Processing* [[Taku Kudo, John Richardson.](https://aclanthology.org/D18-2012/)]\n- The sentencepiece C++ code is available at https://github.com/google/sentencepiece\n    - This package currently wraps release v0.1.96\n- This R package has similar functionalities as the R package https://github.com/bnosac/tokenizers.bpe\n\n## Features\n\nThe R package allows you to \n\n- build a Byte Pair Encoding (BPE), Unigram, Char or Word model\n- apply the model to encode text\n- apply the model to decode ids back to text\n- download pretrained sentencepiece models built on Wikipedia\n\n\n## Installation\n\n- For regular users, install the package from your local CRAN mirror `install.packages(\"sentencepiece\")`\n- For installing the development version of this package: `remotes::install_github(\"bnosac/sentencepiece\")`\n\nLook to the documentation of the functions\n\n```{r}\nhelp(package = \"sentencepiece\")\n```\n\n## Example on encoding / decoding with a pretrained model built on Wikipedia\n\n```{r}\nlibrary(sentencepiece)\ndl    \u003c- sentencepiece_download_model(\"English\", vocab_size = 50000)\nmodel \u003c- sentencepiece_load_model(dl$file_model)\nmodel\n```\n\n```\nSentencepiece model\n  size of the vocabulary: 50000\n  model stored at: C:/Users/Jan/Documents/R/win-library/3.5/sentencepiece/models/en.wiki.bpe.vs50000.model\n```\n\n```{r}\ntxt \u003c- c(\"Give me back my Money or I'll call the police.\",\n         \"Talk to the hand because the face don't want to hear it any more.\")\ntxt \u003c- tolower(txt)\nsentencepiece_encode(model, txt, type = \"subwords\")\n```\n\n```\n[[1]]\n [1] \"▁give\"   \"▁me\"     \"▁back\"   \"▁my\"     \"▁money\"  \"▁or\"     \"▁i\"      \"'\"       \"ll\"      \"▁call\"   \"▁the\"    \"▁police\" \".\"      \n\n[[2]]\n [1] \"▁talk\"    \"▁to\"      \"▁the\"     \"▁hand\"    \"▁because\" \"▁the\"     \"▁face\"    \"▁don\"     \"'\"        \"t\"        \"▁want\"    \"▁to\"      \"▁hear\"    \"▁it\"      \"▁any\"     \"▁more\"    \".\"\n```\n\n```{r}\nsentencepiece_encode(model, txt, type = \"ids\")\n```\n\n```\n[[1]]\n [1]  3090   352   810  1241  2795   127   386 49937  1188   612     7  2142 49935\n\n[[2]]\n [1]  4252    42     7  1197   936     7  3227  1616 49937 49915  4451    42  6800   107   756   407 49935\n```\n\n\n## Example on training\n\n- As an example, let's take some training data containing questions asked in Belgian Parliament in 2017 and focus on French text only.\n\n\n```{r}\nlibrary(tokenizers.bpe)\nlibrary(sentencepiece)\ndata(belgium_parliament, package = \"tokenizers.bpe\")\nx \u003c- subset(belgium_parliament, language == \"french\")\nwriteLines(text = x$text, con = \"traindata.txt\")\n```\n\n- Train a model on text data and inspect the vocabulary\n\n\n```{r}\nmodel \u003c- sentencepiece(\"traindata.txt\", type = \"bpe\", coverage = 0.999, vocab_size = 5000, \n                       model_dir = getwd(), verbose = FALSE)\nmodel\n```  \n\n```\nSentencepiece model\n  size of the vocabulary: 5000\n  model stored at: sentencepiece.model\n```\n\n```{r}\nstr(model$vocabulary)\n```\n\n```\n'data.frame':\t5000 obs. of  2 variables:\n $ id     : int  0 1 2 3 4 5 6 7 8 9 ...\n $ subword: chr  \"\u003cunk\u003e\" \"\u003cs\u003e\" \"\u003c/s\u003e\" \"es\" ...\n```\n\n\n- Use the model to encode text\n\n\n```{r}\ntext \u003c- c(\"L'appartement est grand \u0026 vraiment bien situe en plein centre\",\n          \"Proportion de femmes dans les situations de famille monoparentale.\")\nsentencepiece_encode(model, x = text, type = \"subwords\")\n```\n\n```\n[[1]]\n [1] \"▁L\"      \"'\"       \"app\"     \"ar\"      \"tement\"  \"▁est\"    \"▁grand\"  \"▁\"       \"\u0026\"       \"▁v\"      \"r\"       \"ai\"      \"ment\"    \"▁bien\"   \"▁situe\"  \"▁en\"     \"▁plein\"  \"▁centre\"\n\n[[2]]\n [1] \"▁Pro\"        \"por\"         \"tion\"        \"▁de\"         \"▁femmes\"     \"▁dans\"       \"▁les\"        \"▁situations\" \"▁de\"         \"▁famille\"    \"▁mon\"        \"op\"          \"ar\"          \"ent\"         \"ale\"         \".\" \n```\n\n```{r}\nsentencepiece_encode(model, x = text, type = \"ids\")\n```\n\n```\n[[1]]\n [1]   75 4951  252   31  461  109  960 4934    0   49 4941   34   32  585 4225   44 3356 1915\n\n[[2]]\n [1] 1362 4159   25    9 2060   93   40 3825    9 2923  705  247   31   19  116 4953\n```\n\n- Use the model to decode byte pair encodings back to text\n\n\n```{r}\nx \u003c- sentencepiece_encode(model, x = text, type = \"ids\")\nsentencepiece_decode(model, x)\n```\n\n```\n[[1]]\n[1] \"L'appartement est grand  ⁇  vraiment bien situe en plein centre\"\n\n[[2]]\n[1] \"Proportion de femmes dans les situations de famille monoparentale.\"\n```\n\n## Support in text mining\n\nNeed support in text mining?\nContact BNOSAC: http://www.bnosac.be\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnosac%2Fsentencepiece","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbnosac%2Fsentencepiece","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnosac%2Fsentencepiece/lists"}