Datasets:

Languages:
Vietnamese
ArXiv:
License:
holylovenia commited on
Commit
2911a20
·
verified ·
1 Parent(s): dc0a779

Upload visobert.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. visobert.py +158 -0
visobert.py ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
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
+ from pathlib import Path
17
+ from typing import Dict, List, Tuple
18
+
19
+ import datasets
20
+
21
+ from seacrowd.utils import schemas
22
+ from seacrowd.utils.configs import SEACrowdConfig
23
+ from seacrowd.utils.constants import Licenses, Tasks
24
+
25
+ _CITATION = """\
26
+ @inproceedings{nguyen-etal-2023-visobert,
27
+ title = "{V}i{S}o{BERT}: A Pre-Trained Language Model for {V}ietnamese Social Media Text Processing",
28
+ author = "Nguyen, Nam and
29
+ Phan, Thang and
30
+ Nguyen, Duc-Vu and
31
+ Nguyen, Kiet",
32
+ editor = "Bouamor, Houda and
33
+ Pino, Juan and
34
+ Bali, Kalika",
35
+ booktitle = "Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing",
36
+ month = dec,
37
+ year = "2023",
38
+ address = "Singapore",
39
+ publisher = "Association for Computational Linguistics",
40
+ url = "https://aclanthology.org/2023.emnlp-main.315",
41
+ pages = "5191--5207",
42
+ abstract = "English and Chinese, known as resource-rich languages, have witnessed the strong
43
+ development of transformer-based language models for natural language processing tasks. Although
44
+ Vietnam has approximately 100M people speaking Vietnamese, several pre-trained models, e.g., PhoBERT,
45
+ ViBERT, and vELECTRA, performed well on general Vietnamese NLP tasks, including POS tagging and
46
+ named entity recognition. These pre-trained language models are still limited to Vietnamese social
47
+ media tasks. In this paper, we present the first monolingual pre-trained language model for
48
+ Vietnamese social media texts, ViSoBERT, which is pre-trained on a large-scale corpus of high-quality
49
+ and diverse Vietnamese social media texts using XLM-R architecture. Moreover, we explored our
50
+ pre-trained model on five important natural language downstream tasks on Vietnamese social media
51
+ texts: emotion recognition, hate speech detection, sentiment analysis, spam reviews detection, and
52
+ hate speech spans detection. Our experiments demonstrate that ViSoBERT, with far fewer parameters,
53
+ surpasses the previous state-of-the-art models on multiple Vietnamese social media tasks. Our
54
+ ViSoBERT model is available only for research purposes. Disclaimer: This paper contains actual
55
+ comments on social networks that might be construed as abusive, offensive, or obscene.",
56
+ }
57
+ """
58
+
59
+ _DATASETNAME = "visobert"
60
+
61
+ _DESCRIPTION = """\
62
+ The ViSoBERT corpus is composed of Vietnamese textual data crawled from Facebook, TikTok, and YouTube. The
63
+ dataset contains Facebook posts, TikTok comments, and Youtube comments of Vietnamese-verified users, from
64
+ Jan 2016 (Jan 2020 for TikTok) to Dec 2022. A post-processing mechanism is applied to handles hashtags,
65
+ emojis, misspellings, hyperlinks, and other noncanonical texts.
66
+ """
67
+
68
+ _HOMEPAGE = "https://huggingface.co/uitnlp/visobert"
69
+
70
+ _LANGUAGES = ["vie"]
71
+
72
+ _LICENSE = Licenses.CC_BY_NC_4_0.value
73
+
74
+ _LOCAL = False
75
+
76
+ _URLS = "https://drive.usercontent.google.com/download?id=1BoiR9k2DrjBcd2aHy5BOq4haEp5V2_ug&confirm=xxx"
77
+
78
+ _SUPPORTED_TASKS = [Tasks.SELF_SUPERVISED_PRETRAINING]
79
+
80
+ _SOURCE_VERSION = "1.0.0"
81
+
82
+ _SEACROWD_VERSION = "2024.06.20"
83
+
84
+
85
+ class ViSoBERTDataset(datasets.GeneratorBasedBuilder):
86
+ """
87
+ The ViSoBERT corpus is a Vietnamese pretraining dataset from https://huggingface.co/uitnlp/visobert.
88
+ """
89
+
90
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
91
+ SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
92
+
93
+ BUILDER_CONFIGS = [
94
+ SEACrowdConfig(
95
+ name=f"{_DATASETNAME}_source",
96
+ version=datasets.Version(_SOURCE_VERSION),
97
+ description=f"{_DATASETNAME} source schema",
98
+ schema="source",
99
+ subset_id=f"{_DATASETNAME}",
100
+ ),
101
+ SEACrowdConfig(
102
+ name=f"{_DATASETNAME}_seacrowd_ssp",
103
+ version=datasets.Version(_SEACROWD_VERSION),
104
+ description=f"{_DATASETNAME} SEACrowd schema",
105
+ schema="seacrowd_ssp",
106
+ subset_id=f"{_DATASETNAME}",
107
+ ),
108
+ ]
109
+
110
+ def _info(self) -> datasets.DatasetInfo:
111
+ if self.config.schema == "source" or self.config.schema == "seacrowd_ssp":
112
+ features = schemas.self_supervised_pretraining.features
113
+ else:
114
+ raise ValueError(f"Invalid schema: '{self.config.schema}'")
115
+
116
+ return datasets.DatasetInfo(
117
+ description=_DESCRIPTION,
118
+ features=features,
119
+ homepage=_HOMEPAGE,
120
+ license=_LICENSE,
121
+ citation=_CITATION,
122
+ )
123
+
124
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
125
+ """
126
+ Returns SplitGenerators.
127
+ """
128
+
129
+ path = dl_manager.download(_URLS)
130
+
131
+ return [
132
+ datasets.SplitGenerator(
133
+ name=datasets.Split.TRAIN,
134
+ gen_kwargs={
135
+ "filepath": path,
136
+ "split": "train",
137
+ },
138
+ ),
139
+ ]
140
+
141
+ def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
142
+ """
143
+ Yields examples as (key, example) tuples.
144
+ """
145
+
146
+ with open(filepath, "r", encoding="utf-8") as f:
147
+ if self.config.schema == "source" or self.config.schema == "seacrowd_ssp":
148
+ for idx, row in enumerate(f):
149
+ if row.strip() != "":
150
+ yield (
151
+ idx,
152
+ {
153
+ "id": str(idx),
154
+ "text": row.strip(),
155
+ },
156
+ )
157
+ else:
158
+ raise ValueError(f"Invalid config: '{self.config.name}'")