hf_ez_sentence_similarity: Compare Sentence Similarity Semantically

View source: R/ez.R

hf_ez_sentence_similarityR Documentation

Compare Sentence Similarity Semantically

Description

Calculate the semantic similarity between one text and a list of other sentences by comparing their embeddings.

Usage

hf_ez_sentence_similarity(
  model_id = "sentence-transformers/all-MiniLM-L6-v2",
  use_api = FALSE
)

Arguments

model_id

A model_id. Run hf_search_models(...) for model_ids. Defaults to 'sentence-transformers/all-MiniLM-L6-v2'.

use_api

Whether to use the Inference API to run the model (TRUE) or download and run the model locally (FALSE). Defaults to FALSE

Value

A sentence similarity object

See Also

https://huggingface.co/docs/api-inference/detailed_parameters#sentence-similarity-task

Examples

## Not run: 
# Load the default model and use local inference
ez <- hf_ez_sentence_similarity()
ez$infer(source_sentence = 'That is a happy person', sentences = list('That is a happy dog', 'That is a very happy person", "Today is a sunny day'))

# Use the api for inference.
ez <- hf_ez_sentence_similarity(use_api = TRUE)
ez$infer(source_sentence = 'That is a happy person', sentences = list('That is a happy dog', 'That is a very happy person', 'Today is a sunny day'))

## End(Not run)

farach/huggingfaceR documentation built on Feb. 4, 2023, 10:31 p.m.