omwdataset / main.py
victormiller's picture
Update main.py
b2b380b verified
raw
history blame
24.2 kB
from fasthtml.common import *
from fasthtml.components import *
from fasthtml.components import (
D_title,
D_article,
D_front_matter,
D_contents,
D_byline,
D_bibliography,
D_appendix,
D_cite,
)
from plotly import graph_objects as go
from fh_plotly import plotly2fasthtml
import pandas as pd
import json
from rich import print
import overview
import curated
import web
import common
import results
from pybtex.database import parse_file
app, rt = fast_app(
debug=True,
pico=False,
hdrs=(
Meta(charset="UTF-8"),
Meta(name="viewport", content="width=device-width, initial-scale=1.0"),
Script(src="https://distill.pub/template.v2.js"),
Script(src="https://unpkg.com/htmx.org@next/dist/htmx.min.js"),
Script(src="https://cdn.plot.ly/plotly-latest.min.js"),
Link(rel="stylesheet", href="style.css"),
MarkdownJS(),
),
)
front_matter = """
<d-front-matter>
<script id='distill-front-matter' type="text/json">{
"title": "",
"description": "",
"published": "",
"affiliation": {},
"authors": [
{
"author":"",
"authorURL":""
}
],
"katex": {
"delimiters": [
{"left": "$$", "right": "$$", "display": false}
]
}
}
</script>
</d-front-matter>
"""
def read_bibs():
bib_data = parse_file("bibliography.bib")
cits = []
for key in bib_data.entries.keys():
cits.append(D_cite(bibtex_key=key))
return cits
@app.get("/bibliography.bib")
def get():
return FileResponse("bibliography.bib")
@app.get("/")
def main():
return Div(
D_title(
H1(
"TxT360: the most comprehensive, highest quality, and production ready pretraining dataset",
cls="l-body",
style="text-align: center;",
),
Div(
Img(src="images/llm360_logo.png"),
id="title-plot",
cls="main-plot-container l-page",
),
),
Div(D_byline(), NotStr(front_matter), style="display: none;"),
D_article(
D_contents(
Nav(
H3("Table of Contents"),
Div(
A("TxT360", href="#_self"),
hx_get="/intro",
hx_target="#inner-text",
),
Div(
Ul(
Li(
A(
"About TxT360",
href="/intro#section1",
hx_get="/intro#section1",
hx_target="#inner-text",
)
),
Li(
A(
"Motivation Behind Txt360",
href="/intro#section2",
hx_get="/intro#section2",
hx_target="#inner-text",
)
),
Li(
A(
"Generalizable Approach to Data Processing",
href="/intro#section3",
hx_get="/intro#section3",
hx_target="#inner-text",
)
),
Li(
A(
"Introducing Global Deduplication",
href="/intro#section4",
hx_get="/intro#section4",
hx_target="#inner-text",
)
),
),
),
# Div(
# A("Overview", href="#inner-text"),
# hx_get="/overview",
# hx_target="#inner-text",
# ),
Div(
A("Global Processing Steps", href="#inner-text"),
hx_get="/common",
hx_target="#inner-text",
),
Div(
A("Web Data Processing", href="#inner-text"),
hx_get="/webdata",
hx_target="#inner-text",
),
Div(
A("Curated Sources Processing", href="#inner-text"),
hx_get="/curated",
hx_target="#inner-text",
),
Div(
A("TxT360 Results", href="#inner-text"),
hx_get="/results",
hx_target="#inner-text",
),
role="navigation",
cls="l-text figcaption",
),
),
intro(),
),
D_appendix(D_bibliography(src="bibliography.bib")),
Div(*read_bibs(), style="display: none;"),
)
intro_text = P(
"Pretraining performant large language models (LLMs) requires trillions of tokens of high quality data. Many prior work, including our previous pretraining projects ",
A("Amber-7B", href="https://huggingface.co/LLM360/Amber"),
", ",
A("Crystal-7B", href="https://huggingface.co/LLM360/CrystalCoder"),
", ",
A("K2-65B", href="https://huggingface.co/LLM360/K2"),
" have demonstrated how data curation is a ‘make-or-break’ decision for model quality and capability.",
)
intro_list = P(
"We present TxT360, the Trillion eXtracted Text corpus, a 5.7T token dataset for pretraining projects that:"
)
intro_list1 = Ol(
Li(
"Curates commonly used pretraining datasets, including all CommonCrawl",
style="margin-bottom: 5px",
),
Li(
"Employs carefully selected filters designed for each data source",
style="margin-bottom: 5px",
),
Li(
"Provides only unique data elements via globally deduplicated across all datasets",
style="margin-bottom: 5px",
),
Li(
"Retains all deduplication metadata for custom upweighting",
style="margin-bottom: 5px",
),
Li(
"Is Production ready! Download here [link to HF repo]",
style="margin-bottom: 5px",
),
)
dataset_comparison1 = pd.DataFrame(
{
"Dataset": [
"TxT360",
"FineWeb",
"RefinedWeb",
"RedPajama-v2",
"C4",
"Dolma",
"RedPajama-v1",
"The Pile",
],
"CommonCrawl": [
"99 Snapshots",
"96 Snapshots",
"90 Snapshots",
"84 Snapshots",
"1 Snapshots",
"24 Snapshots",
"5 Snapshots",
"0.6% of 74 Snapshots",
],
"Papers": [
"5 Sources",
"-",
"-",
"-",
"-",
"1 Source",
"1 Source",
"4 Sources",
],
"Wikipedia": [
"310+ Languages",
"-",
"-",
"-",
"-",
"what does a check mark mean?",
"what does a check mark mean?",
"English Only",
],
"FreeLaw": [
"Included",
"-",
"-",
"-",
"-",
"-",
"-",
"Included",
],
"DM Math": [
"Included",
"-",
"-",
"-",
"-",
"-",
"-",
"Included",
],
"USPTO": [
"Included",
"-",
"-",
"-",
"-",
"-",
"-",
"Included",
],
}
)
table_html = dataset_comparison1.to_html(index=False, border=0)
table_div_1 = Div(NotStr(table_html), style="margin: 40px;")
dataset_comparison2 = pd.DataFrame(
{
"Dataset": [
"TxT360",
"FineWeb",
"RefinedWeb",
"RedPajama-v2",
"C4",
"Dolma",
"RedPajama-v1",
"The Pile",
],
"PG-19": [
"Included",
"-",
"-",
"-",
"-",
"Included",
"Included",
"Included",
],
"HackerNews": [
"Included",
"-",
"-",
"-",
"-",
"-",
"-",
"Included",
],
"Ubuntu IRC": [
"Included",
"-",
"-",
"-",
"-",
"-",
"-",
"Included",
],
"EuroParl": [
"Included",
"-",
"-",
"-",
"-",
"-",
"-",
"Included",
],
"StackExchange": [
"Included",
"-",
"-",
"-",
"-",
"-",
"Included",
"Included",
],
"Code": [
"- what is this?",
"-",
"-",
"-",
"-",
"Included",
"Included",
"Included",
],
}
)
table_html2 = dataset_comparison2.to_html(index=False, border=0)
table_div_2 = Div(NotStr(table_html2), style="margin: 40px;")
dataset_sources = pd.DataFrame(
{
"Data Source": [
"CommonCrawl",
"Papers",
"Wikipedia",
"Freelaw",
"DM Math",
"USPTO",
"PG-19",
"HackerNews",
"Ubuntu IRC",
"Europarl",
"StackExchange",
],
"Raw Data Size": [
"11 TB",
"712 GB",
"210 GB",
"23 GB",
"22 GB",
"45 GB",
"11 GB",
"4.1 GB",
"4.7 GB",
"6.1 GB",
"45 GB",
],
"Token Count": [
"5.71T",
"154.96B",
"4.75B",
"7.34B",
"5.23B",
"4.95B",
"2.94B",
"1.08B",
"1.54B",
"1.96B",
"8.37B",
],
"Cut-Off Date": [
"2024-30",
"Q4 2023",
"-",
"Q1 2024",
"-",
"Q4 2023",
"-",
"Q4 2023",
"Q4 2023",
"-",
"Q4 2023",
],
}
)
table_html_data = dataset_sources.to_html(index=False, border=0)
table_div_data = Div(NotStr(table_html_data), style="margin: 40px;")
def get_curated_chart():
# Dataset
data = {
'Source': ['ArXiv', 'PubMed Central', 'PubMed Abstract', 'S2ORC Full Text', 'S2ORC Abstract', 'PhilPapers', 'Wikipedia', 'StackExchange', 'EuroParl', 'Ubuntu IRC', 'Freelaw', 'PG19', 'USPTO', 'HackerNews', 'DM Maths'],
'Category': ['Papers', 'Papers', 'Papers', 'Papers', 'Papers', 'Papers', 'Internet', 'Conversational', 'Legal/Formal', 'Conversational', 'Legal/Formal', 'Books', 'Legal/Formal', 'Conversational', 'Reasoning'],
'Count': [100, 200, 150, 120, 80, 90, 300, 250, 180, 150, 150, 250, 180, 120, 90],
'Details': [
'A repository of scientific papers in various disciplines, including computer science, physics, mathematics, and more.',
'A database of biomedical and life sciences research articles.',
'Abstracts of biomedical literature from various sources.',
'Full-text articles from the Semantic Scholar Open Research Corpus.',
'Abstracts of articles from the Semantic Scholar Open Research Corpus.',
'Papers from the PhilPapers database, a comprehensive index and bibliography of philosophy research.',
'A collaborative online encyclopedia that covers a wide range of topics.',
'A network of question-and-answer websites on various subjects, including programming, science, mathematics, and more.',
'A collection of multilingual parallel corpora of parliamentary debates from the European Parliament.',
'Chat logs from the Ubuntu Internet Relay Chat (IRC) channels.',
'Legal documents and court cases from various jurisdictions.',
'A collection of books from Project Gutenberg, a digital library of public domain works.',
'Patent documents from the United States Patent and Trademark Office.',
'User-generated news and discussion platform focused on technology and startups.',
'Deep Mind Maths dataset with generated questions.'
]
}
# Calculate percentage for each data source
total_count = sum(data['Count'])
data['Percentage'] = [count / total_count * 100 for count in data['Count']]
# Create treemap
fig = px.treemap(data, path=['Category', 'Source'], values='Count', hover_data=['Details', 'Percentage'], hover_name='Source')
# Set the size of the chart
fig.update_layout(width=800, height=600)
# Display treemap
st.plotly_chart(fig)
overview_div = Div(
Section(
H2("Overview"),
H3("What This Section Contains"),
Ul(
Li("Motivation Behind TxT360", style = "margin-bottom: 5px"),
Li("The Highlevel Data Process Approach", style = "margin-bottom: 5px"),
Li("Introduction to Global Deduplication", style = "margin-bottom: 5px"),
),
H2("Motivation Behind Txt360"),
H3("TxT360 is the first dataset to combine both web and curated data sources commonly used in pretraining."),
P("The quality and size of a pre-training dataset play a crucial role in the performance of large language models (LLMs). Data is often referred as low quality if it has not been filtered to review unwanted text. The community has introduced a variety of filtered datasets including purely web-based datasets."),
P("In pretraining, it is common to combine web data and curated sources (cite). Web data is included to provide a vast quantity of long tail and diverse data, while curated datasets are often information rich and provide the 'deep-dive' domain information. Both datasets play critical for effective LLM pre-training."),
H4("The Gap TxT360 Fills"),
P("Despite advancements in filtering and source material for both data types, each type of dataset has its limitations. RefinedWeb is known for its high quality content but and only about 10% of the entire dataset has been disclosed and the processing scripts have not been released. For datasets that have combined curated sources with web data, the web component is relatively small (NEED TO UPDATE - citation needed)."),
P("By integrating the extensive reach of web data with the exceptional quality of curated sources, TxT360 meets and surpasess the rigorous standards required for state-of-the-art LLM pre-training as demostated in the Results section."),
P("Table 1: The following table shows TxT360 and other well-known datasets on the coverage and size of data sources."),
table_div_1,
table_div_2,
P("Table 2: Basic TxT360 Statistics."),
table_div_data,
),
Section(
H2("Our Generalizable Approach to Data Processing"),
P("To produce TxT360, a comprehensive and transparent data processing pipeline was designed to account for the nuances of both web and curated datasets. The pipeline presents a unified framework for processing both data types, making it convenient and easily adaptive for users to revise and fine-tune the pipeline for their own use cases."),
P("Web datasets are inherently noisy and varied. Thus, the pipeline includes sophisticated filtering and deduplication techniques to clean the data and remove redundancies or irrelevant information."),
P("Curated datasets are typically already structured and consistently formatted. TxT360 filters these sources with selective steps to maintain their integrity while providing seamless integration into the larger dataset."),
P("We will open-source the scripts for the whole pipeline, allowing the community to review, replicate, and build upon our processes."),
Img(src="images/pipeline.png", height = "300", width = "600" ),
P("Figure 1: Data processing pipeline. All the steps are adopted for processing web data while the yellow blocks are adopted for processing curated sources."),
),
Section(
H2("Introducing Global Deduplication"),
P("Deduplication is crucial in language model pre-training for several reasons (NEEDS CITATION). Main hypothesis on why deduplicaiton is necessary and help include:"),
Ul(
Li("reducing data volume reduces training time (and cost)", style = "margin-bottom: 5px"),
Li("removing duplicataive data can lead to better accuracy", style = "margin-bottom: 5px"),
Li("prevent train-test overlap", style = "margin-bottom: 5px"),
Li("minimizes the risk of memorization leading to test loss", style = "margin-bottom: 5px"),
),
P("Furthermore, by controlling the pretraining data distribution through deduplication and selective upsampling avoida relying on the often inconsistent distribution of internet-sourced data."),
H3("Highlights of the TxT360 Deduplication Process"),
P("Our deduplication process began with 61.8 TB of filtered, and compressed documents, totaling approximately 48.83 billion documents. We first performed exact deduplication using a Bloom filter, reducing the dataset by 17% to 40.21 billion documents. For global near-deduplication, we scaled methodologies from prior works like SlimPajama to handle the entire dataset, including 87 Common Crawl dumps and other curated data. This involved generating document signatures, matching them to identify near-duplicates, and clustering these to retain only one document per cluster. We prioritized retaining documents from curated sources and more recent CommonCrawl dumps. Throughout the deduplication stages, we extensively used Dask for distributed data processing."),
P("After the global near-deduplication of all 87 CommonCrawl dumps and other curated data, we removed around 85% of the total documents. This leaves us with approximately 4.24 trillion deduplicated tokens, which aligns with what FineWeb has reported for their iterative global deduplication. Along with the list of duplicated documents to delete, our deduplication code also saves some metadata about the duplicate clusters that we find. We save statistics about every duplicate cluster we find, with the document ID of the document we retain from the cluster as the key and with a value capturing the distribution of the duplicates within the cluster over the CommonCrawl dumps (identified by the first 2 digits of every document ID). This way, we always have information about the duplicates we have deleted, allowing us to upsample any data distribution we want for training."),
P("During deduplication, it is not feasible to store all the duplicate clusters we form, but we do save some samples at every size. Here are some observations we made by examining these sample duplicate clusters:"),
Ul(
Li("Smaller components tend to have more overlap in their MinHash bands. The smallest components, which are essentially pairs, consist of exact duplicate documents that local exact deduplication missed."),
Li("When clusters contain three or more documents, incremental changes in the text become apparent. For example, there may be a growing list of personnel over the years."),
Li("In sizable clusters comprising 1,000 or more documents, we observe a trend towards templatization. This involves the recurrent use of standardized language to convey general topics such as terms and conditions, warnings, and disclaimers. Such language is prevalent on commercial websites, offering a consistent and efficient way to communicate commonly encountered information."),
),
P("All Deduplication details can be found in the Global Data Processing Steps section."),
),
)
@app.get("/intro")
def intro():
return Div(
Section(
H2("About TxT360"),
P("We introduce Trillion eXtracted Text (TxT360): the highest quality, most comprehensive, and production ready pretraining dataset released to date, an open source pre training textual dataset with the widest coverage to date, including all 99 Common Crawl snapshots released to date and 14 widely used curated sources such as Wikipedia, StackExchange, and ArXiv."),
P("Building on top of the prior study on pre-training data, (cite C4, chinchilla, fineweb, refinedweb, 2305.16264, ) TxT360 carefully implements data processing steps such as extraction, filtering, deduplication, PII removal and so on. Notably, we design a schema to provide users with full control on the weights of each data point, instead of relying on unknown distribution from the raw dataset. Specifically, we strive to make each data point appear only once, via global deduplication across the whole corpus. Importantly, we store enough metadata to recover the raw distribution, and additionally allow one to have fine-grained control to create data distributions and corpus of desired size. As an example, we present one simple upsampling scheme that takes into account the duplication counts, resulting in a 15~16 trillion token corpus, outperforming FineWeb and our non-upsampling baselines, on diverse evaluations. Unlike DCLM and RedPajama V2, we present the final deduplicated dataset that is ready to go."),
P("We have carefully implemented a large set of filters by carefully reviewing the input, output from data samples and tailored design for each data source. We learned from and compared our implementation with prior data pipelines, such as Chinchilla, C4, DataTrove, Dolma, and RedPajama Data V2 to make carefully considered decisions."),
P("In light of the 360 open source spirit, we will open source the code and document all the implementation details in this blog post, along with the examples and why each decision is made, hoping to shed some light on this important but tedious step."),
id="section1",
),
overview_div,
id="inner-text",
)
#rt("/overview")(overview.overview)
rt("/curated")(curated.curated)
rt("/curated/{target}")(curated.update)
rt("/webdata")(web.web_data)
rt("/webdata/{target}")(web.update)
rt("/common")(common.common_steps)
rt("/results")(results.results)
serve()