dataset_info:
- config_name: Raw_Java
features:
- name: file_name
dtype: string
- name: file_path
dtype: string
- name: content
dtype: string
- name: file_size
dtype: int64
- name: language
dtype: string
- name: extension
dtype: string
- name: repo_name
dtype: string
- name: repo_stars
dtype: int64
- name: repo_forks
dtype: int64
- name: repo_open_issues
dtype: int64
- name: repo_created_at
dtype: string
- name: repo_pushed_at
dtype: string
splits:
- name: train
num_bytes: 59165182788
num_examples: 7798053
download_size: 15597123595
dataset_size: 59165182788
- config_name: Stackless_Java_V2
features:
- name: file_name
dtype: string
- name: file_path
dtype: string
- name: content
dtype: string
- name: file_size
dtype: int64
- name: language
dtype: string
- name: extension
dtype: string
- name: repo_name
dtype: string
- name: repo_stars
dtype: int64
- name: repo_forks
dtype: int64
- name: repo_open_issues
dtype: int64
- name: repo_created_at
dtype: string
- name: repo_pushed_at
dtype: string
- name: sha
dtype: string
- name: near_dups_stkv2_idx
sequence: int64
splits:
- name: train
num_bytes: 41264087796
num_examples: 2130615
download_size: 20953239433
dataset_size: 41264087796
configs:
- config_name: Raw_Java
data_files:
- split: train
path: data/Raw_Java/train-*
- config_name: Stackless_Java_V2
data_files:
- split: train
path: data/Stackless_Java_V2/train-*
Dataset Summary
We create a new Java dataset by scraping public repositories on GitHub. Our file-level dataset includes individual Java files rather than entire projects or code snippets such as functions or class definitions. Our approach combines techniques used in creating the Stack dataset family, which served as the training foundation for the StarCoder models. We specifically focus on the Stack v2 for its latest release and public availability. Our dataset creation pipeline involves three key stages: collection, cleaning, and deduplication.
Collection
We start the collection process by scraping 10500 public repositories using the GitHub API. We specifically look for repositories released under a strong copyleft license such as GPL-2.0, GPL-3.0, or AGPL-3.0. We use copyleft licenses to ensure our dataset is not contaminated with training data from Stack v2. This issue occurred with other publicly available file-level code datasets, including Stack v1, which claimed to contain only permissively licensed code, however, they were contaminated with copyleft-licensed code. Stack v2 also claims to exclude copyleft-licensed code due to community stance uncertainty and its low volume. Nevertheless, we still deduplicated our dataset against Stack v2 to ensure there was no overlap and that our data was safe for training. We extract repositories created between 2001 and April 2024 in decreasing order of their star counts. To avoid GitHub rate limits, we use timeouts and pagination to fetch the repositories. The search is based on the repository license type, star count, and creation date.
The features we extract for each repository are illustrated in the example below.
{
"id": 126178683,
"full_name": "halo-dev/halo",
"html_url": "https://github.com/halo-dev/halo",
"stargazers_count": 29115,
"forks_count": 8985,
"watchers_count": 29115,
"open_issues_count": 278,
"language": "Java",
"created_at": "2018-03-21T12:56:52Z",
"pushed_at": "2023-10-28T16:29:39Z",
"license": {
"key": "gpl-3.0",
"name": "GNU General Public License v3.0",
"spdx_id": "GPL-3.0",
"url": "https://api.github.com/licenses/gpl-3.0",
"node_id": "MDc6TGljZW5zZTk="
},
"retrieval_date": "10/30/2023, 3:24:57 PM (Europe/Amsterdam)"
}
Repository Fields
- id: unique id of the repo
- full_name: complete name of the repo
- html_url: URL to the repo
- stargazers_count: number of stars of the repo
- forks_count: number of forks of the repo
- watchers_count: number of watchers of the repo
- open_issues_count: number of open issues of the repo at the extraction time
- language: main language of the repo
- created_at: creation date of the repo
- pushed_at: date of the most recent push to the repo until the extraction date
- license: license type of the repo
- retrieval_date: date when the repo was scraped from GitHub
We start by retrieving repositories with more than 900 stars using two-month tumbling windows. If we hit the 1000 repository limit per window (for a personal GitHub account), we shorten the search space to a one-month window and restart the iteration. Otherwise, the window advances by two months. Once the 2001-2024 timeframe is covered, we reduce the star search space: between 900 and 100 stars, we decrease the interval by 50 (e.g. search between [900, 850]), between 100 and 10 stars, we decrease the interval by 10, and for the last 10 stars, we decrease by 1. Figure 1 showcases the distribution of repositories with up to 500 stars. Since most repositories fall within the 0-100 star range, using the creation date and star count filters helps us avoid API limits and scrape more data by narrowing the search space. Although the creation date window can be reduced even further (week or day level), a one-month window was enough for our needs. After retrieving the repositories, we extract all the files with a .java extension.
The final dataset structure is shown in the example below.
{
"file_name": "Font.java",
"file_path": ".../lateralgm/resources/Font.java",
"content": "*/ package org.lateralgm.resources; import java.util.EnumMap; import org.lateralgm.main.Prefs; ...",
"file_size": 1,985,
"language": "Java",
"extension": ".java",
"repo_name": "lwizchz/GameMaker-HTML5-Player",
"repo_stars": 22,
"repo_forks": 9,
"repo_open_issues": 0,
"repo_created_at": "2011-09-10T16:05:20Z",
"repo_pushed_at": "2013-05-06T23:00:17Z",
"sha": "00046809b218b2c058f4be7...",
"near_dups_stkv2_idx": [21192944, 106219595]
}
Dataset Fields
- file_name: name of the file extracted from its repo
- file_path: path to the file in its repo
- content: content of the file
- file_size: size of the file
- language: language of the file
- extension: language extension of the file
- repo_name: complete name of the file's repo
- repo_stars: number of stars of the file's repo
- repo_forks: number of forks of the file's repo
- repo_open_issues: number of open issues of the file's repo at the extraction date
- repo_created_at: creation date of the file's repo
- repo_pushed_at: date of the most recent push to the file's repo until the extraction date
- sha: sha value of the file's content
- near_dups_stkv2_idx: IDs of files from Java-Stack v2 that are near-duplicates to the current file
Figure 1: Distribution of scraped repositories with at most 500 stars.
Cleaning
The next stage in our dataset pipeline is the cleaning procedure. We exclude Java files larger than 50 MB and those with fewer than 10 words. We also remove auto-generated files by searching for specific keywords in the first 5 lines of each file. If any of these keywords occur, the file is considered auto-generated and removed:
- generated by
- autogenerated
- auto-generated
- this file was generated
- this file is generated
- generated automatically
- automatically generated
These keywords were derived from the Stack v2 approach and manual file inspection.
Deduplication
The final stage of our dataset pipeline is the deduplication process. Firstly, we remove any potential duplicated repositories obtained due to the pagination process. We then perform exact deduplication between our dataset and the Java-Stack v2, and within our dataset itself, using the sha256 function to generate hashes for each file. We choose this hash function because it provides a uniform distribution of hash values, minimizes collisions, and ensures even distribution across the hash space. For near-deduplication, we use the MinHashLSH algorithm from the datasketch1 library. To calculate the minhashes, we use the same hash function as above, but we extract the first 16 bytes to generate 128-bit hash values. This approach balances the need for a strong hash function with the efficiency of a shorter hash length.
Additionally, we use 128 file permutations for LSH, with weights of 0.4 for precision and 0.6 for recall. We generate 7-character shingles after lowercasing the file content and removing whitespace. We find that 7-shingles provide a reasonable trade-off between the number of shingles and the data processed, being small enough to keep the number of unique shingles manageable yet large enough to provide meaningful comparisons. It was shown that the number of shingles should be large enough to ensure a low probability of shingles appearing across documents, with k = 5 suggested for smaller documents such as emails. However, Java files usually contain a larger dictionary of characters than emails, including arithmetic and comparison operators which are less frequent in emails. Thus, given the increased complexity and size of Java files, we consider 7-shingles to be appropriate to capture sufficient context, ensuring uniqueness and reducing false positives, which smaller shingles such as k = 5 might fail to achieve. Furthermore, k = 9 was shown to be a safe choice for large research articles, however, for our needs, 7-shingles strike a balance between accuracy and computational efficiency, crucial for handling the Java-Stack v2’s size of over 222 M files. This choice provides better computational efficiency by reducing the number of comparisons while maintaining a manageable shingle space. Lastly, we use a Jaccard similarity threshold of 0.7, which proved to be efficient for both SantaCoder and StarCoder models. Such a high threshold reduces false positives, leading to fewer unnecessary comparisons and lower computational overhead.
Instead of removing near-duplicates, we introduce a new feature to our dataset, called near_dups_stkv2_idx. This feature is a list of IDs of the near-duplicate files from the Java-Stack v2 corresponding to the current file in our dataset. The table below shows the number of files removed by each preprocessing method and the final number of files we are left with in the end (excluding near-duplicates). Starting with 7.8 M files, we are left with about 2.13 M after applying all pre-processing methods (this includes near-duplicates). Of the removed files, approximately 5.63 M are exact duplicates (including about 0.87 M from Java-Stack v2) and 0.8 M are near-duplicates from Java-Stack v2. This implies that training any LLM on Stack v2 will breach copy-left code licenses, despite the dataset creators’ claim that files under such licenses were removed.
Files removed by each pre-processing method
| Method | #Files |
|---|---|
| Raw dataset | 7.80 M |
| Auto-generated | 0.04 M |
| Exact-deduplication | 5.63 M |
| Near-deduplication | 0.80 M |
| Final dataset | 1.33 M |
Usage
By default, the dataset includes near-duplicate entries from Java-Stack v2, with their IDs listed in the near_dups_stkv2_idx field. An entry with an empty list in this field indicates that no near-duplicate files were found in Java-Stack v2 for that specific file.
Near-duplicates can be removed as shown in the example below.
from datasets import load_dataset
# Load dataset
dataset = load_dataset("LaughingLogits/Stackless_Java_V2")
# Load train split (only one split available)
dataset = load_dataset("LaughingLogits/Stackless_Java_V2", split="train")
# Dataset streaming
data = load_dataset("LaughingLogits/Stackless_Java_V2", split="train", streaming= True)
for sample in iter(data):
print(sample["content"])
# Filter dataset to not include near-duplicates from Java-Stack v2
dataset = load_dataset("LaughingLogits/Stackless_Java_V2", split="train")
near_deduplicated_dataset = dataset.filter(lambda sample: len(sample["near_dups_stkv2_idx"]) == 0)