Skip to content

Commit 643ee98

Browse files
Merge pull request #1252 from Alex-Fabbri:opinosis
PiperOrigin-RevId: 296215231
2 parents fbc76a7 + 84c884d commit 643ee98

File tree

12 files changed

+147
-0
lines changed

12 files changed

+147
-0
lines changed

docs/release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
[VTAB benchmark](https://arxiv.org/abs/1910.04867).
1818
* Add e-SNLI dataset from the paper
1919
[e-SNLI](http://papers.nips.cc/paper/8163-e-snli-natural-language-inference-with-natural-language-explanations.pdf).
20+
* Add [Opinosis dataset](https://www.aclweb.org/anthology/C10-1039.pdf).
2021
* Add SCAN dataset introduced [here](https://arxiv.org/pdf/1711.00350.pdf).
2122
* Add [Imagewang](https://github.com/fastai/imagenette) dataset.
2223
* Add DIV2K dataset from the paper

tensorflow_datasets/summarization/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from tensorflow_datasets.summarization.gigaword import Gigaword
2424
from tensorflow_datasets.summarization.multi_news import MultiNews
2525
from tensorflow_datasets.summarization.newsroom import Newsroom
26+
from tensorflow_datasets.summarization.opinosis import Opinosis
2627
from tensorflow_datasets.summarization.reddit_tifu import RedditTifu
2728
from tensorflow_datasets.summarization.scientific_papers import ScientificPapers
2829
from tensorflow_datasets.summarization.wikihow import Wikihow
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
"""Opinosis Opinion Dataset."""
17+
18+
from __future__ import absolute_import
19+
from __future__ import division
20+
from __future__ import print_function
21+
22+
import os
23+
24+
import tensorflow as tf
25+
import tensorflow_datasets.public_api as tfds
26+
27+
_CITATION = """
28+
@inproceedings{ganesan2010opinosis,
29+
title={Opinosis: a graph-based approach to abstractive summarization of highly redundant opinions},
30+
author={Ganesan, Kavita and Zhai, ChengXiang and Han, Jiawei},
31+
booktitle={Proceedings of the 23rd International Conference on Computational Linguistics},
32+
pages={340--348},
33+
year={2010},
34+
organization={Association for Computational Linguistics}
35+
}
36+
"""
37+
38+
_DESCRIPTION = """
39+
The Opinosis Opinion Dataset consists of sentences extracted from reviews for 51 topics.
40+
Topics and opinions are obtained from Tripadvisor, Edmunds.com and Amazon.com.
41+
"""
42+
43+
_URL = "https://github.com/kavgan/opinosis-summarization/raw/master/OpinosisDataset1.0_0.zip"
44+
45+
_REVIEW_SENTS = "review_sents"
46+
_SUMMARIES = "summaries"
47+
48+
49+
class Opinosis(tfds.core.GeneratorBasedBuilder):
50+
"""Opinosis Opinion Dataset."""
51+
52+
VERSION = tfds.core.Version("1.0.0")
53+
54+
def _info(self):
55+
return tfds.core.DatasetInfo(
56+
builder=self,
57+
description=_DESCRIPTION,
58+
features=tfds.features.FeaturesDict({
59+
_REVIEW_SENTS: tfds.features.Text(),
60+
_SUMMARIES: tfds.features.Sequence(tfds.features.Text())
61+
}),
62+
supervised_keys=(_REVIEW_SENTS, _SUMMARIES),
63+
homepage="http://kavita-ganesan.com/opinosis/",
64+
citation=_CITATION,
65+
)
66+
67+
def _split_generators(self, dl_manager):
68+
"""Returns SplitGenerators."""
69+
extract_path = dl_manager.download_and_extract(_URL)
70+
return [
71+
tfds.core.SplitGenerator(
72+
name=tfds.Split.TRAIN,
73+
gen_kwargs={"path": extract_path},
74+
),
75+
]
76+
77+
def _generate_examples(self, path=None):
78+
"""Yields examples."""
79+
topics_path = os.path.join(path, "topics")
80+
filenames = tf.io.gfile.listdir(topics_path)
81+
for filename in filenames:
82+
file_path = os.path.join(topics_path, filename)
83+
topic_name = filename.split(".txt")[0]
84+
with tf.io.gfile.GFile(file_path, "rb") as src_f:
85+
input_data = src_f.read()
86+
summaries_path = os.path.join(path, "summaries-gold", topic_name)
87+
summary_lst = []
88+
for summ_filename in sorted(tf.io.gfile.listdir(summaries_path)):
89+
file_path = os.path.join(summaries_path, summ_filename)
90+
with tf.io.gfile.GFile(file_path, "rb") as tgt_f:
91+
data = tgt_f.read().strip()
92+
summary_lst.append(data)
93+
summary_data = summary_lst
94+
yield filename, {_REVIEW_SENTS: input_data, _SUMMARIES: summary_data}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
"""Test for Opinosis Opinion Dataset."""
17+
18+
from __future__ import absolute_import
19+
from __future__ import division
20+
from __future__ import print_function
21+
22+
from tensorflow_datasets import testing
23+
from tensorflow_datasets.summarization import opinosis
24+
25+
26+
class OpinosisTest(testing.DatasetBuilderTestCase):
27+
DATASET_CLASS = opinosis.Opinosis
28+
SPLITS = {
29+
"train": 2, # Number of fake test example
30+
}
31+
DL_EXTRACT_RESULT = ""
32+
33+
34+
if __name__ == "__main__":
35+
testing.test_main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is a gold summary for topic 1.
2+
Sentences in gold summaries are separated by newlines.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is another gold summary for topic 1.
2+
Sentences in gold summaries are separated by newlines.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is a gold summary for topic 2.
2+
Sentences in gold summaries are separated by newlines.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is another gold summary for topic 2.
2+
Sentences in gold summaries are separated by newlines.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is another gold summary for topic 2.
2+
Sentences in gold summaries are separated by newlines.
3+
Topics have a variable number of gold summaries.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is a fake topic.
2+
The topics have multiple sentence inputs.

0 commit comments

Comments
 (0)