File size: 5,411 Bytes
010bd36
 
 
 
 
 
 
 
 
c28d81d
010bd36
 
1358c21
010bd36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10bdf14
494bd12
010bd36
 
 
 
 
 
 
 
 
494bd12
 
 
 
 
010bd36
 
 
 
d405df4
10bdf14
 
 
494bd12
 
 
 
 
10bdf14
494bd12
 
 
 
10bdf14
 
 
 
 
 
 
 
 
 
494bd12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import pandas as pd
from datasets import load_dataset
import streamlit as st

from clarin_datasets.dataset_to_show import DatasetToShow


class AspectEmoDataset(DatasetToShow):
    def __init__(self):
        DatasetToShow.__init__(self)
        self.dataset_name = "clarin-pl/aspectemo"
        self.description = """
        AspectEmo Corpus is an extended version of a publicly available PolEmo 2.0 
        corpus of Polish customer reviews used in many projects on the use of different methods in sentiment 
        analysis. The AspectEmo corpus consists of four subcorpora, each containing online customer reviews from the 
        following domains: school, medicine, hotels, and products. All documents are annotated at the aspect level 
        with six sentiment categories: strong negative (minus_m), weak negative (minus_s), neutral (zero), 
        weak positive (plus_s), strong positive (plus_m).
        
        Tasks (input, output and metrics)
        
        Aspect-based sentiment analysis (ABSA) is a text analysis method that 
        categorizes data by aspects and identifies the sentiment assigned to each aspect. It is the sequence tagging 
        task.
        
        Input ('tokens' column): sequence of tokens
        
        Output ('labels' column): sequence of predicted tokens’ classes ("O" + 6 possible classes: strong negative (
        a_minus_m), weak negative (a_minus_s), neutral (a_zero), weak positive (a_plus_s), strong positive (
        a_plus_m), ambiguous (a_amb) )
        
        Domain: school, medicine, hotels and products
        
        Measurements:
        
        Example: ['Dużo', 'wymaga', ',', 'ale', 'bardzo', 'uczciwy', 'i', 'przyjazny', 'studentom', '.', 'Warto', 'chodzić', 
        'na', 'konsultacje', '.', 'Docenia', 'postępy', 'i', 'zaangażowanie', '.', 'Polecam', '.'] → ['O', 'a_plus_s', 'O', 
        'O', 'O', 'a_plus_m', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'a_zero', 'O', 'a_plus_m', 'O', 'O', 'O', 'O', 'O', 'O'] 
        """

    def load_data(self):
        raw_dataset = load_dataset(self.dataset_name)
        self.data_dict = {
            subset: raw_dataset[subset].to_pandas() for subset in self.subsets
        }

    def show_dataset(self):
        header = st.container()
        description = st.container()
        dataframe_head = st.container()
        class_distribution = st.container()
        most_common_tokens = st.container()

        with header:
            st.title(self.dataset_name)

        with description:
            st.header("Dataset description")
            st.write(self.description)

        full_dataframe = pd.concat(self.data_dict.values(), axis="rows")
        tokens_all = full_dataframe["tokens"].tolist()
        tokens_all = [x for subarray in tokens_all for x in subarray]
        labels_all = full_dataframe["labels"].tolist()
        labels_all = [x for subarray in labels_all for x in subarray]

        with dataframe_head:
            df_to_show = full_dataframe.head(10)
            st.header("First 10 observations of the dataset")
            st.dataframe(df_to_show)
            st.text_area(label="LaTeX code", value=df_to_show.style.to_latex())

        class_distribution_dict = {}
        for subset in self.subsets:
            all_labels_from_subset = self.data_dict[subset]["labels"].tolist()
            all_labels_from_subset = [
                x for subarray in all_labels_from_subset for x in subarray if x != 0
            ]
            all_labels_from_subset = pd.Series(all_labels_from_subset)
            class_distribution_dict[subset] = (
                all_labels_from_subset.value_counts(normalize=True)
                    .sort_index()
                    .reset_index()
                    .rename({"index": "class", 0: subset}, axis="columns")
            )

        class_distribution_df = pd.merge(
            class_distribution_dict["train"],
            class_distribution_dict["test"],
            on="class",
        )
        with class_distribution:
            st.header("Class distribution in each subset (without '0')")
            st.dataframe(class_distribution_df)
            st.text_area(
                label="LaTeX code", value=class_distribution_df.style.to_latex()
            )

        # Most common tokens from selected class (without 0)
        full_df_unzipped = pd.DataFrame(
            {
                "token": tokens_all,
                "label": labels_all,
            }
        )
        full_df_unzipped = full_df_unzipped.loc[full_df_unzipped["label"] != 0]
        possible_options = sorted(full_df_unzipped["label"].unique())
        with most_common_tokens:
            st.header("10 most common tokens from selected class (without '0')")
            selected_class = st.selectbox(
                label="Select class to show", options=possible_options
            )
            df_to_show = (
                full_df_unzipped.loc[full_df_unzipped["label"] == selected_class]
                .groupby(["token"])
                .count()
                .reset_index()
                .rename({"label": "no_of_occurrences"}, axis=1)
                .sort_values(by="no_of_occurrences", ascending=False)
                .reset_index(drop=True)
                .head(10)
            )
            st.dataframe(df_to_show)
            st.text_area(label="LaTeX code", value=df_to_show.style.to_latex())