Group-Theory-Collection / permutation-groups.py
BeeGass's picture
Upload permutation-groups.py with huggingface_hub
5771c9a verified
raw
history blame
4.54 kB
import datasets
import json
import os
from sympy.combinatorics import Permutation
from sympy.combinatorics.named_groups import AlternatingGroup, SymmetricGroup
_DESCRIPTION = "A collection of permutation composition datasets for various symmetric and alternating groups."
_HOMEPAGE = "https://huggingface.co/datasets/BeeGass/permutation-groups"
_LICENSE = "MIT"
class PermutationGroupsConfig(datasets.BuilderConfig):
def __init__(self, *args, group_name=None, group_degree=None, group_order=None, **kwargs):
super().__init__(*args, **kwargs)
self.group_name = group_name
self.group_degree = group_degree
self.group_order = group_order
class PermutationGroups(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
PermutationGroupsConfig(
name="s3_data",
description="Permutation Composition Dataset for the Symmetric Group S3.",
group_name="S3",
group_degree=3,
group_order=6,
),
PermutationGroupsConfig(
name="s4_data",
description="Permutation Composition Dataset for the Symmetric Group S4.",
group_name="S4",
group_degree=4,
group_order=24,
),
PermutationGroupsConfig(
name="s5_data",
description="Permutation Composition Dataset for the Symmetric Group S5.",
group_name="S5",
group_degree=5,
group_order=120,
),
PermutationGroupsConfig(
name="s6_data",
description="Permutation Composition Dataset for the Symmetric Group S6.",
group_name="S6",
group_degree=6,
group_order=720,
),
PermutationGroupsConfig(
name="s7_data",
description="Permutation Composition Dataset for the Symmetric Group S7.",
group_name="S7",
group_degree=7,
group_order=5040,
),
PermutationGroupsConfig(
name="a5_data",
description="Permutation Composition Dataset for the Alternating Group A5.",
group_name="A5",
group_degree=5,
group_order=60,
),
PermutationGroupsConfig(
name="a6_data",
description="Permutation Composition Dataset for the Alternating Group A6.",
group_name="A6",
group_degree=6,
group_order=360,
),
PermutationGroupsConfig(
name="a7_data",
description="Permutation Composition Dataset for the Alternating Group A7.",
group_name="A7",
group_degree=7,
group_order=2520,
),
]
DEFAULT_CONFIG_NAME = "s5_data"
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({
"input_sequence": datasets.Value("string"),
"target": datasets.Value("string"),
}),
homepage=_HOMEPAGE,
license=_LICENSE,
)
def _split_generators(self, dl_manager):
# The data files are already uploaded to the repo in data/<config_name>/
# We need to provide the paths relative to the dataset script
data_dir = f"data/{self.config.name}"
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": os.path.join(data_dir, "train", "data-*.arrow"),
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"filepath": os.path.join(data_dir, "test", "data-*.arrow"),
"split": "test",
},
),
]
def _generate_examples(self, filepath, split):
# Load the Arrow files directly
for i, file in enumerate(dl_manager.iter_files(filepath)):
# Assuming each .arrow file contains a table that can be converted to a list of dicts
# For simplicity, we'll load it as a Dataset and iterate
dataset = datasets.Dataset.from_file(file)
for id_, row in enumerate(dataset):
yield f"{split}_{i}_{id_}", {
"input_sequence": row["input_sequence"],
"target": row["target"],
}