Web pages share boilerplate: navigation menus, cookie banners, footers. Document-level de-duplication cannot remove it, because the pages differ elsewhere. Llama 3's pipeline adds aggressive line-level de-duplication: split the corpus into buckets of documents and, within each bucket, remove every line that appears more than 6 times. Implement it.
dedup_lines(docs, bucket_size, max_count=6)
docs is a list of documents, each a string of lines separated by "\n".docs into consecutive buckets of bucket_size documents (the last bucket may be smaller).max_count."\n".(cleaned_docs, removed): the list of cleaned documents (a document may become empty but stays in the list) and the total number of lines removed.collections.Counter per bucket is enough.