Datasets:
File size: 4,295 Bytes
653c6d4 2ca435d 653c6d4 |
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 126 127 128 129 130 131 132 |
# coding=utf-8
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Lint as: python3
import csv
import os
import textwrap
import numpy as np
import datasets
import pandas as pd
_CITATION = """\
@article{sileo2022probing,
title={Probing neural language models for understanding of words of estimative probability},
author={Sileo, Damien and Moens, Marie-Francine},
journal={arXiv preprint arXiv:2211.03358},
year={2022}
}
"""
_DESCRIPTION = """\
Probing neural language models for understanding of words of estimative probability
"""
URL = 'https://sileod.s3.eu-west-3.amazonaws.com/probability_words/'
class WepProbeConfig(datasets.BuilderConfig):
"""BuilderConfig for WepProbe."""
def __init__(
self,
data_dir,
label_classes=None,
process_label=lambda x: x,
**kwargs,
):
super(WepProbeConfig, self).__init__(version=datasets.Version("1.0.5", ""), **kwargs)
self.text_features = {k:k for k in ['context', 'hypothesis', 'valid_hypothesis', 'invalid_hypothesis','probability_word','distractor','hypothesis_assertion']}
self.label_column = 'label'
self.label_classes = ['valid', 'invalid']
self.data_url = URL
self.url=URL
self.data_dir=data_dir
self.citation = _CITATION
self.process_label = process_label
class WepProbe(datasets.GeneratorBasedBuilder):
"""Evaluation of word estimative of probability understanding"""
BUILDER_CONFIGS = [
WepProbeConfig(
name="reasoning_1hop",
data_dir="reasoning_1hop"),
WepProbeConfig(
name="reasoning_2hop",
data_dir="reasoning_2hop"),
WepProbeConfig(
name="usnli",
data_dir="usnli"),
]
def _info(self):
features = {text_feature: datasets.Value("string") for text_feature in self.config.text_features.keys()}
if self.config.label_classes:
features["label"] = datasets.features.ClassLabel(names=self.config.label_classes)
else:
features["label"] = datasets.Value("float32")
features["idx"] = datasets.Value("int32")
features["probability"] = datasets.Value("float32")
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(features),
homepage=self.config.url,
citation=self.config.citation + "\n" + _CITATION,
)
def _split_generators(self, dl_manager):
data_dirs=[]
for split in ['train','validation','test']:
url=f'{URL}{self.config.data_dir}_{split}.csv'
print(url)
data_dirs+=[dl_manager.download(url)]
print(data_dirs)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"data_file": data_dirs[0],
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"data_file": data_dirs[1],
"split": "dev",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"data_file": data_dirs[2],
"split": "test",
},
),
]
def _generate_examples(self, data_file, split):
df = pd.read_csv(data_file).drop(['rnd','split','_'],axis=1,errors='ignore')
df['idx']=df.index
for idx, example in df.iterrows():
yield idx, dict(example)
|