library(tidyverse)
library(summarytools)
library(stringr)
library(psych)
library(dplyr)
library(tidytext)
library(textdata)
library(ggplot2)
prosocial_dane <- read.csv("validation.csv")
head(prosocial_dane, n=10)
Źródło: https://huggingface.co/datasets/allenai/prosocial-dialog
Kim, H., Yu, Y., Jiang, L., Lu, X., Khashabi, D., Kim, G., Choi, Y., & Sap, M. (2022). ProsocialDialog: A Prosocial Backbone for Conversational Agents. In Proceedings of the Conference on Empirical Methods in Natural Language Processing (EMNLP).
| attribute | type | description |
|---|---|---|
context |
str | the potentially unsafe utterance |
response |
str | the guiding utterance grounded on rules-of-thumb
(rots) |
rots |
list of str|null | the relevant rules-of-thumb for text not
labeled as __casual__ |
safety_label |
str | the final verdict of the context according to
safety_annotations: {__casual__,
__possibly_needs_caution__, __probably_needs_caution__,
__needs_caution__, __needs_intervention__} |
safety_annotations |
list of str | raw annotations from three workers: {casual, needs caution, needs intervention} |
safety_annotation_reasons |
list of str | the reasons behind the safety annotations in free-form text from each worker |
source |
str | the source of the seed text that was used to craft the first utterance of the dialogue: {socialchemistry, sbic, ethics_amt, ethics_reddit} |
etc |
str|null | other information |
dialogue_id |
int | the dialogue index |
response_id |
int | the response index |
episode_done |
bool | an indicator of whether it is the end of the dialogue |
View(prosocial_dane)
summary(prosocial_dane)
context response rots safety_label safety_annotations safety_annotation_reasons source
Length:20416 Length:20416 Length:20416 Length:20416 Length:20416 Length:20416 Length:20416
Class :character Class :character Class :character Class :character Class :character Class :character Class :character
Mode :character Mode :character Mode :character Mode :character Mode :character Mode :character Mode :character
etc dialogue_id response_id episode_done
Length:20416 Min. : 0 Min. :0.000 Length:20416
Class :character 1st Qu.:1791 1st Qu.:0.000 Class :character
Mode :character Median :3571 Median :1.000 Mode :character
Mean :3569 Mean :0.952
3rd Qu.:5353 3rd Qu.:2.000
Max. :7131 Max. :2.000
ggplot(prosocial_dane) +
aes(x = safety_label, fill = safety_label) +
geom_bar() +
scale_fill_manual(
values = c(`__casual__` = "#006837",
`__needs_caution__` = "#F88D51",
`__needs_intervention__` = "#A50026",
`__possibly_needs_caution__` = "#86CB66",
`__probably_needs_caution__` = "#FFFFBF")
) +
labs(
x = "Safety label",
y = "Liczba wystąpień",
title = "Rozkład wystąpień zmiennej \"safety_label\" w zbiorze",
fill = "Rodzaje etykiet"
) +
theme_minimal()
library(sentimentr)
prosocial_dane$context <- as.character(prosocial_dane$context)
prosocial_dane$sentiment_score <- sapply(prosocial_dane$context, function(x)
mean(sentiment(x)$sentiment))
Zapisywanie pliku na wszelki wypadek - kod renderował mi się pół godziny
write.csv(prosocial_dane, file = "prosocial_dane_sentiment.csv", row.names = FALSE)
prosocial_dane_sentiment <- prosocial_dane
Wszystkie wyniki usunęły mi się, dlatego dodam plik jeszcze raz
prosocial_dane_sentiment <- read.csv("prosocial_dane_sentiment.csv")
prosocial_dane_sentiment$sentiment_score <- format(prosocial_dane_sentiment$sentiment_score, scientific = FALSE)
prosocial_dane_sentiment
prosocial_dane_sentiment$sentiment_cat <- ifelse(prosocial_dane_sentiment$sentiment_score > 0, "positive",
ifelse(prosocial_dane_sentiment$sentiment_score < 0, "negative", "neutral"))
class(prosocial_dane_sentiment$sentiment_score)
[1] "numeric"
prosocial_dane_sentiment$sentiment_score <- as.numeric(prosocial_dane_sentiment$sentiment_score)
ggplot(prosocial_dane_sentiment) +
aes(x = sentiment_cat, fill = sentiment_cat) +
geom_bar() +
labs(
x = "Rodzaj walencji",
y = "Liczba wystąpień",
title = "Rozkład rodzaju walencji w zbiorze"
) +
scale_fill_brewer(palette = "RdYlGn", direction = 1) +
theme_minimal()
ggplot(prosocial_dane_sentiment) +
aes(x = safety_label, fill = sentiment_cat) +
geom_bar(position = "dodge") +
scale_fill_brewer(palette = "RdYlGn", direction = 1) +
labs(
x = "Safety label",
y = "Liczba wystąpień",
title = "Rozkład rodzaju walencji u poszczególnych grup zmiennej \"safety label\""
) +
theme_minimal()
ggplot(prosocial_dane_sentiment) +
aes(x = "", y = sentiment_score, fill = safety_label) +
geom_boxplot() +
scale_fill_manual(
values = c(`__casual__` = "#006837",
`__needs_caution__` = "#F88D51",
`__needs_intervention__` = "#A50026",
`__possibly_needs_caution__` = "#86CB66",
`__probably_needs_caution__` = "#FFFFBF")
) +
labs(
x = "Safety label",
y = "Sentiment score",
title = "Rozkład zmiennej \"sentiment score\" według grup zmiennej \"safety_label\"",
fill = "Rodzaje etykiet \"safety label\""
)+
theme_minimal()
Hipoteza zerowa (H0): Średnie wartości “sentiment_score” są równe dla wszystkich kategorii “safety_label”.
class(prosocial_dane_sentiment$sentiment_score)
[1] "numeric"
prosocial_dane_sentiment$sentiment_score <- as.numeric(prosocial_dane_sentiment$sentiment_score)
library(nortest)
kolsmir_wynik <- lillie.test(prosocial_dane_sentiment$sentiment_score)
kolsmir_wynik <- format(kolsmir_wynik, scientific = FALSE)
kolsmir_wynik
statistic p.value method
"0.07920027" "0" "Lilliefors (Kolmogorov-Smirnov) normality test"
data.name
"prosocial_dane_sentiment$sentiment_score"
Zatem odrzucamy hipotezę zerową o normalności rozkładu zmiennej sentiment_score. Ta zmienna nie ma rozkładu normalnego.
Hipoteza zerowa (H0): Rozkłady “sentiment_score” są jednakowe we wszystkich kategoriach “safety_labels” (mediany są równe).
class(prosocial_dane_sentiment$safety_label)
class(prosocial_dane_sentiment$sentiment_score)
prosocial_dane_sentiment$safety_label <- as.factor(prosocial_dane_sentiment$safety_label)
kruskal_wynik <- kruskal.test(prosocial_dane_sentiment$sentiment_score, prosocial_dane_sentiment$safety_label, sentiment_score ~ safety_label)
kruskal_wynik <- format(kruskal_wynik, scientific = FALSE)
kruskal_wynik
statistic
"163.939"
parameter
"4"
p.value
"0.0000000000000000000000000000000002089368"
method
"Kruskal-Wallis rank sum test"
data.name
"prosocial_dane_sentiment$sentiment_score and prosocial_dane_sentiment$safety_label"
Odrzucamy hipotezę zerową, zatem istnieją statystycznie istotne różnice między przynajmniej dwiema z grup w analizowanej zmiennej “sentiment_score”.
library(DescTools)
Ostrzeżenie: pakiet ‘DescTools’ został zbudowany w wersji R 4.3.2Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 method overwritten by 'DescTools':
method from
print.palette wesanderson
Dołączanie pakietu: ‘DescTools’
Następujące obiekty zostały zakryte z ‘package:psych’:
AUC, ICC, SD
posthoc_result <- DunnTest(prosocial_dane_sentiment$sentiment_score, prosocial_dane_sentiment$safety_label, method = "bonferroni")
posthoc_result
Dunn's test of multiple comparisons using rank sums : bonferroni
mean.rank.diff pval
__needs_caution__-__casual__ -1476.1636523 < 2e-16 ***
__needs_intervention__-__casual__ -1475.4392345 < 2e-16 ***
__possibly_needs_caution__-__casual__ -944.2994059 1.3e-08 ***
__probably_needs_caution__-__casual__ -1311.3863971 < 2e-16 ***
__needs_intervention__-__needs_caution__ 0.7244178 1.00000
__possibly_needs_caution__-__needs_caution__ 531.8642463 0.00054 ***
__probably_needs_caution__-__needs_caution__ 164.7772552 1.00000
__possibly_needs_caution__-__needs_intervention__ 531.1398286 0.00944 **
__probably_needs_caution__-__needs_intervention__ 164.0528374 1.00000
__probably_needs_caution__-__possibly_needs_caution__ -367.0869911 0.20324
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Grupy “needs caution”, “needs intervention”, “possibly needs caution” i “probably needs caution” istotnie różnią się poziomem zmiennej “sentiment score” od grupy “casual”.
Dodatkowo statystycznie istotne różnice występują między grupą “possibly needs caution” oraz grupami “needs caution” i “needs intervention”.