This guide shows you how to get training data from the internet or create your own data.txt file.
# Download Shakespeare text (recommended for testing)
python download_data.py --type shakespeare
# Create a sample data file
python download_data.py --type sample --output data/my_data.txt --samples 200
# Download Wikipedia article (requires: pip install wikipedia)
python download_data.py --type wikipedia --title "Artificial Intelligence" --output data/ai_article.txtShakespeare Dataset:
python download_data.py --type shakespeareDownloads classic Shakespeare text - great for testing!
Create Sample Data:
python download_data.py --type sample --output data/my_data.txt --samples 100Creates a file with sample sentences about ML/AI.
Wikipedia Article:
python download_data.py --type wikipedia --title "Machine Learning" --output data/ml_article.txtDownloads a Wikipedia article (requires pip install wikipedia).
- Create a text file:
nano data/my_data.txt
# or
vim data/my_data.txt- Add your text (one sentence per line):
This is my first training sample.
This is my second training sample.
Add as many lines as you want.
- Save and use:
python train.py --data data/my_data.txtShakespeare Text:
curl -o data/shakespeare.txt https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txtBook Corpus Sample:
# Download Project Gutenberg books
curl -o data/book.txt https://www.gutenberg.org/files/1342/1342-0.txt # Pride and PrejudiceNews Articles:
# Download news text
curl -o data/news.txt https://raw.githubusercontent.com/sunnysai12345/News_Summary/master/news_summary_more.csvFrom Wikipedia (Python):
import wikipedia
page = wikipedia.page("Machine Learning")
with open("data/ml_article.txt", "w") as f:
f.write(page.content)From a Website:
import requests
from bs4 import BeautifulSoup
url = "https://example.com/article"
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
text = soup.get_text()
with open("data/scraped.txt", "w") as f:
f.write(text)WikiText-2:
# Download WikiText-2
wget https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-v1.zip
unzip wikitext-2-v1.zip
# Use: wikitext-2/wiki.train.tokensOpenWebText Sample:
# Download sample
curl -o data/openwebtext_sample.txt https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txtBookCorpus:
# Various book sources available
# Check: https://github.com/soskek/bookcorpusYour data.txt file should:
- Have one text sample per line
- Use UTF-8 encoding
- Be plain text (no special formatting)
Example format:
This is the first training example.
This is the second training example.
Each line becomes one training sample.
Good:
Hello world!
This is a sentence.
Machine learning is cool.
Bad:
This is paragraph 1 with multiple sentences. This is sentence 2.
This is paragraph 2.
- Clean your data:
import re
with open("raw_data.txt", "r") as f:
text = f.read()
# Remove extra whitespace
text = re.sub(r'\s+', ' ', text)
# Split into sentences
sentences = text.split('.')
# Write one per line
with open("data/cleaned_data.txt", "w") as f:
for sentence in sentences:
if sentence.strip():
f.write(sentence.strip() + '\n')- Split long texts:
# If you have long texts, split them into sentences
text = "Long paragraph here. Another sentence. More text."
sentences = text.split('.')
for sentence in sentences:
if sentence.strip():
print(sentence.strip())- Create a small test file:
cat > data/test.txt << EOF
Hello world!
This is a test.
Language models are cool.
EOF- Train with it:
python train.py --data data/test.txt --output ./checkpoints- Small (for testing): Shakespeare text, sample_data.txt
- Medium (for training): Wikipedia articles, news articles
- Large (for serious training): WikiText-2, BookCorpus, OpenWebText
Once you have your data.txt file:
# Train your model
python train.py --data data/your_data.txt --output ./checkpoints
# Or use the sample data
python train.py --data data/sample_data.txt --output ./checkpointsHappy training! 🚀