Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

text_hashing_trick

Converts a text to a sequence of indexes in a fixed-size hashing space.


Description

Converts a text to a sequence of indexes in a fixed-size hashing space.

Usage

text_hashing_trick(
  text,
  n,
  hash_function = NULL,
  filters = "!\"#$%&()*+,-./:;<=>?@[\\]^_`{|}~\t\n",
  lower = TRUE,
  split = " "
)

Arguments

text

Input text (string).

n

Dimension of the hashing space.

hash_function

if NULL uses python hash function, can be 'md5' or any function that takes in input a string and returns a int. Note that hash is not a stable hashing function, so it is not consistent across different runs, while 'md5' is a stable hashing function.

filters

Sequence of characters to filter out such as punctuation. Default includes basic punctuation, tabs, and newlines.

lower

Whether to convert the input to lowercase.

split

Sentence split marker (string).

Details

Two or more words may be assigned to the same index, due to possible collisions by the hashing function.

Value

A list of integer word indices (unicity non-guaranteed).

See Also


keras

R Interface to 'Keras'

v2.4.0
MIT + file LICENSE
Authors
Daniel Falbel [ctb, cph, cre], JJ Allaire [aut, cph], François Chollet [aut, cph], RStudio [ctb, cph, fnd], Google [ctb, cph, fnd], Yuan Tang [ctb, cph] (<https://orcid.org/0000-0001-5243-233X>), Wouter Van Der Bijl [ctb, cph], Martin Studer [ctb, cph], Sigrid Keydana [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.