| hf_classify | R Documentation |
Classify text using a Hugging Face model. Commonly used for sentiment analysis, topic classification, etc. Vector inputs are sent in a single batched Inference API request when possible, which is substantially faster than one API request per text.
hf_classify(
text,
model = hf_default_model("classify"),
token = NULL,
endpoint_url = NULL,
...
)
text |
Character vector of text(s) to classify. |
model |
Character string. Model ID from Hugging Face Hub. Default: "distilbert/distilbert-base-uncased-finetuned-sst-2-english" (sentiment analysis). |
token |
Character string or NULL. API token for authentication. |
endpoint_url |
Character string or NULL. A custom Inference Endpoint URL. When provided, requests are sent to this URL instead of the public Inference API. Use for models deployed on dedicated Inference Endpoints. |
... |
Additional arguments (currently unused). |
A tibble with columns: text, label, score
## Not run:
# Sentiment analysis
hf_classify("I love R programming!")
# Multiple texts
hf_classify(c("This is great!", "This is terrible."))
# Use in a pipeline
library(dplyr)
reviews |>
mutate(sentiment = hf_classify(review_text)) |>
unnest(sentiment)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.