ben-aaron188 | 287b30b | 2022-09-11 16:46:37 +0200 | [diff] [blame] | 1 | % Generated by roxygen2: do not edit by hand |
ben-aaron188 | 2b89c2a | 2022-09-11 16:54:25 +0200 | [diff] [blame] | 2 | % Please edit documentation in R/gpt3_embeddings.R |
| 3 | \name{gpt3_embeddings} |
| 4 | \alias{gpt3_embeddings} |
ben-aaron188 | 287b30b | 2022-09-11 16:46:37 +0200 | [diff] [blame] | 5 | \title{Retrieves text embeddings for character input from a vector from the GPT-3 API} |
| 6 | \usage{ |
ben-aaron188 | 68434e4 | 2022-12-24 20:04:21 +0100 | [diff] [blame^] | 7 | gpt3_embeddings(input_var, id_var, param_model = "text-embedding-ada-002") |
ben-aaron188 | 287b30b | 2022-09-11 16:46:37 +0200 | [diff] [blame] | 8 | } |
| 9 | \arguments{ |
| 10 | \item{input_var}{character vector that contains the texts for which you want to obtain text embeddings from the GPT-3 model |
| 11 | #' @param id_var (optional) character vector that contains the user-defined ids of the prompts. See details.} |
| 12 | |
ben-aaron188 | 68434e4 | 2022-12-24 20:04:21 +0100 | [diff] [blame^] | 13 | \item{param_model}{a character vector that indicates the \href{https://beta.openai.com/docs/guides/embeddings/embedding-models}{embedding model}; one of "text-embedding-ada-002" (default), "text-similarity-ada-001", "text-similarity-curie-001", "text-similarity-babbage-001", "text-similarity-davinci-001"} |
ben-aaron188 | 287b30b | 2022-09-11 16:46:37 +0200 | [diff] [blame] | 14 | } |
| 15 | \value{ |
| 16 | A data.table with the embeddings as separate columns; one row represents one input text. See details. |
| 17 | } |
| 18 | \description{ |
ben-aaron188 | 2b89c2a | 2022-09-11 16:54:25 +0200 | [diff] [blame] | 19 | \code{gpt3_embeddings()} extends the single embeddings function \code{gpt3_single_embedding()} to allow for the processing of a whole vector |
ben-aaron188 | 287b30b | 2022-09-11 16:46:37 +0200 | [diff] [blame] | 20 | } |
| 21 | \details{ |
ben-aaron188 | 68434e4 | 2022-12-24 20:04:21 +0100 | [diff] [blame^] | 22 | The returned data.table contains the column \code{id} which indicates the text id (or its generic alternative if not specified) and the columns \code{dim_1} ... \verb{dim_\{max\}}, where \code{max} is the length of the text embeddings vector that the different models (see below) return. For the default "Ada 2nd gen." model, these are 1536 dimensions (i.e., \code{dim_1}... \code{dim_1536}). |
ben-aaron188 | 287b30b | 2022-09-11 16:46:37 +0200 | [diff] [blame] | 23 | |
ben-aaron188 | 68434e4 | 2022-12-24 20:04:21 +0100 | [diff] [blame^] | 24 | The function supports the text similarity embeddings for the \href{https://beta.openai.com/docs/guides/embeddings/embedding-models}{five GPT-3 embeddings models} as specified in the parameter list. It is strongly advised to use the second generation model "text-embedding-ada-002". The main difference between the five models is the size of the embedding representation as indicated by the vector embedding size and the pricing. The newest model (default) is the fastest, cheapest and highest quality one. |
ben-aaron188 | 287b30b | 2022-09-11 16:46:37 +0200 | [diff] [blame] | 25 | \itemize{ |
ben-aaron188 | 68434e4 | 2022-12-24 20:04:21 +0100 | [diff] [blame^] | 26 | \item Ada 2nd generation \code{text-embedding-ada-002} (1536 dimensions) |
ben-aaron188 | 287b30b | 2022-09-11 16:46:37 +0200 | [diff] [blame] | 27 | \item Ada (1024 dimensions) |
| 28 | \item Babbage (2048 dimensions) |
| 29 | \item Curie (4096 dimensions) |
| 30 | \item Davinci (12288 dimensions) |
| 31 | } |
| 32 | |
| 33 | Note that the dimension size (= vector length), speed and \href{https://openai.com/api/pricing/}{associated costs} differ considerably. |
| 34 | |
| 35 | These vectors can be used for downstream tasks such as (vector) similarity calculations. |
| 36 | } |
| 37 | \examples{ |
| 38 | # First authenticate with your API key via `gpt3_authenticate('pathtokey')` |
| 39 | |
| 40 | # Use example data: |
ben-aaron188 | 2b89c2a | 2022-09-11 16:54:25 +0200 | [diff] [blame] | 41 | ## The data below were generated with the `gpt3_single_request()` function as follows: |
ben-aaron188 | 287b30b | 2022-09-11 16:46:37 +0200 | [diff] [blame] | 42 | ##### DO NOT RUN ##### |
ben-aaron188 | 2b89c2a | 2022-09-11 16:54:25 +0200 | [diff] [blame] | 43 | # travel_blog_data = gpt3_single_request(prompt_input = "Write a travel blog about a dog's journey through the UK:", temperature = 0.8, n = 10, max_tokens = 200)[[1]] |
ben-aaron188 | 287b30b | 2022-09-11 16:46:37 +0200 | [diff] [blame] | 44 | ##### END DO NOT RUN ##### |
| 45 | |
| 46 | # You can load these data with: |
| 47 | data("travel_blog_data") # the dataset contains 10 completions for the above request |
| 48 | |
ben-aaron188 | 287b30b | 2022-09-11 16:46:37 +0200 | [diff] [blame] | 49 | ## Obtain text embeddings for the completion texts: |
ben-aaron188 | 2b89c2a | 2022-09-11 16:54:25 +0200 | [diff] [blame] | 50 | emb_travelblogs = gpt3_embeddings(input_var = travel_blog_data$gpt3) |
| 51 | dim(emb_travelblogs) |
ben-aaron188 | 287b30b | 2022-09-11 16:46:37 +0200 | [diff] [blame] | 52 | } |