Datasets:
Upload permutation-groups.py with huggingface_hub
Browse files- permutation-groups.py +130 -0
permutation-groups.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
import json
|
| 3 |
+
from sympy.combinatorics import Permutation
|
| 4 |
+
from sympy.combinatorics.named_groups import AlternatingGroup, SymmetricGroup
|
| 5 |
+
|
| 6 |
+
_DESCRIPTION = "A collection of permutation composition datasets for various symmetric and alternating groups."
|
| 7 |
+
_HOMEPAGE = "https://huggingface.co/datasets/BeeGass/permutation-groups"
|
| 8 |
+
_LICENSE = "MIT"
|
| 9 |
+
|
| 10 |
+
class PermutationGroupsConfig(datasets.BuilderConfig):
|
| 11 |
+
def __init__(self, *args, group_name=None, group_degree=None, group_order=None, **kwargs):
|
| 12 |
+
super().__init__(*args, **kwargs)
|
| 13 |
+
self.group_name = group_name
|
| 14 |
+
self.group_degree = group_degree
|
| 15 |
+
self.group_order = group_order
|
| 16 |
+
|
| 17 |
+
class PermutationGroups(datasets.GeneratorBasedBuilder):
|
| 18 |
+
VERSION = datasets.Version("1.0.0")
|
| 19 |
+
|
| 20 |
+
BUILDER_CONFIGS = [
|
| 21 |
+
PermutationGroupsConfig(
|
| 22 |
+
name="s3_data",
|
| 23 |
+
description="Permutation Composition Dataset for the Symmetric Group S3.",
|
| 24 |
+
group_name="S3",
|
| 25 |
+
group_degree=3,
|
| 26 |
+
group_order=6,
|
| 27 |
+
),
|
| 28 |
+
PermutationGroupsConfig(
|
| 29 |
+
name="s4_data",
|
| 30 |
+
description="Permutation Composition Dataset for the Symmetric Group S4.",
|
| 31 |
+
group_name="S4",
|
| 32 |
+
group_degree=4,
|
| 33 |
+
group_order=24,
|
| 34 |
+
),
|
| 35 |
+
PermutationGroupsConfig(
|
| 36 |
+
name="s5_data",
|
| 37 |
+
description="Permutation Composition Dataset for the Symmetric Group S5.",
|
| 38 |
+
group_name="S5",
|
| 39 |
+
group_degree=5,
|
| 40 |
+
group_order=120,
|
| 41 |
+
),
|
| 42 |
+
PermutationGroupsConfig(
|
| 43 |
+
name="s6_data",
|
| 44 |
+
description="Permutation Composition Dataset for the Symmetric Group S6.",
|
| 45 |
+
group_name="S6",
|
| 46 |
+
group_degree=6,
|
| 47 |
+
group_order=720,
|
| 48 |
+
),
|
| 49 |
+
PermutationGroupsConfig(
|
| 50 |
+
name="s7_data",
|
| 51 |
+
description="Permutation Composition Dataset for the Symmetric Group S7.",
|
| 52 |
+
group_name="S7",
|
| 53 |
+
group_degree=7,
|
| 54 |
+
group_order=5040,
|
| 55 |
+
),
|
| 56 |
+
PermutationGroupsConfig(
|
| 57 |
+
name="a5_data",
|
| 58 |
+
description="Permutation Composition Dataset for the Alternating Group A5.",
|
| 59 |
+
group_name="A5",
|
| 60 |
+
group_degree=5,
|
| 61 |
+
group_order=60,
|
| 62 |
+
),
|
| 63 |
+
PermutationGroupsConfig(
|
| 64 |
+
name="a6_data",
|
| 65 |
+
description="Permutation Composition Dataset for the Alternating Group A6.",
|
| 66 |
+
group_name="A6",
|
| 67 |
+
group_degree=6,
|
| 68 |
+
group_order=360,
|
| 69 |
+
),
|
| 70 |
+
PermutationGroupsConfig(
|
| 71 |
+
name="a7_data",
|
| 72 |
+
description="Permutation Composition Dataset for the Alternating Group A7.",
|
| 73 |
+
group_name="A7",
|
| 74 |
+
group_degree=7,
|
| 75 |
+
group_order=2520,
|
| 76 |
+
),
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
DEFAULT_CONFIG_NAME = "s5_data"
|
| 80 |
+
|
| 81 |
+
def _info(self):
|
| 82 |
+
return datasets.DatasetInfo(
|
| 83 |
+
description=_DESCRIPTION,
|
| 84 |
+
features=datasets.Features({
|
| 85 |
+
"input_sequence": datasets.Value("string"),
|
| 86 |
+
"target": datasets.Value("string"),
|
| 87 |
+
}),
|
| 88 |
+
homepage=_HOMEPAGE,
|
| 89 |
+
license=_LICENSE,
|
| 90 |
+
# Add custom metadata to info.metadata
|
| 91 |
+
metadata=datasets.MetadataDict({
|
| 92 |
+
"group_name": self.config.group_name,
|
| 93 |
+
"group_degree": self.config.group_degree,
|
| 94 |
+
"group_order": self.config.group_order,
|
| 95 |
+
}),
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
def _split_generators(self, dl_manager):
|
| 99 |
+
# The data files are already uploaded to the repo in data/<config_name>/
|
| 100 |
+
# We need to provide the paths relative to the dataset script
|
| 101 |
+
data_dir = f"data/{self.config.name}"
|
| 102 |
+
|
| 103 |
+
return [
|
| 104 |
+
datasets.SplitGenerator(
|
| 105 |
+
name=datasets.Split.TRAIN,
|
| 106 |
+
gen_kwargs={
|
| 107 |
+
"filepath": os.path.join(data_dir, "train", "data-*.arrow"),
|
| 108 |
+
"split": "train",
|
| 109 |
+
},
|
| 110 |
+
),
|
| 111 |
+
datasets.SplitGenerator(
|
| 112 |
+
name=datasets.Split.TEST,
|
| 113 |
+
gen_kwargs={
|
| 114 |
+
"filepath": os.path.join(data_dir, "test", "data-*.arrow"),
|
| 115 |
+
"split": "test",
|
| 116 |
+
},
|
| 117 |
+
),
|
| 118 |
+
]
|
| 119 |
+
|
| 120 |
+
def _generate_examples(self, filepath, split):
|
| 121 |
+
# Load the Arrow files directly
|
| 122 |
+
for i, file in enumerate(dl_manager.iter_files(filepath)):
|
| 123 |
+
# Assuming each .arrow file contains a table that can be converted to a list of dicts
|
| 124 |
+
# For simplicity, we'll load it as a Dataset and iterate
|
| 125 |
+
dataset = datasets.Dataset.from_file(file)
|
| 126 |
+
for id_, row in enumerate(dataset):
|
| 127 |
+
yield f"{split}_{i}_{id_}", {
|
| 128 |
+
"input_sequence": row["input_sequence"],
|
| 129 |
+
"target": row["target"],
|
| 130 |
+
}
|