{"id":27879381,"url":"https://github.com/gesistsa/grafzahl","last_synced_at":"2025-05-05T03:21:18.675Z","repository":{"id":65380552,"uuid":"505463375","full_name":"gesistsa/grafzahl","owner":"gesistsa","description":"🧛 fine-tuning Transformers for text data from within R","archived":false,"fork":false,"pushed_at":"2025-02-19T14:00:03.000Z","size":5211,"stargazers_count":41,"open_issues_count":4,"forks_count":2,"subscribers_count":4,"default_branch":"v0.1","last_synced_at":"2025-04-26T09:39:44.119Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://gesistsa.github.io/grafzahl/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gesistsa.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2022-06-20T13:56:26.000Z","updated_at":"2025-02-19T14:00:07.000Z","dependencies_parsed_at":"2024-03-18T16:14:23.056Z","dependency_job_id":"688ea411-bab8-4f43-aa6d-7e9a6fa8a4e4","html_url":"https://github.com/gesistsa/grafzahl","commit_stats":null,"previous_names":["gesistsa/grafzahl","chainsawriot/grafzahl"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gesistsa%2Fgrafzahl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gesistsa%2Fgrafzahl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gesistsa%2Fgrafzahl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gesistsa%2Fgrafzahl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gesistsa","download_url":"https://codeload.github.com/gesistsa/grafzahl/tar.gz/refs/heads/v0.1","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252430272,"owners_count":21746629,"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":"2025-05-05T03:21:17.969Z","updated_at":"2025-05-05T03:21:18.657Z","avatar_url":"https://github.com/gesistsa.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# grafzahl \u003cimg src=\"man/figures/grafzahl_logo.png\" align=\"right\" height=\"139\" /\u003e\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/grafzahl)](https://CRAN.R-project.org/package=grafzahl)\n\u003c!-- badges: end --\u003e\n\nThe goal of grafzahl (**G**racious **R** **A**nalytical **F**ramework for **Z**appy **A**nalysis of **H**uman **L**anguages [^1]) is to duct tape the [quanteda](https://github.com/quanteda/quanteda) ecosystem to modern [Transformer-based text classification models](https://simpletransformers.ai/), e.g. BERT, RoBERTa, etc. The model object looks and feels like the textmodel S3 object from the package [quanteda.textmodels](https://github.com/quanteda/quanteda.textmodels).\n\nIf you don't know what I am talking about, don't worry, this package is gracious. You don't need to know a lot about Transformers to use this package. See the examples below.\n\nPlease cite this software as:\n\nChan, C., (2023). [grafzahl: fine-tuning Transformers for text data from within R](paper/grafzahl_sp.pdf). *Computational Communication Research* 5(1): 76-84. [https://doi.org/10.5117/CCR2023.1.003.CHAN](https://doi.org/10.5117/CCR2023.1.003.CHAN)\n\n## Installation: Local environment\n\nInstall the CRAN version\n\n```r\ninstall.packages(\"grafzahl\")\n```\n\nAfter that, you need to setup your conda environment\n\n```r\nrequire(grafzahl)\nsetup_grafzahl(cuda = TRUE) ## if you have GPU(s)\n```\n\n## On remote environments, e.g. Google Colab\n\nOn Google Colab, you need to enable non-Conda mode\n\n```r\ninstall.packages(\"grafzahl\")\nrequire(grafzahl)\nuse_nonconda()\n```\n\nPlease refer the vignette.\n\n## Usage\n\nSuppose you have a bunch of tweets in the quanteda corpus format. And the corpus has exactly one docvar that denotes the labels you want to predict. The data is from [this repository](https://github.com/pablobarbera/incivility-sage-open) (Theocharis et al., 2020).\n\n```{r, echo = FALSE, message = FALSE}\ndevtools::load_all()\n```\n\n```{r}\nunciviltweets\n```\n\nIn order to train a Transfomer model, please select the `model_name` from [Hugging Face's list](https://huggingface.co/models). The table below lists some common choices. In most of the time, providing `model_name` is sufficient, there is no need to provide `model_type`.\n\nSuppose you want to train a Transformer model using \"bertweet\" (Nguyen et al., 2020) because it matches your domain of usage. By default, it will save the model in the `output` directory of the current directory. You can change it to elsewhere using the `output_dir` parameter. \n\n```r\nmodel \u003c- grafzahl(unciviltweets, model_type = \"bertweet\", model_name = \"vinai/bertweet-base\")\n### If you are hardcore quanteda user:\n## model \u003c- textmodel_transformer(unciviltweets,\n##                                model_type = \"bertweet\", model_name = \"vinai/bertweet-base\")\n```\n\nMake prediction\n\n```r\npredict(model)\n```\n\nThat is it.\n\n## Extended examples\n\nSeveral extended examples are also available.\n\n| Examples                                        | file                                           |\n|-------------------------------------------------|------------------------------------------------|\n| van Atteveldt et al. (2021)                     | [paper/vanatteveldt.md](paper/vanatteveldt.md) |\n| Dobbrick et al. (2021)                          | [paper/dobbrick.md](paper/dobbrick.md)         |\n| Theocharis et al. (2020)                        | [paper/theocharis.md](paper/theocharis.md)     |\n| OffensEval-TR (2020)                            | [paper/coltekin.md](paper/coltekin.md)         |\n| Amharic News Text classification Dataset (2021) | [paper/azime.md](paper/azime.md)               |\n\n## Some common choices of `model_name`\n\n| Your data         | model_type | model_name                         |\n|-------------------|------------|------------------------------------|\n| English tweets    | bertweet   | vinai/bertweet-base                |\n| Lightweight       | mobilebert | google/mobilebert-uncased          |\n|                   | distilbert | distilbert-base-uncased            |\n| Long Text         | longformer | allenai/longformer-base-4096       |\n|                   | bigbird    | google/bigbird-roberta-base        |\n| English (General) | bert       | bert-base-uncased                  |\n|                   | bert       | bert-base-cased                    |\n|                   | electra    | google/electra-small-discriminator |\n|                   | roberta    | roberta-base                       |\n| Multilingual      | xlm        | xlm-mlm-17-1280                    |\n|                   | xml        | xlm-mlm-100-1280                   |\n|                   | bert       | bert-base-multilingual-cased       |\n|                   | xlmroberta | xlm-roberta-base                   |\n|                   | xlmroberta | xlm-roberta-large                  |\n\n# References\n\n1. Theocharis, Y., Barberá, P., Fazekas, Z., \u0026 Popa, S. A. (2020). The dynamics of political incivility on Twitter. Sage Open, 10(2), 2158244020919447.\n2. Nguyen, D. Q., Vu, T., \u0026 Nguyen, A. T. (2020). BERTweet: A pre-trained language model for English Tweets. arXiv preprint arXiv:2005.10200.\n\n---\n[^1]: Yes, I totally made up the meaningless long name. Actually, it is the German name of the *Sesame Street* character [Count von Count](https://de.wikipedia.org/wiki/Sesamstra%C3%9Fe#Graf_Zahl), meaning \"Count (the noble title) Number\". And it seems to be so that it is compulsory to name absolutely everything related to Transformers after Seasame Street characters.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgesistsa%2Fgrafzahl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgesistsa%2Fgrafzahl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgesistsa%2Fgrafzahl/lists"}