LargeCorpusSpaCy / README.md
SPOOKEXE's picture
model-card
648963d verified
|
Raw History Blame Contribute Delete
4.94 kB
---
license: mit
task_categories:
- text-classification
- text-generation
language:
- en
size_categories:
- 10K<n<100K
---
# UKS Seed Dataset Generator
Generates preprocessed training data for the UKS Energy System from the FineWeb dataset.
## Overview
This pipeline processes text from HuggingFace's FineWeb dataset and produces two output formats:
1. **pre_tokenized.jsonl.gz**: Ready for direct model training
2. **intermediate.parquet**: For exploration and custom tokenization workflows
## Dependencies
```bash
pip install spacy transformers datasets tqdm
python -m spacy download en_core_web_sm
pip install pyarrow # for parquet output
```
## Tokenizer
### XLNetTokenizer
Preprocessed data uses **[XLNetTokenizer](https://huggingface.co/xlnet/xlnet-base-cased)** for subword tokenization.
**Model**: `xlnet/xlnet-base-cased`
**Vocab size**: 32,000 tokens
**Features**:
- SentencePiece subword tokenization
- Punctuation-aware splitting
- Multilingual support built-in
**Example tokenization**:
```python
from transformers import XLNetTokenizer
tokenizer = XLNetTokenizer.from_pretrained("xlnet/xlnet-base-cased")
text = "Don't forget the meeting at 5pm."
ids = tokenizer.encode(text, add_special_tokens=False)
tokens = tokenizer.convert_ids_to_tokens(ids)
# tokens: ["Don", "'", "t", "forget", "the", "meeting", "at", "5", "pm", "."]
# ids: [13645, 9, 24, 12087, 5, 4857, 19, 821, 131, 10]
```
### spaCy Features
Linguistic annotations are extracted using **spaCy** (`en_core_web_sm`):
| Feature | Description |
|---------|-------------|
| `pos` | Part-of-speech tags (NOUN, VERB, ADJ, etc.) |
| `dep` | Dependency relations (nsubj, dobj, prep, etc.) |
| `lemma` | Lemmatized forms |
| `ent_type` | Named entity types (PERSON, ORG, DATE, etc.) |
| `head_dist` | Distance to head token in dependency tree |
## Output Schema
Both output files contain the following columns:
| Column | Type | Description | Example |
|--------|------|-------------|---------|
| `id` | string | SHA256 hash (first 16 chars) | `"a1b2c3d4e5f6g7h8"` |
| `text` | string | Original sentence | `"The cat sat on the mat."` |
| `tokens` | string (JSON list) | XLNet token strings | `["The", "cat", "sat", ...]` |
| `token_ids` | string (JSON list) | XLNet integer IDs | `[44, 245, 1234, ...]` |
| `pos` | string (JSON list) | spaCy POS tags | `["DET", "NOUN", "VERB", ...]` |
| `dep` | string (JSON list) | Dependency labels | `["det", "nsubj", "ROOT", ...]` |
| `lemma` | string (JSON list) | Lemmas | `["the", "cat", "sit", ...]` |
| `ent_type` | string (JSON list) | Entity types | `["O", "O", "O", "DATE"]` |
| `head_dist` | string (JSON list) | Head distances | `[1, -2, 0, ...]` |
### JSON List Format
All list columns are stored as JSON strings for compatibility:
```python
import json
# Loading tokens from file
record = json.loads(line)
tokens = json.loads(record["tokens"]) # ["The", "cat", "sat", ...]
```
## Output Files
### pre_tokenized.jsonl.gz
Gzipped JSON Lines format for direct training consumption:
```python
import gzip
import json
with gzip.open("output/pre_tokenized.jsonl.gz", "rt") as f:
for line in f:
record = json.loads(line)
# Use directly in training
```
### intermediate.parquet
Apache Parquet for data exploration:
```python
import pyarrow.parquet as pq
table = pq.read_table("output/intermediate.parquet")
df = table.to_pandas()
# Explore with pandas
```
## Usage
### Basic Generation
```bash
cd hf_dataset
python generate.py
```
### Custom Options
```bash
python generate.py \
--max-samples 50000 \
--batch-size 200 \
--output-dir ./my_output \
--cache-dir ./my_cache
```
### Python API
```python
from generate import SEEDDatasetGenerator, SEEDConfig
config = SEEDConfig(
max_samples=10000,
batch_size=100,
output_dir=Path("output"),
)
generator = SEEDDatasetGenerator(config)
paths = generator.generate()
print(f"Generated: {paths}")
```
## Configuration
| Parameter | Default | Description |
|-----------|---------|-------------|
| `max_samples` | 10,000 | Maximum sentences to process |
| `batch_size` | 100 | Documents per spaCy batch |
| `min_sentence_len` | 5 | Minimum sentence characters |
| `max_sentence_len` | 512 | Maximum sentence characters |
| `output_dir` | `hf_dataset/output` | Output directory |
| `cache_dir` | `hf_dataset/.cache` | Cache directory |
| `hf_dataset_name` | `HuggingFaceFW/fineweb` | Source dataset |
| `spacy_model` | `en_core_web_sm` | spaCy model name |
| `xlnet_model` | `xlnet/xlnet-base-cased` | HuggingFace model path |
## Cache
The generator tracks processed samples in `cache_dir/processed_ids.json` to avoid duplicates and enable resuming interrupted runs.
## Notes
- Sentences shorter than 5 characters are skipped
- Sentences longer than 512 characters are truncated
- Duplicates are detected via SHA256 hash
- Processsing is streamed from HuggingFace (memory efficient)