Skip to content

Commit 53e5a7f

Browse files
committed
fix annotation vignette
1 parent 9ebdaa3 commit 53e5a7f

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

vignettes/annotation.Rmd

+29-24
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,18 @@ q_thought <- tribble(
167167
output_thought <- query(q_thought, output = "text")
168168
#>
169169
#> ── Answer from llama3.2:3b-instruct-q8_0 ─────────────────────────────
170-
#> I would assign a **negative** sentiment to this text.
170+
#> I would assign a negative sentiment to this text.
171171
#>
172172
#> Here's why:
173173
#>
174-
#> * The word "terrible" is a strong adjective that implies a strongly
175-
#> unfavorable opinion. It suggests that the speaker has had a very poor
176-
#> experience with the pizza.
177-
#> * The tone of the sentence is direct and critical, implying that the
178-
#> speaker was not just mildly dissatisfied but actively disliked the
179-
#> pizza.
180-
#> * There's no nuance or mixed sentiment in this text; it's a
181-
#> straightforward expression of dislike.
174+
#> * The word "terrible" is a strong adjective that conveys a strong
175+
#> negative opinion.
176+
#> * The tone of the sentence is also quite critical and dismissive.
177+
#> * There are no positive or neutral phrases in the text, which
178+
#> suggests that the author has a clear dislike for the pizza.
182179
#>
183-
#> Overall, the language and tone used suggest that the speaker had a
184-
#> very negative experience with the pizza.
180+
#> Overall, the language and tone used in this text indicate a strong
181+
#> negative sentiment towards the pizza.
185182
```
186183

187184
In the next step we can use the assistant's reasoning and a user prompt with the classification question.
@@ -267,15 +264,19 @@ q_os <- make_query(
267264
template = "{text}\n{prompt}",
268265
prompt = "Categories: positive, neutral, negative",
269266
system = "You assign texts into categories. Answer with just the correct category.",
267+
example = examples_os,
270268
)
271269
print(q_os)
272270
#> [[1]]
273-
#> # A tibble: 2 × 2
274-
#> role content
275-
#> <chr> <glue>
276-
#> 1 system You assign texts into categories. Answer with just the corre…
277-
#> 2 user the service is great
278-
#> Categories: positive, neutral, negative
271+
#> # A tibble: 4 × 2
272+
#> role content
273+
#> <chr> <glue>
274+
#> 1 system You assign texts into categories. Answer with just the co…
275+
#> 2 user the pizza tastes terrible
276+
#> Categories: positive, neutral, n…
277+
#> 3 assistant negative
278+
#> 4 user the service is great
279+
#> Categories: positive, neutral, negati…
279280

280281
query(q_os)
281282
#>
@@ -388,23 +389,27 @@ We can also use this approach in a 'tidy' coding style:
388389

389390

390391
``` r
391-
library(dplyr)
392+
library(dplyr, warn.conflicts = FALSE)
392393
movie_reviews_annotated <- movie_reviews |>
393394
mutate(
394-
sentiment = queries = make_query(
395+
sentiment = make_query(
395396
text = review,
396397
prompt = "Categories: positive, neutral, negative",
397398
template = "{prefix}{text}\n{prompt}",
398399
system = "Classify the sentiment of the movie review. Answer with just the correct category.",
399400
prefix = "Text to classify: "
400-
) |>
401+
) |>
401402
query(screen = FALSE, output = "text")
402403
)
403404
movie_reviews_annotated
404-
#> Error in parse(text = input): <text>:4:25: unexpected '='
405-
#> 3: mutate(
406-
#> 4: sentiment = queries =
407-
#> ^
405+
#> # A tibble: 5 × 4
406+
#> review_id review annotation sentiment
407+
#> <int> <chr> <chr> <chr>
408+
#> 1 1 A stunning visual spectacle with a g… Positive Positive
409+
#> 2 2 The plot was predictable, but the ac… positive positive
410+
#> 3 3 An overrated film with underwhelming… Negative Negative
411+
#> 4 4 A beautiful tale of love and adventu… Positive Positive
412+
#> 5 5 The movie lacked depth, but the spec… Neutral Neutral
408413
```
409414

410415
This takes a little longer than classic supervised machine learning or even classification with transformer models.

vignettes/annotation.Rmd.orig

+3-3
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,16 @@ movie_reviews
307307
We can also use this approach in a 'tidy' coding style:
308308

309309
```{r}
310-
library(dplyr)
310+
library(dplyr, warn.conflicts = FALSE)
311311
movie_reviews_annotated <- movie_reviews |>
312312
mutate(
313-
sentiment = queries = make_query(
313+
sentiment = make_query(
314314
text = review,
315315
prompt = "Categories: positive, neutral, negative",
316316
template = "{prefix}{text}\n{prompt}",
317317
system = "Classify the sentiment of the movie review. Answer with just the correct category.",
318318
prefix = "Text to classify: "
319-
) |>
319+
) |>
320320
query(screen = FALSE, output = "text")
321321
)
322322
movie_reviews_annotated

0 commit comments

Comments
 (0)