View source: R/sentence_similarity.R
sentence_similarity | R Documentation |
Uses sentiment analysis pipelines from huggingface to compute probabilities that the text corresponds to the specified classes
sentence_similarity(
text,
comparison_text,
transformer = c("all_minilm_l6"),
device = c("auto", "cpu", "cuda"),
preprocess = FALSE,
keep_in_env = TRUE,
envir = 1
)
text |
Character vector or list. Text in a vector or list data format |
comparison_text |
Character vector or list. Text in a vector or list data format |
transformer |
Character.
Specific sentence similarity transformer
to be used.
Defaults to Also allows any sentence similarity models with a pipeline
from huggingface
to be used by using the specified name (e.g., |
device |
Character.
Whether to use CPU or GPU for inference.
Defaults to |
preprocess |
Boolean.
Should basic preprocessing be applied?
Includes making lowercase, keeping only alphanumeric characters,
removing escape characters, removing repeated characters,
and removing white space.
Defaults to |
keep_in_env |
Boolean.
Whether the classifier should be kept in your global environment.
Defaults to |
envir |
Numeric. Environment for the classifier to be saved for repeated use. Defaults to the global environment |
Returns a n x m similarity matrix where n is length of text
and m is the length of comparison_text
Alexander P. Christensen <alexpaulchristensen@gmail.com>
# Load data
data(neo_ipip_extraversion)
# Example text
text <- neo_ipip_extraversion$friendliness[1:5]
## Not run:
# Example with defaults
sentence_similarity(
text = text, comparison_text = text
)
# Example with model from 'sentence-transformers'
sentence_similarity(
text = text, comparison_text = text,
transformer = "sentence-transformers/all-mpnet-base-v2"
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.