Learn R Programming

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 - a package that transforms voice recordings into text, audio features, or embeddings.
  • text - 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 a package with tools for visualizing language patterns into topics.
  • the L-BAM Library a library that provides pre-trained models for different psychological assessments such as mental health issues, personality and related behaviours.

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. * 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.

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 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

ModelsReferencesLayersDimensionsLanguage
‘bert-base-uncased’Devlin et al. 201912768English
‘roberta-base’Liu et al. 201912768English
‘distilbert-base-cased’Sahn et al., 20196768English
‘bert-base-multilingual-cased’Devlin et al. 201912768104 top languages at Wikipedia
‘xlm-roberta-large’Liu et al241024100 language

See HuggingFace 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() 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.

Copy Link

Version

Install

install.packages('text')

Monthly Downloads

1,904

Version

1.8.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Oscar Kjell

Last Published

February 16th, 2026

Functions in text (1.8.1)

textEmbedStatic

Apply static word embeddings
textEmbedRawLayers

Extract layers of hidden states
textPredictAll

Predict from several models, selecting the correct input
textProjection

Supervised Dimension Projection
textGeneration

Text generation
textExamples

Identify language examples.
textPredict

textPredict, textAssess and textClassify
textFineTuneTask

Task Adapted Pre-Training (EXPERIMENTAL - under development)
textPredictTest

Significance testing for model prediction performance
textModels

Check downloaded, available models.
textEmbedReduce

Pre-trained dimension reduction (experimental)
textPlot

Plot words
textModelsRemove

Delete a specified model
textDescriptives

Compute descriptive statistics of character variables.
textPCAPlot

textPCAPlot
textNER

Named Entity Recognition. (experimental)
textPCA

textPCA()
textModelLayers

Number of layers
textLBAM

The LBAM library
textTopics

BERTopic
textTopicsReduce

textTopicsReduce (EXPERIMENTAL)
textSum

Summarize texts. (experimental)
textQA

Question Answering. (experimental)
textSimilarity

Semantic Similarity
textSimilarityMatrix

Semantic similarity across multiple word embeddings
textProjectionPlot

Plot Supervised Dimension Projection
textSimilarityNorm

Semantic similarity between a text variable and a word norm
textFindNonASCII

Detect non-ASCII characters
textZeroShot

Zero Shot Classification (Experimental)
textTopicsTest

Wrapper for topicsTest function from the topics package
textTranslate

Translation. (experimental)
textTrainRegression

Train word embeddings to a numeric variable.
textTopicsWordcloud

Plot word clouds
textrpp_initialize

Initialize text required python packages
textTokenizeAndCount

Tokenize and count
textFineTuneDomain

Domain Adapted Pre-Training (EXPERIMENTAL - under development)
textTokenize

Tokenize text-variables
textTrainNPlot

Plot cross-validated accuracies across sample sizes
textTrainRandomForest

Trains word embeddings usig random forest
textTrain

Trains word embeddings
textrpp_uninstall

Uninstall textrpp conda environment
textrpp_install

Install text required python packages in conda or virtualenv environment
textTrainLists

Train lists of word embeddings
textTrainN

Cross-validated accuracies across sample-sizes
textTopicsTree

textTopicsTest (EXPERIMENTAL) to get the hierarchical topic tree
word_embeddings_4

Word embeddings for 4 text variables for 40 participants
textCentrality

Semantic similarity score between single words' and an aggregated word embeddings
Language_based_assessment_data_8

Text and numeric data for 10 participants.
textClean

Cleans text from standard personal information
textCentralityPlot

Plots words from textCentrality()
textDiagnostics

Run diagnostics for the text package
textDimName

Change dimension names
textDomainCompare

Compare two language domains
textDistanceNorm

Semantic distance between a text variable and a word norm
textDistanceMatrix

Semantic distance across multiple word embeddings
textEmbedLayerAggregation

Aggregate layers
textDistance

Semantic distance
textEmbed

textEmbed() extracts layers and aggregate them to word embeddings, for all character variables in a given dataframe.
textCleanNonASCII

Clean non-ASCII characters
centrality_data_harmony

Example data for plotting a Semantic Centrality Plot.
find_textrpp_env

Find text required python packages env
PC_projections_satisfactionwords_40

Example data for plotting a Principle Component Projection Plot.
DP_projections_HILS_SWLS_100

Data for plotting a Dot Product Projection Plot.
raw_embeddings_1

Word embeddings from textEmbedRawLayers function
Language_based_assessment_data_3_100

Example text and numeric data.