Skip to content

Commit 1987f10

Browse files
TensorFlow Datasets Teamcopybara-github
authored andcommitted
Add eraser_multi_rc dataset
PiperOrigin-RevId: 291732980
1 parent 9dd9d66 commit 1987f10

File tree

12 files changed

+321
-0
lines changed

12 files changed

+321
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
The judge leaned back in his chair and beckoned to Mr. Andrews .
2+
It was finished .
3+
Spear was free , and from different parts of the courtroom people were moving
4+
toward the door .
5+
Their numbers showed that the friends of the young man had been many .
6+
Mr. Thorndike felt a certain twinge of disappointment .
7+
Even though the result relieved and pleased him , he wished , in bringing it
8+
about , he had had some part .
9+
He begrudged to Isaacs & Sons the credit of having given Spear his liberty .
10+
His morning had been wasted .
11+
He had neglected his own interests , and in no way assisted those of Spear .
12+
He was moving out of the railed enclosure when Andrews called him by name .
13+
" His honor , " he said impressively , " wishes to speak to you . " The judge
14+
leaned over his desk and shook Mr. Thorndike by the hand .
15+
Then he made a speech .
16+
The speech was about public - spirited citizens who , to the neglect of their
17+
own interests , came to assist the ends of justice , and fellow - creatures in
18+
misfortune .
19+
He purposely spoke in a loud voice , and every one stopped to listen .
20+
" The law , Mr. Thorndike , is not vindictive , " he said .
21+
" It wishes only to be just .
22+
Nor can it be swayed by wealth or political or social influences .
23+
But when there is good in a man , I , personally , want to know it , and when
24+
gentlemen like yourself , of your standing in this city , come here to speak a
25+
good word for a man , we would stultify the purpose of justice if we did not
26+
listen .
27+
I thank you for coming , and I wish more of our citizens were as unselfish and
28+
public - spirited . " It was all quite absurd and most embarrassing , but
29+
inwardly Mr. Thorndike glowed with pleasure .
30+
It was a long time since any one had had the audacity to tell him he had done
31+
well .
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
As his car slid downtown on Tuesday morning the mind of Arnold Thorndike was
2+
occupied with such details of daily routine as the purchase of a railroad , the
3+
Japanese loan , the new wing to his art gallery , and an attack that morning ,
4+
in his own newspaper , upon his pet trust .
5+
But his busy mind was not too occupied to return the salutes of the traffic
6+
policemen who cleared the way for him .
7+
Or , by some genius of memory , to recall the fact that it was on this morning
8+
young Spear was to be sentenced for theft .
9+
It was a charming morning .
10+
The spring was at full tide , and the air was sweet and clean .
11+
Mr. Thorndike considered whimsically that to send a man to jail with the memory
12+
of such a morning clinging to him was adding a year to his sentence .
13+
He regretted he had not given the probation officer a stronger letter .
14+
He remembered the young man now , and favorably .
15+
A shy , silent youth , deft in work , and at other times conscious and
16+
embarrassed .
17+
But that , on the part of a stenographer , in the presence of the Wisest Man in
18+
Wall Street , was not unnatural .
19+
On occasions , Mr. Thorndike had put even royalty— frayed , impecunious royalty
20+
, on the lookout for a loan — at its ease .
21+
The hood of the car was down , and the taste of the air , warmed by the sun ,
22+
was grateful .
23+
It was at this time , a year before , that young Spear picked the spring flowers
24+
to take to his mother .
25+
A year from now where would young Spear be ?
26+
It was characteristic of the great man to act quickly , so quickly that his
27+
friends declared he was a slave to impulse .
28+
It was these same impulses , leading so invariably to success , that made his
29+
enemies call him the Wisest Man .
30+
He leaned forward and touched the chauffeur 's shoulder .
31+
" Stop at the Court of General Sessions , " he commanded .
32+
What he proposed to do would take but a few minutes .
33+
A word , a personal word from him to the district attorney , or the judge ,
34+
would be enough .
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
As his car slid downtown on Tuesday morning the mind of Arnold Thorndike was
2+
occupied with such details of daily routine as the purchase of a railroad , the
3+
Japanese loan , the new wing to his art gallery , and an attack that morning ,
4+
in his own newspaper , upon his pet trust .
5+
But his busy mind was not too occupied to return the salutes of the traffic
6+
policemen who cleared the way for him .
7+
Or , by some genius of memory , to recall the fact that it was on this morning
8+
young Spear was to be sentenced for theft .
9+
It was a charming morning .
10+
The spring was at full tide , and the air was sweet and clean .
11+
Mr. Thorndike considered whimsically that to send a man to jail with the memory
12+
of such a morning clinging to him was adding a year to his sentence .
13+
He regretted he had not given the probation officer a stronger letter .
14+
He remembered the young man now , and favorably .
15+
A shy , silent youth , deft in work , and at other times conscious and
16+
embarrassed .
17+
But that , on the part of a stenographer , in the presence of the Wisest Man in
18+
Wall Street , was not unnatural .
19+
On occasions , Mr. Thorndike had put even royalty— frayed , impecunious royalty
20+
, on the lookout for a loan — at its ease .
21+
The hood of the car was down , and the taste of the air , warmed by the sun ,
22+
was grateful .
23+
It was at this time , a year before , that young Spear picked the spring flowers
24+
to take to his mother .
25+
A year from now where would young Spear be ?
26+
It was characteristic of the great man to act quickly , so quickly that his
27+
friends declared he was a slave to impulse .
28+
It was these same impulses , leading so invariably to success , that made his
29+
enemies call him the Wisest Man .
30+
He leaned forward and touched the chauffeur 's shoulder .
31+
" Stop at the Court of General Sessions , " he commanded .
32+
What he proposed to do would take but a few minutes .
33+
A word , a personal word from him to the district attorney , or the judge ,
34+
would be enough .
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
He continued to lie in place , still breathing heavily .
2+
I tried to keep myself calm .
3+
Then , with a sigh , he said , " I have need of a certain stone that I once
4+
possessed .
5+
It would allow me to leave this bed , despite my current illness .
6+
My problem is that it was not made in this realm , but by a human , and only a
7+
human may handle it .
8+
The herb vendor will tell you where you can find it .
9+
If you would fetch me this stone , I would tell you what I can . " " Of course
10+
we will fetch you the stone , " Nepthys assured him .
11+
" You have our thanks . " Outside , the thing at the herb cart nodded when we
12+
mentioned the stone .
13+
He told Nepthys the name of a woman who lived on a certain street , and we set
14+
off .
15+
When we reached the street , I expected some sort of temple , or a row of
16+
antiquaries , or at least a sleazy , black - market relics merchant .
17+
Instead , it looked like we were in the red - light district : women who
18+
probably wanted more than our money eyed us from the alleys .
19+
Nepthys did n't need to warn me not to speak to them .
20+
He took us to the door of a building like a short pagoda that had a sign hanging
21+
over it showing a face with hands uplifted , like a saint under G d 's light ,
22+
and handcuffed .
23+
Inside , the entrance room was hung with bright silks and scattered with velvet
24+
cushions .
25+
Sails of obscene orange and a green that insulted springtime hung draped across
26+
reds that might have been sensual elsewhere but here were only offensive .
27+
A large woman , similarly decorated , quickly drifted up to us .
28+
" Good evening , gentlemen , " she said .
29+
" May I invite you to have a cup of tea ? " " No , thank you , " said Nepthys ,
30+
" we regret that we can not take up your kind offer .
31+
Are you the proprietor of this shop ? " " Yes , " answered the woman .
32+
" I am Madame Entera , at your service .
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Allan sat down at his desk and pulled the chair in close .
2+
Opening a side drawer , he took out a piece of paper and his inkpot .
3+
After filling his pen , Allan looked at his paper in the orange glow from the
4+
lantern set back in the desk 's right - hand corner .
5+
His pen cast a forbidding line of shadow slanting across the page , echoing the
6+
inky darkness crouching in the edges of the lantern 's struggling glow .
7+
The only other illumination came from a lurid moonlight filtered through thin
8+
branches and clouds , casting its bone - pale glow onto the pine floorboards .
9+
Allan unfolded another page , this one crowded with ranks of letters in tight
10+
formation from left to right .
11+
The lines of letters stepped into their divisions , in the shape of a story 's
12+
outline : the loose , dry skeleton of a tale lay exposed beneath their feet ,
13+
awaiting tendons , muscle and blushing skin .
14+
Allan reviewed the troops , all prepared to disembark , their task to form the
15+
tale of a young man returning home from Life Abroad to find his childhood friend
16+
a bride to - be , thus upsetting the apple cart of his life 's plan , clarified
17+
– of course – by his very time away from her he loved best .
18+
Although the concept was a simple one , Allan thought it had potential .
19+
Besides , the public liked a good , simple romance .
20+
Perhaps this will be more saleable , he thought and began to write .
21+
They gazed at each other , lost in the rapture of love based so deeply within
22+
their hearts that they had never seen it before .
23+
" What about Roger ? "
24+
she asked , knowing that the answer no longer mattered .
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"annotation_id": "Fiction-stories-masc-A_Wasted_Day-11.txt:0:0", "classification": "True", "docids": null, "evidences": [[{"docid": "test1.txt", "end_sentence": 15, "end_token": 233, "start_sentence": 14, "start_token": 218, "text": "\" The law , Mr. Thorndike , is not vindictive , \" he said ."}, {"docid": "test1.txt", "end_sentence": 16, "end_token": 241, "start_sentence": 15, "start_token": 233, "text": "\" It wishes only to be just ."}, {"docid": "test1.txt", "end_sentence": 17, "end_token": 254, "start_sentence": 16, "start_token": 241, "text": "Nor can it be swayed by wealth or political or social influences ."}]], "query": "What did the judge tell Mr. Thorndike about the law ? || Cannot be swayed by wealth or political or social influences", "query_type": null}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{"annotation_id": "Fiction-stories-masc-A_Wasted_Day-2.txt:0:0", "classification": "False", "docids": null, "evidences": [[{"docid": "train1.txt", "end_sentence": 16, "end_token": 349, "start_sentence": 15, "start_token": 327, "text": "It was these same impulses , leading so invariably to success , that made his enemies call him the Wisest Man ."}, {"docid": "train1.txt", "end_sentence": 17, "end_token": 359, "start_sentence": 16, "start_token": 349, "text": "He leaned forward and touched the chauffeur 's shoulder ."}, {"docid": "train1.txt", "end_sentence": 18, "end_token": 372, "start_sentence": 17, "start_token": 359, "text": "\" Stop at the Court of General Sessions , \" he commanded ."}, {"docid": "train1.txt", "end_sentence": 20, "end_token": 405, "start_sentence": 19, "start_token": 384, "text": "A word , a personal word from him to the district attorney , or the judge , would be enough ."}]], "query": "How does Mr. Thorndike act upon his impulse ? || It depended on the impulse", "query_type": null}
2+
{"annotation_id": "Fiction-stories-masc-A_Wasted_Day-2.txt:0:1", "classification": "False", "docids": null, "evidences": [[{"docid": "train2.txt", "end_sentence": 16, "end_token": 349, "start_sentence": 15, "start_token": 327, "text": "It was these same impulses , leading so invariably to success , that made his enemies call him the Wisest Man ."}, {"docid": "train2.txt", "end_sentence": 17, "end_token": 359, "start_sentence": 16, "start_token": 349, "text": "He leaned forward and touched the chauffeur 's shoulder ."}, {"docid": "train2.txt", "end_sentence": 18, "end_token": 372, "start_sentence": 17, "start_token": 359, "text": "\" Stop at the Court of General Sessions , \" he commanded ."}, {"docid": "train2.txt", "end_sentence": 20, "end_token": 405, "start_sentence": 19, "start_token": 384, "text": "A word , a personal word from him to the district attorney , or the judge , would be enough ."}]], "query": "How does Mr. Thorndike act upon his impulse ? || He didn't - he first thought things through", "query_type": null}
3+
{"annotation_id": "Fiction-stories-masc-Nathans_Bylichka-6.txt:12:2", "classification": "True", "docids": null, "evidences": [[{"docid": "train3.txt", "end_sentence": 3, "end_token": 40, "start_sentence": 2, "start_token": 18, "text": "Then , with a sigh , he said , \" I have need of a certain stone that I once possessed ."}, {"docid": "train3.txt", "end_sentence": 5, "end_token": 79, "start_sentence": 4, "start_token": 54, "text": "My problem is that it was not made in this realm , but by a human , and only a human may handle it ."}]], "query": "Who can handle the stone ? || Only a human can handle it", "query_type": null}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"annotation_id": "Fiction-stories-masc-The_Black_Willow-0.txt:0:0", "classification": "False", "docids": null, "evidences": [[{"docid": "valid1.txt", "end_sentence": 1, "end_token": 13, "start_sentence": 0, "start_token": 0, "text": "Allan sat down at his desk and pulled the chair in close ."}, {"docid": "valid1.txt", "end_sentence": 2, "end_token": 29, "start_sentence": 1, "start_token": 13, "text": "Opening a side drawer , he took out a piece of paper and his inkpot ."}, {"docid": "valid1.txt", "end_sentence": 3, "end_token": 57, "start_sentence": 2, "start_token": 29, "text": "After filling his pen , Allan looked at his paper in the orange glow from the lantern set back in the desk 's right - hand corner ."}]], "query": "Name few objects said to be in or on Allan 's desk || Eraser", "query_type": null}

tensorflow_datasets/text/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from tensorflow_datasets.text.civil_comments import CivilComments
2020
from tensorflow_datasets.text.cos_e import CosE
2121
from tensorflow_datasets.text.definite_pronoun_resolution import DefinitePronounResolution
22+
from tensorflow_datasets.text.eraser_multi_rc import EraserMultiRc
2223
from tensorflow_datasets.text.esnli import Esnli
2324
from tensorflow_datasets.text.gap import Gap
2425
from tensorflow_datasets.text.glue import Glue
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# coding=utf-8
2+
# Copyright 2020 The TensorFlow Datasets Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
"""Passage, query, answers and answer classification with explanations."""
17+
18+
from __future__ import absolute_import
19+
from __future__ import division
20+
from __future__ import print_function
21+
22+
import json
23+
import os
24+
import tensorflow as tf
25+
import tensorflow_datasets.public_api as tfds
26+
27+
_CITATION = """
28+
@unpublished{eraser2019,
29+
title = {ERASER: A Benchmark to Evaluate Rationalized NLP Models},
30+
author = {Jay DeYoung and Sarthak Jain and Nazneen Fatema Rajani and Eric Lehman and Caiming Xiong and Richard Socher and Byron C. Wallace}
31+
}
32+
@inproceedings{MultiRC2018,
33+
author = {Daniel Khashabi and Snigdha Chaturvedi and Michael Roth and Shyam Upadhyay and Dan Roth},
34+
title = {Looking Beyond the Surface:A Challenge Set for Reading Comprehension over Multiple Sentences},
35+
booktitle = {NAACL},
36+
year = {2018}
37+
}
38+
"""
39+
40+
_DESCRIPTION = """
41+
Eraser Multi RC is a dataset for queries over multi-line passages, along with
42+
answers and a rationalte. Each example in this dataset has the following 5 parts
43+
1. A Mutli-line Passage
44+
2. A Query about the passage
45+
3. An Answer to the query
46+
4. A Classification as to whether the answer is right or wrong
47+
5. An Explanation justifying the classification
48+
"""
49+
50+
_DOWNLOAD_URL = 'http://www.eraserbenchmark.com/zipped/multirc.tar.gz'
51+
52+
53+
class EraserMultiRc(tfds.core.GeneratorBasedBuilder):
54+
"""Multi Sentence Reasoning with Explanations (Eraser Benchmark)."""
55+
56+
VERSION = tfds.core.Version('0.1.0')
57+
58+
def _info(self):
59+
return tfds.core.DatasetInfo(
60+
builder=self,
61+
description=_DESCRIPTION,
62+
features=tfds.features.FeaturesDict({
63+
'passage': tfds.features.Text(),
64+
'query_and_answer': tfds.features.Text(),
65+
'label': tfds.features.ClassLabel(names=['True', 'False']),
66+
'evidences': tfds.features.Sequence(tfds.features.Text())
67+
}),
68+
supervised_keys=None,
69+
homepage='https://cogcomp.seas.upenn.edu/multirc/',
70+
citation=_CITATION,
71+
)
72+
73+
def _split_generators(self, dl_manager):
74+
"""Returns SplitGenerators."""
75+
76+
dl_dir = dl_manager.download_and_extract(_DOWNLOAD_URL)
77+
data_dir = os.path.join(dl_dir, 'multirc')
78+
return [
79+
tfds.core.SplitGenerator(
80+
name=tfds.Split.TRAIN,
81+
# These kwargs will be passed to _generate_examples
82+
gen_kwargs={'data_dir': data_dir,
83+
'filepath': os.path.join(data_dir, 'train.jsonl')},
84+
),
85+
tfds.core.SplitGenerator(
86+
name=tfds.Split.VALIDATION,
87+
# These kwargs will be passed to _generate_examples
88+
gen_kwargs={'data_dir': data_dir,
89+
'filepath': os.path.join(data_dir, 'val.jsonl')},
90+
),
91+
tfds.core.SplitGenerator(
92+
name=tfds.Split.TEST,
93+
# These kwargs will be passed to _generate_examples
94+
gen_kwargs={'data_dir': data_dir,
95+
'filepath': os.path.join(data_dir, 'test.jsonl')},
96+
),
97+
]
98+
99+
def _generate_examples(self, data_dir, filepath):
100+
"""Yields examples."""
101+
102+
multirc_dir = os.path.join(data_dir, 'docs')
103+
with tf.io.gfile.GFile(filepath) as f:
104+
for line in f:
105+
row = json.loads(line)
106+
evidences = []
107+
108+
for evidence in row['evidences'][0]:
109+
docid = evidence['docid']
110+
evidences.append(evidence['text'])
111+
112+
passage_file = os.path.join(multirc_dir, docid)
113+
with tf.io.gfile.GFile(passage_file) as f1:
114+
passage_text = f1.read()
115+
116+
yield row['annotation_id'], {
117+
'passage': passage_text,
118+
'query_and_answer': row['query'],
119+
'label': row['classification'],
120+
'evidences': evidences
121+
}

0 commit comments

Comments
 (0)