Two-paragraph reflection

Reflection draft: revise after running the code and completing the manual review.

My earlier RPubs report helped me understand how tokenization and stop-word removal turn short reviews into a word-frequency table. Extending that work with AI provides a way to explore sentiment and interactive charts, but I need to verify the code and its interpretations. In this report, I will check row counts, compare the word counts with the original sentences, and inspect which words the sentiment dictionary actually matches. A frequent word identifies a repeated topic; it does not establish whether people like that topic or why they mention it.

Human judgment contributes the context that a word dictionary cannot reliably capture. A review can praise product quality while criticizing shipping, so a single positive label can hide an important complaint. I will compare the automated results with my own reading of all five reviews and explain any disagreement. These sentences are classroom examples rather than a representative customer sample, so their percentages cannot establish broader customer attitudes. AI can help produce code and charts, but I remain responsible for interpreting the evidence, documenting limitations, and supporting any recommendation.

1. Purpose and data source

This report extends my published Text analysis–Week 13 report. The input consists of the same five example product-review sentences shown there. They are classroom examples rather than newly collected customer data.

The questions are: Which words recur, what sentiment words are detected, and where might a dictionary score fail to reflect the complete meaning of a review?

reviews_raw <- tibble(
  review_id = seq_len(5),
  text = c(
    "I love the quality of this product. The price is reasonable, and delivery was fast.",
    "The product quality is excellent, but the shipping took too long.",
    "Great customer service! I would definitely recommend this product to my friends.",
    "The price is too expensive. However, the product looks beautiful.",
    "Fast delivery and excellent service. I am very satisfied with my purchase."
  )
)
kable(reviews_raw, caption = "The original five classroom examples")
The original five classroom examples
review_id text
1 I love the quality of this product. The price is reasonable, and delivery was fast.
2 The product quality is excellent, but the shipping took too long.
3 Great customer service! I would definitely recommend this product to my friends.
4 The price is too expensive. However, the product looks beautiful.
5 Fast delivery and excellent service. I am very satisfied with my purchase.

2. Clean the data and document changes

Keep the original text. Remove blank records, trim repeated whitespace, and check for exact duplicate review text. In a real collection, identical text from different people may be meaningful; the appropriate duplicate rule depends on the source. For this small classroom exercise, exact repeated text would be retained once.

reviews_nonblank <- reviews_raw %>%
  mutate(text_clean = str_squish(text)) %>%
  filter(!is.na(text_clean), text_clean != "")
reviews <- reviews_nonblank %>% distinct(text_clean, .keep_all = TRUE)
cleaning_audit <- tibble(
  check = c("Original rows", "Blank rows removed", "Exact duplicates removed", "Final rows"),
  value = c(nrow(reviews_raw), nrow(reviews_raw) - nrow(reviews_nonblank),
            nrow(reviews_nonblank) - nrow(reviews), nrow(reviews))
)
kable(cleaning_audit)
check value
Original rows 5
Blank rows removed 0
Exact duplicates removed 0
Final rows 5
stopifnot(nrow(reviews) == 5L, !anyDuplicated(reviews$review_id),
          all(nchar(reviews$text_clean) > 0))

3. Text analysis

Tokenize to one word per row. Use stop-word removal for the frequency analysis. Keep a separate token table for sentiment so that this frequency filter does not silently decide which words are available for sentiment matching.

tokens_all <- reviews %>%
  select(review_id, text_clean) %>%
  unnest_tokens(word, text_clean)
tokens_content <- tokens_all %>%
  anti_join(tidytext::stop_words, by = "word") %>%
  filter(str_detect(word, "[a-z]"))
word_counts <- tokens_content %>% count(word, sort = TRUE)
kable(tibble(measure = c("All word tokens", "Tokens after frequency filters", "Distinct retained words"),
             value = c(nrow(tokens_all), nrow(tokens_content), nrow(word_counts))))
measure value
All word tokens 60
Tokens after frequency filters 26
Distinct retained words 17
kable(word_counts, caption = "Word occurrences, not number of customers")
Word occurrences, not number of customers
word n
product 4
delivery 2
excellent 2
fast 2
price 2
quality 2
service 2
beautiful 1
customer 1
expensive 1
friends 1
love 1
purchase 1
reasonable 1
recommend 1
satisfied 1
shipping 1
word_chart_data <- word_counts %>%
  slice_max(n, n = 15, with_ties = FALSE) %>%
  arrange(n, word) %>%
  mutate(word = factor(word, levels = word))
plot_ly(word_chart_data, x = ~n, y = ~word, type = "bar", orientation = "h",
        marker = list(color = "#2563A6"),
        hovertemplate = "%{y}<br>Occurrences: %{x}<extra></extra>") %>%
  layout(title = "Most frequent retained words in five example reviews",
         xaxis = list(title = "Word occurrences", dtick = 1),
         yaxis = list(title = ""), margin = list(l = 110))

Hover over the bars to inspect counts. The chart summarizes this small set only.

4. Sentiment analysis using the Bing dictionary

The Bing dictionary assigns words positive or negative labels. For each review, score = positive word occurrences minus negative word occurrences. A positive score is labeled Positive and a negative score Negative. A zero score with matches is called Balanced; a review with no matches is called No matches. Neither label proves that a human would regard a review as neutral. This method does not model negation, sarcasm, or the target of an opinion.

bing <- tidytext::get_sentiments("bing")
sentiment_matches <- tokens_all %>% inner_join(bing, by = "word")
match_counts <- sentiment_matches %>%
  group_by(review_id) %>%
  summarise(positive_words = sum(sentiment == "positive"),
            negative_words = sum(sentiment == "negative"), .groups = "drop")
scored <- reviews %>%
  left_join(match_counts, by = "review_id") %>%
  mutate(across(c(positive_words, negative_words), ~replace_na(.x, 0L)),
         matched_words = positive_words + negative_words,
         score = positive_words - negative_words,
         automated_label = case_when(
           matched_words == 0 ~ "No matches",
           score > 0 ~ "Positive",
           score < 0 ~ "Negative",
           TRUE ~ "Balanced"
         ))
sentiment_summary <- scored %>% count(automated_label, name = "reviews") %>%
  mutate(percent = 100 * reviews / sum(reviews))
kable(scored %>% select(review_id, positive_words, negative_words, score, automated_label))
review_id positive_words negative_words score automated_label
1 3 0 3 Positive
2 1 0 1 Positive
3 2 0 2 Positive
4 1 1 0 Balanced
5 3 0 3 Positive
kable(sentiment_summary, digits = 1, caption = "Shares of the five examples under the stated scoring rule")
Shares of the five examples under the stated scoring rule
automated_label reviews percent
Balanced 1 20
Positive 4 80
kable(sentiment_matches %>% count(review_id, word, sentiment),
      caption = "Inspect the actual word matches before interpreting the scores")
Inspect the actual word matches before interpreting the scores
review_id word sentiment n
1 fast positive 1
1 love positive 1
1 reasonable positive 1
2 excellent positive 1
3 great positive 1
3 recommend positive 1
4 beautiful positive 1
4 expensive negative 1
5 excellent positive 1
5 fast positive 1
5 satisfied positive 1
plot_ly(sentiment_summary, x = ~automated_label, y = ~reviews, type = "bar",
        text = ~paste0(round(percent, 1), "%"), textposition = "auto",
        marker = list(color = "#24887C"),
        hovertemplate = "%{x}<br>Reviews: %{y}<br>Share: %{text}<extra></extra>") %>%
  layout(title = "Dictionary labels for five example reviews",
         xaxis = list(title = "Automated label"),
         yaxis = list(title = "Review count", dtick = 1))

5. Verify the results

Automatic sanity checks

These checks compare independently defined quantities. They do not prove that sentiment labels match human interpretation.

checks <- tibble(
  check = c("Cleaning accounting balances", "Five reviews retained",
            "One sentiment result per review", "Sentiment counts add to five",
            "Percentages add to 100", "Dictionary matches accounted for"),
  passed = c(
    nrow(reviews_raw) == cleaning_audit$value[2] + cleaning_audit$value[3] + nrow(reviews),
    nrow(reviews) == 5,
    nrow(scored) == nrow(reviews) && !anyDuplicated(scored$review_id),
    sum(sentiment_summary$reviews) == nrow(reviews),
    abs(sum(sentiment_summary$percent) - 100) < 1e-8,
    sum(scored$matched_words) == nrow(sentiment_matches)
  )
)
kable(checks)
check passed
Cleaning accounting balances TRUE
Five reviews retained TRUE
One sentiment result per review TRUE
Sentiment counts add to five TRUE
Percentages add to 100 TRUE
Dictionary matches accounted for TRUE
stopifnot(all(checks$passed))

Hand calculation: the word product

Reading the original sentences shows that the word product appears once in each of reviews 1, 2, 3, and 4, and does not appear in review 5. The hand count is therefore 4. Compare that with the code result below.

product_count <- sum(tokens_all$word == "product")
kable(tibble(word = "product", hand_count = 4L, code_count = product_count,
             agrees = product_count == 4L))
word hand_count code_count agrees
product 4 4 TRUE
stopifnot(product_count == 4L)

Manual sentiment review: complete before submitting

Read each original sentence yourself. Replace the five empty labels below with Positive, Negative, Mixed, or Neutral; enter a short reason for each. These labels are intentionally blank so this report does not claim a manual review you have not performed. Mixed is useful when a review contains both praise and criticism.

manual_review <- tibble(
  review_id = 1:5,
  human_label = c("", "", "", "", ""),
  human_reason = c("", "", "", "", "")
)
valid_labels <- c("", "Positive", "Negative", "Mixed", "Neutral")
stopifnot(all(manual_review$human_label %in% valid_labels))
review_comparison <- scored %>%
  select(review_id, text, automated_label, score) %>%
  left_join(manual_review, by = "review_id") %>%
  mutate(review_status = if_else(human_label == "", "Needs human review", "Human label entered"))
kable(review_comparison)
review_id text automated_label score human_label human_reason review_status
1 I love the quality of this product. The price is reasonable, and delivery was fast. Positive 3 Needs human review
2 The product quality is excellent, but the shipping took too long. Positive 1 Needs human review
3 Great customer service! I would definitely recommend this product to my friends. Positive 2 Needs human review
4 The price is too expensive. However, the product looks beautiful. Balanced 0 Needs human review
5 Fast delivery and excellent service. I am very satisfied with my purchase. Positive 3 Needs human review
cat("Completed human labels:", sum(manual_review$human_label != ""), "of", nrow(manual_review))
## Completed human labels: 0 of 5

Complete: Identify at least one disagreement or limitation from this table and explain what the dictionary missed. Human Mixed and Neutral labels need not map directly to the automated Balanced or No matches categories.

6. Findings and critique: finish after running

  • Repeated topics: Discuss the frequent words in the frequency table and read their original sentences before proposing themes.
  • Sentiment result: Report the counts shown by the code and name the scoring rule. Avoid describing a dictionary label as a verified customer attitude.
  • Context: Examine reviews 2 and 4 for both praise and criticism. Explain whether their automated scores preserve that balance.
  • Limitations: Five constructed classroom examples cannot represent a market. Word counts do not explain causes, and dictionary matching does not understand phrases or opinion targets.
  • Practical implication: Suggest an action supported by the specific sentences, such as investigating an issue mentioned in a review; do not generalize its prevalence to customers as a whole.

My final interpretation: [Replace this sentence with 3–5 sentences describing your computed results, your manual check, and one cautious recommendation.]

7. AI prompts and response evidence

The following are suggested prompts to send, not a record of completed exchanges. Use at least two AI turns and screenshot the actual prompts and responses in your chat. Include your code or results in the improved prompt.

Prompt 1 — specific initial request

Extend my existing RPubs exercise at https://rpubs.com/michelenorrego/1477019. Use only its five example product-review sentences. Write an HTML R Markdown report using dplyr, tidytext, ggplot2, and plotly. Include a cleaning audit, word frequencies, Bing sentiment scores by review, an interactive bar chart, and verification checks. Keep the original text. Do not invent customer data, execution results, or completed human verification. Explain the limits of the five-sentence dataset.

Prompt 2 — improved follow-up after inspecting the first response

Review and improve your previous R Markdown code. Keep stop-word removal separate from sentiment tokenization; retain reviews without dictionary matches. Distinguish positive, negative, balanced, and no-match scores. Show the exact matched words for each review and add a hand-check of the word product, which appears four times. Provide a blank table for my human labels and explain how mixed reviews and negation can mislead the method. Check the code I paste below and explain any corrections without claiming you ran it. [Paste the first response and any actual Console errors or output here.]

Evidence checklist: Save screenshots of each original prompt, the response, your improved prompt, and its response. Use the exchanges you actually complete. Post the screenshots to the discussion forum; do not submit example prompts as though they were already used.

References

sessionInfo()
## R version 4.6.2 (2026-10-29)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.5 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
##  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
##  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
## [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
## 
## time zone: UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] knitr_1.52     plotly_4.12.1  ggplot2_4.0.4  tidytext_0.4.3 tibble_3.3.1  
## [6] stringr_1.6.0  tidyr_1.3.2    dplyr_1.2.1   
## 
## loaded via a namespace (and not attached):
##  [1] Matrix_1.7-6        gtable_0.3.6        jsonlite_2.0.0     
##  [4] janeaustenr_1.0.0   compiler_4.6.2      tidyselect_1.2.1   
##  [7] Rcpp_1.1.2          jquerylib_0.1.4     scales_1.4.0       
## [10] yaml_2.3.12         fastmap_1.2.0       lattice_0.23-1     
## [13] R6_2.6.1            SnowballC_0.7.1     generics_0.1.4     
## [16] htmlwidgets_1.6.4   RColorBrewer_1.1-3  bslib_0.12.0       
## [19] pillar_1.11.1       tokenizers_0.3.0    rlang_1.3.0        
## [22] cachem_1.1.0        stringi_1.8.9       xfun_0.62          
## [25] S7_0.2.2            sass_0.4.10         otel_0.3.0         
## [28] viridisLite_0.4.3   cli_3.6.6           withr_3.0.3        
## [31] magrittr_2.0.5      crosstalk_1.2.2     digest_0.6.39      
## [34] grid_4.6.2          lifecycle_1.0.5     vctrs_0.7.3        
## [37] data.table_1.18.6.1 evaluate_1.0.5      glue_1.8.1         
## [40] farver_2.1.2        httr_1.4.9          rmarkdown_2.32     
## [43] purrr_1.2.2         tools_4.6.2         pkgconfig_2.0.3    
## [46] htmltools_0.5.9