Skip to content

flairR: An R Wrapper for Accessing Flair NLP Library

R-MacOS R-ubuntu R-Windows R Docker Image codecov CodeFactor

flaiR is an R package that provides convenient access to flairNLP/flair, a powerful Python-based NLP toolkit developed Zalando Research.

flaiR R package provides R-friendly wrapper functions integrated with R community packages for quantitative text analysis.


Required Softwares

  • Python >= 3.9 (Python 3.10 is recommended)
  • R >= 4.1.3
  • Rstudio

Operation Systems

OS R Versions Python Version CI Status
Mac 4.1.3, 4.2.3, 4.3.2 and recent 3.10.x, 3.9 R-MacOS
Windows 4.1.3, 4.2.3, 4.3.2 and recent 3.10.x, 3.9 R-Windows
Ubuntu 4.1.3, 4.2.3, 4.3.2 and recent 3.10.x, 3.9 R-ubuntu

*: On R 4.2.1 and 4.0.5, particularly when using the Matrix package on ARM 64 architecture Macs (M1/M2/M3), compatibility issues with gfortran may occur. It’s recommended to avoid these versions.


Fast Install flaiR with remotes

Prerequisites

Before installing flaiR, ensure you have Python (>= 3.9.0) and the following Python dependencies: - PyTorch (>= 2.2.0) - Transformers (>= 4.37.2) - Flair (>= 0.11.3)

Step 1: Install and Load reticulate Package

# Install reticulate package
install.packages("reticulate")
# Load reticulate library
library(reticulate)

Step 2: Check Existing Python Configuration

If not, recommend referring to the Quick Start-flaiR Installation. This quick install guide provides step-by-step instructions for installing recommended Python with reticulate.

To install flaiR package

install.packages("remotes")
remotes::install_github("davidycliao/flaiR", force = TRUE)
#> Environment Information:
#> OS: Darwin (15.2)
#> Using existing Python: /usr/local/bin/python3.10
#> Python               ✓  3.10
#> GPU                  ✓  Mac MPS

#> PyTorch              ✓  2.2.2
#> Transformers         ✓  4.40.1
#> Flair NLP            ✓  0.13.1
#> Word Embeddings      ✓  4.3.2
#> flaiR: An R Wrapper for Accessing Flair NLP 0.13.1

If you have never used gensim before and gensim dependencies are not detected, you will see a message like:

#> Environment Information:
#> OS: Darwin (15.2)
#> Using existing Python: /usr/local/bin/python3.10
#> Python               ✓  3.10
#> GPU                  ✓  Mac MPS

#> PyTorch              ✓  2.2.2
#> Transformers         ✓  4.40.1
#> Flair NLP            ✓  0.13.1
#> Word Embeddings      ✗  Not Available
#> Word embeddings feature is not detected.

#> Install with:
#> In R:
#>  reticulate::py_install('flair[word-embeddings]', pip = TRUE)
#>  system(paste(Sys.which('python3'), '-m pip install flair[word-embeddings]'))

#> In terminal:
#>  pip install flair[word-embeddings]
#> flaiR: An R Wrapper for Accessing Flair NLP 0.13.1


Installation with Docker

  • Intel/AMD Processors:
# Pull image
docker pull ghcr.io/davidycliao/flair-rstudio:latest

# Run container
docker run -d -p 8787:8787 --user root --name flair-rstudio ghcr.io/davidycliao/flair-rstudio:latest
  • Apple Silicon (M1/M2 Mac):
# Pull image
docker pull --platform linux/amd64 ghcr.io/davidycliao/flair-rstudio:latest

# Run container
docker run -d -p 8787:8787 --platform linux/amd64 --user root --name flair-rstudio ghcr.io/davidycliao/flair-rstudio:latest

After running these commands in terminal (or powershell), open your browser and navigate to http://localhost:8787 to access RStudio Server. For detailed installation instructions, please visit Quick Start Guide.


Contribution and Open Source

R developers who want to contribute to flaiR are welcome – flaiR is an open source project. We warmly invite R users who share similar interests to join in contributing to this package. Please feel free to shoot me an email us to collaborate on the task. Contributions – whether they be comments, code suggestions, tutorial examples, or forking the repository – are greatly appreciated. Please note that the flaiR is released with the Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

The primary communication channel for R users can be found here. Please feel free to share your insights on the Discussion page and report any issues related to the R interface in the Issue section. If the issue pertains to the actual implementation of Flair in Python, please submit a pull request to the offical flair NLP.