# text ## R Language Analysis Suite An R-package for analyzing natural language with transformers-based large language models. The `text` package is part of the *R Language Analysis Suite*, including: - [`talk`](https://www.r-talk.org/) - a package that transforms voice recordings into text, audio features, or embeddings. - [`text`](https://www.r-text.org/) - a package that provides tools for many language tasks such as converting digital text into word embeddings. `talk` and `text` offer access to Large Language Models from Hugging Face. - [`topics`](https://www.r-topics.org/) a package with tools for visualizing language patterns into topics. - [`the L-BAM Library`](https://r-text.org/articles/LBAM.html) a library that provides pre-trained models for different psychological assessments such as mental health issues, personality and related behaviours. ![](reference/figures/talk_text_topics.svg) The *R Language Analysis Suite* is created through a collaboration between psychology and computer science to address research needs and ensure state-of-the-art techniques. The suite is continuously tested on Ubuntu, Mac OS and Windows using the latest stable R version. The *text*-package has two main objectives: \* First, to serve R-users as a *point solution* for transforming text to state-of-the-art word embeddings that are ready to be used for downstream tasks. The package provides a user-friendly link to language models based on transformers from [Hugging Face](https://huggingface.co/). \* Second, to serve as an *end-to-end solution* that provides state-of-the-art AI techniques tailored for social and behavioral scientists. Please reference our tutorial article when using the `text` package: [The text-package: An R-package for Analyzing and Visualizing Human Language Using Natural Language Processing and Deep Learning](https://pubmed.ncbi.nlm.nih.gov/37126041/). > ### đŸ“£ Online Workshop: *Analysing Human Language using R* > > **August 11–13, 2026** — three half-day sessions (2:00–5:00 pm CEST / > 8:00–11:00 am ET) > > Learn the full *R Language Analysis Suite* — > [`talk`](https://www.r-talk.org/), [`text`](https://www.r-text.org/), > and [`topics`](https://www.r-topics.org/) — with Oscar Kjell. > > **[Read more & register →](https://smart-workshops.com/lang-r-info)** ### Point solution for transforming text to embeddings Recent significant advances in NLP research have resulted in improved representations of human language (i.e., language models). These language models have produced big performance gains in tasks related to understanding human language. Text are making these SOTA models easily accessible through an interface to [HuggingFace](https://huggingface.co/docs/transformers/index) in Python. *Text* provides many of the contemporary state-of-the-art language models that are based on deep learning to model word order and context. Multilingual language models can also represent several languages; multilingual BERT comprises *104 different languages*. *Table 1. Some of the available language models* | Models | References | Layers | Dimensions | Language | |:---|:---|:---|:---|:---| | ‘bert-base-uncased’ | [Devlin et al. 2019](https://aclanthology.org/N19-1423/) | 12 | 768 | English | | ‘roberta-base’ | [Liu et al. 2019](https://arxiv.org/abs/1907.11692) | 12 | 768 | English | | ‘distilbert-base-cased’ | [Sahn et al., 2019](https://arxiv.org/abs/1910.01108) | 6 | 768 | English | | ‘bert-base-multilingual-cased’ | [Devlin et al. 2019](https://aclanthology.org/N19-1423/) | 12 | 768 | [104 top languages at Wikipedia](https://meta.wikimedia.org/wiki/List_of_Wikipedias) | | ‘xlm-roberta-large’ | [Liu et al](https://arxiv.org/pdf/1907.11692) | 24 | 1024 | [100 language](https://huggingface.co/docs/transformers/multilingual) | See [HuggingFace](https://huggingface.co/models/) for a more comprehensive list of models. ### An end-to-end package *Text* also provides functions to analyse the word embeddings with well-tested machine learning algorithms and statistics. The focus is to analyze and visualize text, and their relation to other text or numerical variables. For example, the [`textTrain()`](https://r-text.org/reference/textTrain.md) function is used to examine how well the word embeddings from a text can predict a numeric or categorical variable. Another example is functions plotting statistically significant words in the word embedding space. # Package index ## Installation - [`textrpp_install()`](https://r-text.org/reference/textrpp_install.md) [`textrpp_install_virtualenv()`](https://r-text.org/reference/textrpp_install.md) : Install text required python packages in conda or virtualenv environment - [`textrpp_uninstall()`](https://r-text.org/reference/textrpp_uninstall.md) : Uninstall textrpp conda environment - [`textrpp_initialize()`](https://r-text.org/reference/textrpp_initialize.md) : Initialize text required python packages - [`textDiagnostics()`](https://r-text.org/reference/textDiagnostics.md) : Run diagnostics for the text package ## Transform text to word embeddings - [`textEmbed()`](https://r-text.org/reference/textEmbed.md) : textEmbed() extracts layers and aggregate them to word embeddings, for all character variables in a given dataframe. - [`textDimName()`](https://r-text.org/reference/textDimName.md) : Change dimension names - [`textEmbedRawLayers()`](https://r-text.org/reference/textEmbedRawLayers.md) : Extract layers of hidden states - [`textEmbedLayerAggregation()`](https://r-text.org/reference/textEmbedLayerAggregation.md) : Aggregate layers - [`textEmbedReduce()`](https://r-text.org/reference/textEmbedReduce.md) : Pre-trained dimension reduction (experimental) - [`textEmbedStatic()`](https://r-text.org/reference/textEmbedStatic.md) : Apply static word embeddings ## Fine-tuning models - [`textFineTuneTask()`](https://r-text.org/reference/textFineTuneTask.md) : Task Adapted Pre-Training (EXPERIMENTAL - under development) - [`textFineTuneDomain()`](https://r-text.org/reference/textFineTuneDomain.md) : Domain Adapted Pre-Training (EXPERIMENTAL - under development) ## Text language analysis tasks - [`textGeneration()`](https://r-text.org/reference/textGeneration.md) : Text generation - [`textNER()`](https://r-text.org/reference/textNER.md) : Named Entity Recognition. (experimental) - [`textSum()`](https://r-text.org/reference/textSum.md) : Summarize texts. (experimental) - [`textQA()`](https://r-text.org/reference/textQA.md) : Question Answering. (experimental) - [`textTranslate()`](https://r-text.org/reference/textTranslate.md) : Translation. (experimental) - [`textZeroShot()`](https://r-text.org/reference/textZeroShot.md) : Zero Shot Classification (Experimental) ## The text-train functions - [`textTrain()`](https://r-text.org/reference/textTrain.md) : Trains word embeddings - [`textTrainLists()`](https://r-text.org/reference/textTrainLists.md) : Train lists of word embeddings - [`textTrainRegression()`](https://r-text.org/reference/textTrainRegression.md) : Train word embeddings to a numeric variable. - [`textTrainRandomForest()`](https://r-text.org/reference/textTrainRandomForest.md) : Trains word embeddings usig random forest - [`textTrainN()`](https://r-text.org/reference/textTrainN.md) : Cross-validated accuracies across sample-sizes - [`textTrainNPlot()`](https://r-text.org/reference/textTrainNPlot.md) : Plot cross-validated accuracies across sample sizes - [`textExamples()`](https://r-text.org/reference/textExamples.md) : Identify language examples. ## The text-predict functions - [`textPredict()`](https://r-text.org/reference/textPredict.md) [`textAssess()`](https://r-text.org/reference/textPredict.md) [`textClassify()`](https://r-text.org/reference/textPredict.md) : textPredict, textAssess and textClassify - [`textPredictTest()`](https://r-text.org/reference/textPredictTest.md) : Significance testing for model prediction performance - [`textPredictAll()`](https://r-text.org/reference/textPredictAll.md) : Predict from several models, selecting the correct input - [`textLBAM()`](https://r-text.org/reference/textLBAM.md) : The LBAM library ## Semantic similarities and distances functions - [`textSimilarity()`](https://r-text.org/reference/textSimilarity.md) : Semantic Similarity - [`textDistance()`](https://r-text.org/reference/textDistance.md) : Semantic distance - [`textSimilarityMatrix()`](https://r-text.org/reference/textSimilarityMatrix.md) : Semantic similarity across multiple word embeddings - [`textDistanceMatrix()`](https://r-text.org/reference/textDistanceMatrix.md) : Semantic distance across multiple word embeddings - [`textSimilarityNorm()`](https://r-text.org/reference/textSimilarityNorm.md) : Semantic similarity between a text variable and a word norm - [`textDistanceNorm()`](https://r-text.org/reference/textDistanceNorm.md) : Semantic distance between a text variable and a word norm ## Visualise words in the word embedding space - [`textProjection()`](https://r-text.org/reference/textProjection.md) : Supervised Dimension Projection - [`textWordPrediction()`](https://r-text.org/reference/textWordPrediction.md) : Compute word-level prediction scores for plotting with textProjectionPlot(). - [`textPlot()`](https://r-text.org/reference/textPlot.md) : Plot words - [`textProjectionPlot()`](https://r-text.org/reference/textProjectionPlot.md) : Plot Supervised Dimension Projection - [`textCentrality()`](https://r-text.org/reference/textCentrality.md) : Semantic similarity score between single words' and an aggregated word embeddings - [`textCentralityPlot()`](https://r-text.org/reference/textCentralityPlot.md) : Plots words from textCentrality() - [`textPCA()`](https://r-text.org/reference/textPCA.md) : textPCA() - [`textPCAPlot()`](https://r-text.org/reference/textPCAPlot.md) : textPCAPlot ## BERTopics - [`textTopics()`](https://r-text.org/reference/textTopics.md) [`textBERTopics()`](https://r-text.org/reference/textTopics.md) : BERTopic - [`textTopicsTest()`](https://r-text.org/reference/textTopicsTest.md) : Wrapper for topicsTest function from the topics package - [`textTopicsWordcloud()`](https://r-text.org/reference/textTopicsWordcloud.md) : Plot word clouds - [`textTopicsReduce()`](https://r-text.org/reference/textTopicsReduce.md) : textTopicsReduce (EXPERIMENTAL) - [`textTopicsTree()`](https://r-text.org/reference/textTopicsTree.md) : textTopicsTest (EXPERIMENTAL) to get the hierarchical topic tree ## View or delete downloaded HuggingFace models - [`textModels()`](https://r-text.org/reference/textModels.md) : Check downloaded, available models. - [`textModelLayers()`](https://r-text.org/reference/textModelLayers.md) : Number of layers - [`textModelsRemove()`](https://r-text.org/reference/textModelsRemove.md) : Delete a specified model ## Miscellaneous - [`textDescriptives()`](https://r-text.org/reference/textDescriptives.md) : Compute descriptive statistics of character variables. - [`textClean()`](https://r-text.org/reference/textClean.md) : Cleans text from standard personal information - [`textTokenize()`](https://r-text.org/reference/textTokenize.md) : Tokenize text-variables - [`textTokenizeAndCount()`](https://r-text.org/reference/textTokenizeAndCount.md) : Tokenize and count - [`textDomainCompare()`](https://r-text.org/reference/textDomainCompare.md) : Compare two language domains - [`textFindNonASCII()`](https://r-text.org/reference/textFindNonASCII.md) : Detect non-ASCII characters - [`textCleanNonASCII()`](https://r-text.org/reference/textCleanNonASCII.md) : Clean non-ASCII characters ## Example Data - [`Language_based_assessment_data_8`](https://r-text.org/reference/Language_based_assessment_data_8.md) : Text and numeric data for 10 participants. - [`word_embeddings_4`](https://r-text.org/reference/word_embeddings_4.md) : Word embeddings for 4 text variables for 40 participants - [`raw_embeddings_1`](https://r-text.org/reference/raw_embeddings_1.md) : Word embeddings from textEmbedRawLayers function - [`Language_based_assessment_data_3_100`](https://r-text.org/reference/Language_based_assessment_data_3_100.md) : Example text and numeric data. - [`DP_projections_HILS_SWLS_100`](https://r-text.org/reference/DP_projections_HILS_SWLS_100.md) : Data for plotting a Dot Product Projection Plot. - [`centrality_data_harmony`](https://r-text.org/reference/centrality_data_harmony.md) : Example data for plotting a Semantic Centrality Plot. - [`PC_projections_satisfactionwords_40`](https://r-text.org/reference/PC_projections_satisfactionwords_40.md) : Example data for plotting a Principle Component Projection Plot. # Articles ### Resources - [Resources](https://r-text.org/articles/resources.md): ### Set-up - [The Language-Based Assessment Model (L-BAM) Library](https://r-text.org/articles/LBAM.md): - [Extended Installation Guide](https://r-text.org/articles/ext_install_guide.md): - [Installing and Managing Python Environments with \`reticulate\`](https://r-text.org/articles/reticulate.md): - [Creating a Singularity Container to Run HuggingFace Transformers Models in R](https://r-text.org/articles/singularity_transformers_container.md): - [How to best manage computationally heavy analyses](https://r-text.org/articles/huggingface_in_r_and_computer_capacity.md): - [HuggingFace language models are downloaded in .cache](https://r-text.org/articles/removing_huggingface_transformers_cache_files.md): ### Tutorials These tutorials go into detail about various text-analyses. - [HuggingFace Transformers in R: Word Embeddings Defaults and Specifications](https://r-text.org/articles/huggingface_in_r.md): - [Psychological Methods: the Text Tutorial](https://r-text.org/articles/psychological_methods.md): - [L-BAM Tutorial](https://r-text.org/articles/lbam_tutorial.md): - [Implicit Motives Tutorial](https://r-text.org/articles/implicit_motives_tutorial.md): ### Comments General comments about text-analyses. - [Pre-registration and Researcher Degrees of Freedom](https://r-text.org/articles/pre_registration_and_transformers.md):