Datasets:

Modalities:
Image
Text
Formats:
parquet
Languages:
Danish
ArXiv:
DOI:
Libraries:
Datasets
Dask
License:
File size: 1,120 Bytes
566156e
a5ac9e2
566156e
 
 
 
 
 
 
 
 
 
 
a5ac9e2
566156e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a5ac9e2
566156e
 
a5ac9e2
566156e
 
 
 
 
 
 
a5ac9e2
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
import logging
from pathlib import Path

import pandas as pd
import plotnine as pn
from datasets import Dataset

logger = logging.getLogger(__name__)


def create_descriptive_statistics_plots(
    dataset: Dataset,
    save_dir: Path,
) -> tuple[Path, pn.ggplot]:
    logger.info("creating descriptive statistics plot to readme.")
    lengths = dataset["token_count"]
    df = pd.DataFrame({"lengths": lengths, "Source": dataset["source"]})

    plot = (
        pn.ggplot(df, pn.aes(x="lengths", y=pn.after_stat("count")))
        + pn.geom_histogram(bins=100)
        + pn.labs(
            x="Document Length (Tokens)",
            y="Count",
            title="Distribution of Document Lengths",
        )
        + pn.theme_minimal()
        + pn.facet_wrap("Source", scales="free", ncol=3)
    )

    img_path = save_dir / "images"
    img_path.mkdir(parents=False, exist_ok=True)
    save_path = img_path / "dist_document_length.png"
    pn.ggsave(
        plot,
        save_path,
        dpi=500,
        width=10,
        height=10,
        units="in",
        verbose=False,
    )

    return save_path, plot