dolma

repository·main·Indexed 23 days ago

https://github.com/allenai/dolma

A high-performance toolkit for curating large-scale datasets for language model pre-training, providing a 3-trillion-token open dataset. It includes pipelines for C4-like processing (reformat, tag, and mix), decontamination using Bloom filters, and specialized tools for code data such as code-file-concat and Fill-In-Middle (FIM) reordering.

Tokens
26.7K
Snippets
47
Records
113
Agent score
80%

What's inside dolma

  1. Overview of the Dolma Toolkit

    main

    The Dolma Toolkit is a high-performance library for curating large-scale datasets for machine learning. Key capabilities include:

    • High Performance: Built-in parallelism allows for concurrent processing of billions of documents.
    • Portability: Can be deployed on single machines, clusters, or cloud environments.
    • Built-In Taggers: Includes ready-to-use taggers used in datasets like Gopher, C4, and OpenWebText.
    • Fast Deduplication: Uses a Rust-based Bloom filter for efficient document deduplication.
    • Extensibility & Cloud Support: Supports custom taggers and AWS S3-compatible storage locations.
  2. Access the Dolma Dataset

    main

    The Dolma Dataset is an open 3-trillion-token corpus consisting of web content, academic publications, code, books, and encyclopedic materials. It is licensed under ODC-BY.

    You can download the dataset from the HuggingFace 🤗 Hub at: huggingface.co/datasets/allenai/dolma

  3. What is Fill-In-Middle (FIM)?

    main

    Fill-In-Middle (FIM) is a standalone script used to produce reordered code text. This reordering is designed for training code completion models to predict code that exists between a given prefix and suffix.

    An original code block is rearranged into a format using special sentinel tokens to demarcate the subsections:

    <|fim_prefix|> [prefix] <|fim_suffix|> [suffix] <|fim_middle|> [middle]

  4. Understand Reddit dataset architectures

    main

    The Reddit source data in Dolma is organized into three primary architectural patterns, depending on how conversational threads and submissions are structured:

    • comment threads: Assembles comments into multi-round dialogues (snippets of complete threads) up to a maximum parent depth. Submissions remain unconnected.
    • atomic content: The simplest format where comments and submissions are treated as individual, complete documents without hierarchical assembly.
    • complete threads: The most structured format. It combines a submission and its entire comment thread into a single document, using code-like indentation to represent the hierarchical position of each comment.
  5. Supported input file formats for fill-in-middle

    main

    The fill-in-middle tool supports the following input formats:

    • JSONL: Standard newline-delimited JSON files where each line contains a "text" key.
    • Zstandard Compressed JSONL: Files with the .zst extension or ending in .jsonl.zst are automatically decompressed during processing.
    • Glob Patterns: Input paths can include wildcards like *, ?, or [] to match multiple files.
  6. Configure document-level vs paragraph-level deduplication

    main

    Deduplication in Dolma can be performed at two distinct levels. You must choose one approach, as the parameters for them are mutually exclusive:

    1. Document-level Deduplication

    Used to identify if an entire document is a duplicate based on a specific key (e.g., a URL).

    • dedupe.documents.key: A JSON-path string pointing to the field used as the unique key. The value must be a string.
    • dedupe.documents.attribute_name: The name of the attribute to be set on documents identified as duplicates.

    2. Paragraph-level Deduplication

    Used to identify duplicate spans within a document. Paragraphs are defined by splitting the text field by newline characters.

    • dedupe.paragraphs.attribute_name: The name of the attribute that will contain the spans of duplicate paragraphs.
    • dedupe.paragraphs.by_ngram.ngram_length: (Optional) If set, segments paragraphs into Unicode words and checks ngrams. The attribute will report the fraction of matched ngrams.
    • dedupe.paragraphs.by_ngram.stride: (Optional) The step size when computing ngrams.
    • dedupe.paragraphs.by_ngram.threshold: (Optional) The fraction of matched ngrams required to consider a paragraph a duplicate (default is 1.0).
  7. Use span replacement to substitute text

    main

    The span_replacement parameter allows you to replace specific text spans within documents. Each object in the list defines:

    • span: A json-path expression pointing to an attribute containing an array of spans. Each span must be a list of three values: [start, end, score].
    • min_score (Optional): The minimum score required for a span to be replaced.
    • replacement: The text to insert.
      • Use {} to represent the original text.
      • Use a $ prefix followed by a jq selector to select a field from the document (e.g., $[field_name]).
      • Note: Escape a leading $ if you do not want to use a jq selector pattern.
  8. Understand the Dolma dataset curation workflow

    main

    Dataset curation with Dolma typically follows a four-step pipeline:

    1. Taggers: Spans of documents are tagged with properties such as language, toxicity, or perplexity scores.
    2. Deduplication: Documents are optionally removed based on content or metadata (utilizing a fast Rust-based Bloom filter).
    3. Mixer: Documents are filtered or selected based on the values of their attributes.
    4. Tokenization: Documents are tokenized using any HuggingFace-compatible tokenizer.
  9. Configure the Bloom filter size and behavior

    main

    The Bloom filter's performance and accuracy depend on its configuration. You must provide a file path for the filter and define its size using one of the following mutually exclusive methods:

    Size Configuration

    Choose one of these three ways to set the filter size:

    1. Fixed Size: Set bloom_filter.size_in_bytes.
    2. Estimated Count: Set bloom_filter.estimated_doc_count AND bloom_filter.desired_false_positive_rate.

    Operational Modes

    • bloom_filter.file (Required): The path to save the Bloom filter. If the file exists at startup, it will be loaded.
    • bloom_filter.read_only: If true, the filter will not be written to. Use this for deduping against a precomputed list (like blocked URLs) or for decontamination against test data.
  10. Filter documents in Dolma Mixer

    main

    You can perform content-based filtering on documents within a stream using include and exclude patterns.

    Logic: A document is retained if it matches any of the include patterns (or if no include patterns are specified) AND matches none of the exclude patterns.

    Syntax: Patterns use jsonpath syntax.

  11. Understand the tokenization output format

    main

    The tokenization library produces two files for every output destination:

    1. A .npy file: Contains the concatenated tokenized documents as a numpy memmap.
    2. A .csv.gz file: Contains the metadata for each tokenized document.

    The metadata CSV includes the following columns:

    • start (int): The 0-indexed start position of the document/chunk in the .npy file.
    • end (int): The 0-indexed exclusive end position of the document/chunk in the .npy file.
    • id (str): The unique identifier of the original document.
    • src (str): The source file path of the original document.
    • loc (int): The 1-indexed line number/location of the document in the original source file.
  12. How to implement a custom Parallel Processor

    main

    Many Dolma toolkit functions use dolma.core.parallel.BaseParallelProcessor to parallelize tasks over a list of inputs while tracking progress via progress bars. To create a custom processor, you must subclass BaseParallelProcessor and implement two specific class methods:

    1. process_single(cls, source_path, destination_path, queue, **kwargs): This method contains the core logic. It is called for each individual input file. You are responsible for opening the source_path, processing the data, and writing the results to destination_path. During processing, you should periodically call increment_progressbar to update the status.
    2. increment_progressbar(cls, queue, /, ...): This method updates the progress bars. Any arguments provided after the / separator in the signature define the metrics tracked by the progress bars. You must call super().increment_progressbar(...) within this method, passing the same arguments to ensure the base class updates the shared queue correctly.
    from dolma.core.parallel import BaseParallelProcessor
    from queue import Queue
    
    
    class CustomParallelProcessor(BaseParallelProcessor):
        @classmethod
        def increment_progressbar(
            cls,
            queue: Queue,
            /,
            files: int = 0,
            documents: int = 0,
            ...
        ):
            """
            This method is called in the process_single
            to increment the progress bar. You can create as many progress bars as are
            the numbers of arguments after the '/' separator.
            """
            super().increment_progressbar(
                queue,
                files=files,
                documents=documents,
                ...
            )
    
        @classmethod
        def process_single(
            cls,
            source_path: str,
            destination_path: str,
            queue: Queue,
            **kwargs: Any,
        ):
            """
            This method is to process a single input file.
            The method broadly opens source_path file, processes it and writes the output to
            destination_path.
            """
            ...