File size: 3,540 Bytes
c273d21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58a9aa1
c273d21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58a9aa1
c273d21
 
e8f12cd
 
 
 
 
 
 
 
 
 
c273d21
 
 
 
58a9aa1
c273d21
 
 
 
 
 
15edcfb
fdecbb6
4df098e
 
 
 
 
 
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
# -*- coding: utf-8 -*-
"""
@author:XuMing(xuming624@qq.com)
@description:
2021搜狐校园文本匹配算法大赛数据集
upload: https://github.com/shibing624
"""


import csv
import os
import json
import datasets


_CITATION = """https://github.com/shibing624/text2vec"""

_DESCRIPTION = """\
2021搜狐校园文本匹配算法大赛数据集
"""

_DATA_URL = "https://huggingface.co/datasets/shibing624/sts-sohu2021/resolve/main"


class Sohu(datasets.GeneratorBasedBuilder):
    """The Chinese Natural Language Inference (sts-sohu) Corpus."""

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name="dda",
            version=datasets.Version("1.0.0", ""),
            description="Plain text import of sts-sohu2021",
        ),
        datasets.BuilderConfig(
            name="ddb",
            version=datasets.Version("1.0.0", ""),
            description="Plain text import of sts-sohu2021",
        ),
        datasets.BuilderConfig(
            name="dca",
            version=datasets.Version("1.0.0", ""),
            description="Plain text import of sts-sohu2021",
        ),
        datasets.BuilderConfig(
            name="dcb",
            version=datasets.Version("1.0.0", ""),
            description="Plain text import of sts-sohu2021",
        ),
        datasets.BuilderConfig(
            name="cca",
            version=datasets.Version("1.0.0", ""),
            description="Plain text import of sts-sohu2021",
        ),
        datasets.BuilderConfig(
            name="ccb",
            version=datasets.Version("1.0.0", ""),
            description="Plain text import of sts-sohu2021",
        ),
        
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "sentence1": datasets.Value("string"),
                    "sentence2": datasets.Value("string"),
                    "label": datasets.Value("int32"),
                }
            ),

            supervised_keys=None,
            homepage="https://github.com/shibing624/text2vec",
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        # https://huggingface.co/datasets/shibing624/sts-sohu2021/resolve/main/dda.jsonl
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN, 
                gen_kwargs={
                    "filepath": dl_manager.download_and_extract(f"{_DATA_URL}/{self.config.name}-train.jsonl")
                }
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "filepath": dl_manager.download_and_extract(f"{_DATA_URL}/{self.config.name}-test.jsonl")
                }
            ),
        ]

    def _generate_examples(self, filepath):
        """This function returns the examples in the raw (jsonl) form."""
        id = 0
        if isinstance(filepath, str):
            filepath = [filepath]
        for file in filepath:
            with open(file, encoding="utf-8") as f:
                for key, row in enumerate(f):
                    if row and len(row) > 1:
                        data = json.loads(row)
                        yield id, {
                                "sentence1": data["sentence1"],
                                "sentence2": data["sentence2"],
                                "label": int(data["label"])
                        }
                        id += 1