Datasets:
norabelrose
commited on
Commit
·
cf7e0da
1
Parent(s):
4e788ea
Update README.md
Browse files
README.md
CHANGED
@@ -36,4 +36,79 @@ dataset_info:
|
|
36 |
---
|
37 |
# Dataset Card for "CEBaB"
|
38 |
|
39 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
---
|
37 |
# Dataset Card for "CEBaB"
|
38 |
|
39 |
+
This is a lightly cleaned and simplified version of the CEBaB counterfactual restaurant review dataset from [this paper](https://arxiv.org/abs/2205.14140).
|
40 |
+
The most important difference from the original dataset is that the `rating` column corresponds to the _median_ rating provided by the Mechanical Turkers,
|
41 |
+
rather than the majority rating. These are the same whenever a majority rating exists, but when there is no majority rating (e.g. because there were two 1s,
|
42 |
+
two 2s, and one 3), the original dataset used a `"no majority"` placeholder whereas we are able to provide an aggregate rating for all reviews.
|
43 |
+
|
44 |
+
The exact code used to process the original dataset is provided below:
|
45 |
+
```py
|
46 |
+
from ast import literal_eval
|
47 |
+
from datasets import DatasetDict, Value, load_dataset
|
48 |
+
|
49 |
+
|
50 |
+
def compute_median(x: str):
|
51 |
+
"""Compute the median rating given a multiset of ratings."""
|
52 |
+
# Decode the dictionary from string format
|
53 |
+
dist = literal_eval(x)
|
54 |
+
|
55 |
+
# Should be a dictionary whose keys are string-encoded integer ratings
|
56 |
+
# and whose values are the number of times that the rating was observed
|
57 |
+
assert isinstance(dist, dict)
|
58 |
+
assert sum(dist.values()) % 2 == 1, "Number of ratings should be odd"
|
59 |
+
|
60 |
+
ratings = []
|
61 |
+
for rating, count in dist.items():
|
62 |
+
ratings.extend([int(rating)] * count)
|
63 |
+
|
64 |
+
ratings.sort()
|
65 |
+
return ratings[len(ratings) // 2]
|
66 |
+
|
67 |
+
|
68 |
+
cebab = load_dataset('CEBaB/CEBaB')
|
69 |
+
assert isinstance(cebab, DatasetDict)
|
70 |
+
|
71 |
+
# Remove redundant splits
|
72 |
+
cebab['train'] = cebab.pop('train_inclusive')
|
73 |
+
del cebab['train_exclusive']
|
74 |
+
del cebab['train_observational']
|
75 |
+
|
76 |
+
cebab = cebab.cast_column(
|
77 |
+
'original_id', Value('int32')
|
78 |
+
).map(
|
79 |
+
lambda x: {
|
80 |
+
# New column with inverted label for counterfactuals
|
81 |
+
'counterfactual': not x['is_original'],
|
82 |
+
# Reduce the rating multiset into a single median rating
|
83 |
+
'rating': compute_median(x['review_label_distribution'])
|
84 |
+
}
|
85 |
+
).map(
|
86 |
+
# Replace the empty string and 'None' with Apache Arrow nulls
|
87 |
+
lambda x: {
|
88 |
+
k: v if v not in ('', 'no majority', 'None') else None
|
89 |
+
for k, v in x.items()
|
90 |
+
}
|
91 |
+
)
|
92 |
+
|
93 |
+
# Sanity check that all the splits have the same columns
|
94 |
+
cols = next(iter(cebab.values())).column_names
|
95 |
+
assert all(split.column_names == cols for split in cebab.values())
|
96 |
+
|
97 |
+
# Clean up the names a bit
|
98 |
+
cebab = cebab.rename_columns({
|
99 |
+
col: col.removesuffix('_majority').removesuffix('_aspect')
|
100 |
+
for col in cols if col.endswith('_majority')
|
101 |
+
}).rename_column(
|
102 |
+
'description', 'text'
|
103 |
+
)
|
104 |
+
|
105 |
+
# Drop the unimportant columns
|
106 |
+
cebab = cebab.remove_columns([
|
107 |
+
col for col in cols if col.endswith('_distribution') or col.endswith('_workers')
|
108 |
+
] + [
|
109 |
+
'edit_id', 'edit_worker', 'id', 'is_original', 'opentable_metadata', 'review'
|
110 |
+
]).sort([
|
111 |
+
# Make sure counterfactual reviews come immediately after each original review
|
112 |
+
'original_id', 'counterfactual'
|
113 |
+
])
|
114 |
+
```
|