MyNixOS website logo
Description

Word Embedding Research Framework for Psychological Science.

An integrative toolbox of word embedding research that provides: (1) a collection of 'pre-trained' static word vectors in the '.RData' compressed format <https://psychbruce.github.io/WordVector_RData.pdf>; (2) a series of functions to process, analyze, and visualize word vectors; (3) a range of tests to examine conceptual associations, including the Word Embedding Association Test <doi:10.1126/science.aal4230> and the Relative Norm Distance <doi:10.1073/pnas.1720347115>, with permutation test of significance; (4) a set of training methods to locally train (static) word vectors from text corpora, including 'Word2Vec' <arXiv:1301.3781>, 'GloVe' <doi:10.3115/v1/D14-1162>, and 'FastText' <arXiv:1607.04606>; (5) a group of functions to download 'pre-trained' language models (e.g., 'GPT', 'BERT') and extract contextualized (dynamic) word vectors (based on the R package 'text').

PsychWordVec

Word Embedding Research Framework for Psychological Science.

An integrative toolbox of word embedding research that provides:

  1. A collection of pre-trained static word vectors in the .RData compressed format;
  2. A series of functions to process, analyze, and visualize word vectors;
  3. A range of tests to examine conceptual associations, including the Word Embedding Association Test (Caliskan et al., 2017) and the Relative Norm Distance (Garg et al., 2018), with permutation test of significance;
  4. A set of training methods to locally train (static) word vectors from text corpora, including Word2Vec (Mikolov et al., 2013), GloVe (Pennington et al., 2014), and FastText (Bojanowski et al., 2017);
  5. A group of functions to download pre-trained language models (e.g., GPT, BERT) and extract contextualized (dynamic) word vectors (based on the R package text).

⚠️ All users should update the package to version ≥ 0.3.2. Old versions may have slow processing speed and other problems.

CRAN-Version GitHub-Version R-CMD-check CRAN-Downloads GitHub-Stars

Author

Han-Wu-Shuang (Bruce) Bao 包寒吴霜

📬 [email protected]

📋 psychbruce.github.io

Citation

  • Bao, H.-W.-S. (2022). PsychWordVec: Word embedding research framework for psychological science. https://CRAN.R-project.org/package=PsychWordVec
    • Note: This is the original citation format. Please refer to the information when you library(PsychWordVec) for the APA-7 format of your installed version.
  • Bao, H.-W.-S., Wang, Z.-X., Cheng, X., Su, Z., Yang, Y., Zhang, G.-Y., Wang, B., & Cai, H. (2023). Using word embeddings to investigate human psychology: Methods and applications. Advances in Psychological Science, 31(6), 887--904.
    [包寒吴霜, 王梓西, 程曦, 苏展, 杨盈, 张光耀, 王博, 蔡华俭. (2023). 基于词嵌入技术的心理学研究:方法及应用. 心理科学进展, 31(6), 887--904.]

Installation

## Method 1: Install from CRAN
install.packages("PsychWordVec")

## Method 2: Install from GitHub
install.packages("devtools")
devtools::install_github("psychbruce/PsychWordVec", force=TRUE)

Types of Data for PsychWordVec

embedwordvec
Basic classmatrixdata.table
Row sizevocabulary sizevocabulary size
Column sizedimension size2 (variables: word, vec)
Advantagefaster (with matrix operation)easier to inspect and manage
Function to getas_embed()as_wordvec()
Function to loadload_embed()load_wordvec()

: Note: Word embedding refers to a natural language processing technique that embeds word semantics into a low-dimensional embedding matrix, with each word (actually token) quantified as a numeric vector representing its (uninterpretable) semantic features. Users are suggested to import word vectors data as the embed class using the function load_embed(), which would automatically normalize all word vectors to the unit length 1 (see the normalize() function) and accelerate the running of most functions in PsychWordVec.

Functions in PsychWordVec

  • Word Embeddings Data Management and Transformation
    • as_embed(): from wordvec (data.table) to embed (matrix)
    • as_wordvec(): from embed (matrix) to wordvec (data.table)
    • load_embed(): load word embeddings data as embed (matrix)
    • load_wordvec(): load word embeddings data as wordvec (data.table)
    • data_transform(): transform plain text word vectors to wordvec or embed
  • Word Vectors Extraction, Linear Operation, and Visualization
    • subset(): extract a subset of wordvec and embed
    • normalize(): normalize all word vectors to the unit length 1
    • get_wordvec(): extract word vectors
    • sum_wordvec(): calculate the sum vector of multiple words
    • plot_wordvec(): visualize word vectors
    • plot_wordvec_tSNE(): 2D or 3D visualization with t-SNE
    • orth_procrustes(): Orthogonal Procrustes matrix alignment
  • Word Semantic Similarity Analysis, Network Analysis, and Association Test
    • cosine_similarity(): cos_sim() or cos_dist()
    • pair_similarity(): compute a similarity matrix of word pairs
    • plot_similarity(): visualize similarities of word pairs
    • tab_similarity(): tabulate similarities of word pairs
    • most_similar(): find the Top-N most similar words
    • plot_network(): visualize a (partial correlation) network graph of words
    • test_WEAT(): WEAT and SC-WEAT with permutation test of significance
    • test_RND(): RND with permutation test of significance
  • Dictionary Automatic Expansion and Reliability Analysis
    • dict_expand(): expand a dictionary from the most similar words
    • dict_reliability(): reliability analysis and PCA of a dictionary
  • Local Training of Static Word Embeddings (Word2Vec, GloVe, and FastText)
    • tokenize(): tokenize raw text
    • train_wordvec(): train static word embeddings
  • Pre-trained Language Models (PLM) and Contextualized Word Embeddings
    • text_init(): set up a Python environment for PLM
    • text_model_download(): download PLMs from Hugging Face to local ".cache" folder
    • text_model_remove(): remove PLMs from local ".cache" folder
    • text_to_vec(): extract contextualized token and text embeddings
    • text_unmask(): \<deprecated\> <please use FMAT> fill in the blank mask(s) in a query

See the documentation (help pages) for their usage and details.

Metadata

Version

2023.9

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows