lannliat
commited on
Commit
•
3ffddfd
1
Parent(s):
db86890
First commit
Browse files- .gitignore +160 -0
- README.md +155 -0
- load_script.py +110 -0
.gitignore
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
share/python-wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
MANIFEST
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
.hypothesis/
|
51 |
+
.pytest_cache/
|
52 |
+
cover/
|
53 |
+
|
54 |
+
# Translations
|
55 |
+
*.mo
|
56 |
+
*.pot
|
57 |
+
|
58 |
+
# Django stuff:
|
59 |
+
*.log
|
60 |
+
local_settings.py
|
61 |
+
db.sqlite3
|
62 |
+
db.sqlite3-journal
|
63 |
+
|
64 |
+
# Flask stuff:
|
65 |
+
instance/
|
66 |
+
.webassets-cache
|
67 |
+
|
68 |
+
# Scrapy stuff:
|
69 |
+
.scrapy
|
70 |
+
|
71 |
+
# Sphinx documentation
|
72 |
+
docs/_build/
|
73 |
+
|
74 |
+
# PyBuilder
|
75 |
+
.pybuilder/
|
76 |
+
target/
|
77 |
+
|
78 |
+
# Jupyter Notebook
|
79 |
+
.ipynb_checkpoints
|
80 |
+
|
81 |
+
# IPython
|
82 |
+
profile_default/
|
83 |
+
ipython_config.py
|
84 |
+
|
85 |
+
# pyenv
|
86 |
+
# For a library or package, you might want to ignore these files since the code is
|
87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
88 |
+
# .python-version
|
89 |
+
|
90 |
+
# pipenv
|
91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94 |
+
# install all needed dependencies.
|
95 |
+
#Pipfile.lock
|
96 |
+
|
97 |
+
# poetry
|
98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100 |
+
# commonly ignored for libraries.
|
101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
102 |
+
#poetry.lock
|
103 |
+
|
104 |
+
# pdm
|
105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
106 |
+
#pdm.lock
|
107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
108 |
+
# in version control.
|
109 |
+
# https://pdm.fming.dev/#use-with-ide
|
110 |
+
.pdm.toml
|
111 |
+
|
112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
113 |
+
__pypackages__/
|
114 |
+
|
115 |
+
# Celery stuff
|
116 |
+
celerybeat-schedule
|
117 |
+
celerybeat.pid
|
118 |
+
|
119 |
+
# SageMath parsed files
|
120 |
+
*.sage.py
|
121 |
+
|
122 |
+
# Environments
|
123 |
+
.env
|
124 |
+
.venv
|
125 |
+
env/
|
126 |
+
venv/
|
127 |
+
ENV/
|
128 |
+
env.bak/
|
129 |
+
venv.bak/
|
130 |
+
|
131 |
+
# Spyder project settings
|
132 |
+
.spyderproject
|
133 |
+
.spyproject
|
134 |
+
|
135 |
+
# Rope project settings
|
136 |
+
.ropeproject
|
137 |
+
|
138 |
+
# mkdocs documentation
|
139 |
+
/site
|
140 |
+
|
141 |
+
# mypy
|
142 |
+
.mypy_cache/
|
143 |
+
.dmypy.json
|
144 |
+
dmypy.json
|
145 |
+
|
146 |
+
# Pyre type checker
|
147 |
+
.pyre/
|
148 |
+
|
149 |
+
# pytype static type analyzer
|
150 |
+
.pytype/
|
151 |
+
|
152 |
+
# Cython debug symbols
|
153 |
+
cython_debug/
|
154 |
+
|
155 |
+
# PyCharm
|
156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
+
#.idea/
|
README.md
ADDED
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
annotations_creators:
|
3 |
+
- expert-generated
|
4 |
+
- found
|
5 |
+
language_creators:
|
6 |
+
- found
|
7 |
+
- expert-generated
|
8 |
+
license: []
|
9 |
+
multilinguality:
|
10 |
+
- translation
|
11 |
+
pretty_name: opus
|
12 |
+
size_categories: []
|
13 |
+
source_datasets: []
|
14 |
+
tags:
|
15 |
+
- parallel-corpus
|
16 |
+
task_categories:
|
17 |
+
- translation
|
18 |
+
task_ids: []
|
19 |
+
---
|
20 |
+
|
21 |
+
# Dataset Card for [opus]
|
22 |
+
|
23 |
+
## Table of Contents
|
24 |
+
- [Table of Contents](#table-of-contents)
|
25 |
+
- [Dataset Description](#dataset-description)
|
26 |
+
- [Dataset Summary](#dataset-summary)
|
27 |
+
- [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
|
28 |
+
- [Languages](#languages)
|
29 |
+
- [Dataset Structure](#dataset-structure)
|
30 |
+
- [Data Instances](#data-instances)
|
31 |
+
- [Data Fields](#data-fields)
|
32 |
+
- [Data Splits](#data-splits)
|
33 |
+
- [Dataset Creation](#dataset-creation)
|
34 |
+
- [Curation Rationale](#curation-rationale)
|
35 |
+
- [Source Data](#source-data)
|
36 |
+
- [Annotations](#annotations)
|
37 |
+
- [Personal and Sensitive Information](#personal-and-sensitive-information)
|
38 |
+
- [Considerations for Using the Data](#considerations-for-using-the-data)
|
39 |
+
- [Social Impact of Dataset](#social-impact-of-dataset)
|
40 |
+
- [Discussion of Biases](#discussion-of-biases)
|
41 |
+
- [Other Known Limitations](#other-known-limitations)
|
42 |
+
- [Additional Information](#additional-information)
|
43 |
+
- [Dataset Curators](#dataset-curators)
|
44 |
+
- [Licensing Information](#licensing-information)
|
45 |
+
- [Citation Information](#citation-information)
|
46 |
+
- [Contributions](#contributions)
|
47 |
+
|
48 |
+
## Dataset Description
|
49 |
+
Loads [OPUS](https://opus.nlpl.eu/) as HuggingFace dataset. OPUS is an open parallel corpus covering 700+ languages and 1100+ datasets.
|
50 |
+
|
51 |
+
Given a `src` and `tgt` language, this repository loads *all* available parallel corpus. To my knowledge, other OPUS datasets on Huggingface loads a specific corpus
|
52 |
+
|
53 |
+
**Requirements**. Pip install my fork of `OpusTools`.
|
54 |
+
|
55 |
+
```
|
56 |
+
git clone https://github.com/larrylawl/OpusTools.git
|
57 |
+
pip install -e OpusTools/opustools_pkg
|
58 |
+
```
|
59 |
+
|
60 |
+
**Disclaimer**.
|
61 |
+
|
62 |
+
This repository is still in active development. Do make a PR if there're any issues!
|
63 |
+
|
64 |
+
### Dataset Summary
|
65 |
+
|
66 |
+
[More Information Needed]
|
67 |
+
|
68 |
+
### Supported Tasks and Leaderboards
|
69 |
+
|
70 |
+
[More Information Needed]
|
71 |
+
|
72 |
+
### Languages
|
73 |
+
|
74 |
+
Available languages can be viewed on the [OPUS API](https://opus.nlpl.eu/opusapi/?languages=True)
|
75 |
+
|
76 |
+
## Dataset Structure
|
77 |
+
|
78 |
+
### Data Instances
|
79 |
+
|
80 |
+
[More Information Needed]
|
81 |
+
|
82 |
+
### Data Fields
|
83 |
+
|
84 |
+
```
|
85 |
+
features = {
|
86 |
+
"src": datasets.Value("string"),
|
87 |
+
"tgt": datasets.Value("string"),
|
88 |
+
}
|
89 |
+
```
|
90 |
+
|
91 |
+
### Data Splits
|
92 |
+
|
93 |
+
Merged all data into train split.
|
94 |
+
|
95 |
+
## Dataset Creation
|
96 |
+
|
97 |
+
### Curation Rationale
|
98 |
+
|
99 |
+
[More Information Needed]
|
100 |
+
|
101 |
+
### Source Data
|
102 |
+
|
103 |
+
#### Initial Data Collection and Normalization
|
104 |
+
|
105 |
+
[More Information Needed]
|
106 |
+
|
107 |
+
#### Who are the source language producers?
|
108 |
+
|
109 |
+
[More Information Needed]
|
110 |
+
|
111 |
+
### Annotations
|
112 |
+
|
113 |
+
#### Annotation process
|
114 |
+
|
115 |
+
[More Information Needed]
|
116 |
+
|
117 |
+
#### Who are the annotators?
|
118 |
+
|
119 |
+
[More Information Needed]
|
120 |
+
|
121 |
+
### Personal and Sensitive Information
|
122 |
+
|
123 |
+
[More Information Needed]
|
124 |
+
|
125 |
+
## Considerations for Using the Data
|
126 |
+
|
127 |
+
### Social Impact of Dataset
|
128 |
+
|
129 |
+
[More Information Needed]
|
130 |
+
|
131 |
+
### Discussion of Biases
|
132 |
+
|
133 |
+
[More Information Needed]
|
134 |
+
|
135 |
+
### Other Known Limitations
|
136 |
+
|
137 |
+
[More Information Needed]
|
138 |
+
|
139 |
+
## Additional Information
|
140 |
+
|
141 |
+
### Dataset Curators
|
142 |
+
|
143 |
+
[More Information Needed]
|
144 |
+
|
145 |
+
### Licensing Information
|
146 |
+
|
147 |
+
[More Information Needed]
|
148 |
+
|
149 |
+
### Citation Information
|
150 |
+
|
151 |
+
[More Information Needed]
|
152 |
+
|
153 |
+
### Contributions
|
154 |
+
|
155 |
+
Thanks to [@larrylawl](https://larrylawl.github.io/) for adding this dataset.
|
load_script.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace 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 |
+
# Lint as: python3
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
import json
|
21 |
+
import os
|
22 |
+
from typing import List
|
23 |
+
import datasets
|
24 |
+
import pandas as pd
|
25 |
+
from constants import *
|
26 |
+
from OpusTools.opustools_pkg.opustools.opus_read import OpusRead
|
27 |
+
from OpusTools.opustools_pkg.opustools.opus_get import OpusRead
|
28 |
+
|
29 |
+
_DESCRIPTION = """\
|
30 |
+
Downloads OPUS data using `opustools`.
|
31 |
+
"""
|
32 |
+
|
33 |
+
_VERSION = "1.0.0"
|
34 |
+
_URL = "https://opus.nlpl.eu/"
|
35 |
+
|
36 |
+
class OpusConfig(datasets.BuilderConfig):
|
37 |
+
"""BuilderConfig for Opus Dataset."""
|
38 |
+
|
39 |
+
def __init__(self, *args, src=None, tgt=None, corpus=None, download_dir="data", **kwargs):
|
40 |
+
""" BuilderConfig for Opus Dataset.
|
41 |
+
The following args follows `opustools`: https://pypi.org/project/opustools/
|
42 |
+
|
43 |
+
Args:
|
44 |
+
src: str, source language
|
45 |
+
tgt: str, target language
|
46 |
+
corpus: List[str], List of corpus names. Leave as `None` to download all available corpus for the src-tgt pair.
|
47 |
+
download_dir: str, dir to save downloaded files
|
48 |
+
|
49 |
+
"""
|
50 |
+
|
51 |
+
super(OpusConfig, self).__init__(
|
52 |
+
*args,
|
53 |
+
name=f"{src}-{tgt}",
|
54 |
+
description=f"Translating {src} to {tgt} or vice versa",
|
55 |
+
**kwargs)
|
56 |
+
self.src = src
|
57 |
+
self.tgt = tgt
|
58 |
+
self.opus_get = opustools.OpusGet(source=src, target=tgt, list_resources=True, directory=corpus)
|
59 |
+
self.download_dir = download_dir
|
60 |
+
|
61 |
+
def get_corpora_data(self):
|
62 |
+
""" Returns corpora, number of files, and total size. """
|
63 |
+
return self.opus_get.get_corpora_data()
|
64 |
+
|
65 |
+
|
66 |
+
class Opus(datasets.GeneratorBasedBuilder):
|
67 |
+
""" Opus dataset.
|
68 |
+
See: https://huggingface.co/docs/datasets/dataset_script#create-a-dataset-loading-script"""
|
69 |
+
|
70 |
+
BUILDER_CONFIG_CLASS = OpusConfig
|
71 |
+
|
72 |
+
def _info(self):
|
73 |
+
features = {
|
74 |
+
"src": datasets.Value("string"),
|
75 |
+
"tgt": datasets.Value("string"),
|
76 |
+
}
|
77 |
+
|
78 |
+
return datasets.DatasetInfo(
|
79 |
+
description=_DESCRIPTION,
|
80 |
+
features=datasets.Features(features),
|
81 |
+
homepage=_URL,
|
82 |
+
)
|
83 |
+
|
84 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
85 |
+
return [
|
86 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={}),
|
87 |
+
]
|
88 |
+
|
89 |
+
def _generate_examples(self):
|
90 |
+
# read from specific corpus
|
91 |
+
id_ = 0
|
92 |
+
|
93 |
+
data = self.config.opus_get.get_corpora_data()
|
94 |
+
self.config.opus_get.print_files(*data)
|
95 |
+
|
96 |
+
for d in data[0]:
|
97 |
+
opus_reader = opustools.OpusRead(
|
98 |
+
directory=d["corpus"],
|
99 |
+
source=self.config.src,
|
100 |
+
target=self.config.tgt,
|
101 |
+
write_mode="yield_tuple",
|
102 |
+
leave_non_alignments_out=True,
|
103 |
+
download_dir=self.config.download_dir,
|
104 |
+
suppress_prompts=True,
|
105 |
+
)
|
106 |
+
gen = opus_reader.printPairs()
|
107 |
+
for src, tgt in gen:
|
108 |
+
yield id_, {"src": src, "tgt": tgt}
|
109 |
+
id_ += 1
|
110 |
+
|