TraductAL / docs /GLOSSARY_EXTRACTION_QUICKSTART.md
Norelad's picture
Upload folder using huggingface_hub
40bcd86 verified
|
Raw History Blame Contribute Delete
10 kB

A newer version of the Gradio SDK is available: 6.32.0

Upgrade

πŸ“š Glossary Extraction Quick Start

Your situation: You have Glossaire vaudois (1861) PDF Your goal: Extract lexical data β†’ Import to Swiss French dataset Expected result: ~1,000-2,000 training examples


⚑ 3-Step Quick Start

Step 1: Install PDF Library (30 seconds)

# Install PyPDF2 (easiest)
pip install PyPDF2

# Or install all three for best compatibility
pip install PyPDF2 pdfplumber pymupdf

Step 2: Test Your PDF (1 minute)

# Replace with your actual PDF filename
./test_pdf_extraction.sh glossaire_vaudois_1861.pdf vaud

This will tell you:

  • βœ… Is text extractable?
  • βœ… Does it need OCR?
  • βœ… Where does the glossary start?
  • βœ… What patterns are present?

Step 3: Extract (2-5 minutes)

If test shows "Ready for extraction":

python3 glossary_extractor.py \
  --pdf glossaire_vaudois_1861.pdf \
  --dialect vaud

If test shows "Need OCR":

# Install OCR tool
pip install ocrmypdf

# Run OCR (creates searchable PDF)
ocrmypdf glossaire_vaudois_1861.pdf glossaire_vaudois_1861_ocr.pdf --language fra

# Then extract
python3 glossary_extractor.py \
  --pdf glossaire_vaudois_1861_ocr.pdf \
  --dialect vaud

Result: CSV file at datasets/swiss_french/Raw_Data/extracted_vaud_glossary.csv


πŸ“‹ What You'll See

During Extraction

πŸ“„ Extracting text from: glossaire_vaudois_1861.pdf
   Pages: 250
   βœ… Extracted 245,892 characters

🧹 Cleaning text...
   Cleaned 3,847 lines from 4,123 total

πŸ” Identifying glossary start...
   Found glossary start at line 145: ABAISER, v. Abaisser

πŸ“– Parsing entries from line 145...
   βœ… Parsed 1,247 entries

✨ Enriching entries...
   βœ… Enriched 1,247 entries

============================================================
πŸ“Š EXTRACTION STATISTICS
============================================================
PDF file: glossaire_vaudois_1861.pdf
Dialect: vaud
Total entries extracted: 1,247

Part of speech distribution:
   masculine noun: 542
   feminine noun: 423
   verb: 187
   adjective: 95

Entries with standard French: 892 (71.5%)

Sample entries:
   PANOSSE (feminine noun): Serpillière pour laver le sol...
   LINGE (masculine noun): Serviette de toilette...

πŸ’Ύ Saving to CSV: datasets/swiss_french/Raw_Data/extracted_vaud_glossary.csv
   βœ… Saved 1,247 entries

πŸ“ Next step:
   python3 swiss_french_dataset_builder.py --dialect vaud --import-csv datasets/swiss_french/Raw_Data/extracted_vaud_glossary.csv

CSV Output Format

swiss_french,standard_french,dialect,part_of_speech,definition,source,notes
panosse,serpillière,vaud,feminine noun,Serpillière pour laver le sol,Glossaire vaud (1861),Line 150
linge,serviette,vaud,masculine noun,Serviette de toilette,Glossaire vaud (1861),Line 151
ça joue,ça va,vaud,expression,Manière de saluer familière,Glossaire vaud (1861),Line 243

🎯 After Extraction: Import to Dataset

# Import the CSV
python3 swiss_french_dataset_builder.py \
  --dialect vaud \
  --import-csv datasets/swiss_french/Raw_Data/extracted_vaud_glossary.csv

# Check your progress
python3 swiss_french_dataset_builder.py --stats

Expected output: ```

πŸ“Š DATASET STATISTICS

sft_dictionary_vaud.jsonl: 2,494 examples

βœ… Total examples: 2,494 πŸ“ Location: TraductAL-v1.1.0/datasets/swiss_french

πŸ“ˆ Progress vs. Romansh dataset (46,092 examples): Current: 5.4% 🎯 Next milestone: 5,000 examples (dictionary focus)


**Impact**: 1,247 entries β†’ 2,494 training examples (bidirectional)

---

## πŸ”§ Common Issues & Solutions

### Issue 1: No Text Extracted

**Symptom:**

πŸ“„ Extracting text from: glossaire.pdf Pages: 250 βœ… Extracted 0 characters


**Cause**: PDF is image-based (scanned), not searchable

**Solution**: Run OCR
```bash
# Install
pip install ocrmypdf

# Run OCR (French language)
ocrmypdf glossaire_vaudois_1861.pdf glossaire_vaudois_1861_ocr.pdf --language fra

# Extract from OCR'd version
python3 glossary_extractor.py --pdf glossaire_vaudois_1861_ocr.pdf --dialect vaud

Alternative: Use Google Drive

  1. Upload PDF to Google Drive
  2. Right-click β†’ Open with Google Docs
  3. File β†’ Download β†’ PDF
  4. Extract from the downloaded PDF

Issue 2: Few Entries Found

Symptom:

πŸ“– Parsing entries from line 0...
   βœ… Parsed 23 entries

Cause: Extraction started too early (preface, table of contents)

Solution: Manual start line

# Save raw text
python3 glossary_extractor.py --pdf glossaire.pdf --save-raw raw.txt

# Open and find where glossary starts
less raw.txt
# Look for first entry like "ABAISER" or "A." section marker

# Extract from correct line (e.g., line 145)
python3 glossary_extractor.py \
  --raw-text raw.txt \
  --start-line 145 \
  --dialect vaud

Issue 3: Garbled Characters

Symptom:

panosse,serpilli̬ère,vaud,...

Cause: OCR errors or encoding issues

Solution A: Try different PDF library

# Install pymupdf (often better for OCR)
pip install pymupdf

# Re-extract
python3 glossary_extractor.py --pdf glossaire.pdf --dialect vaud

Solution B: Manual cleanup in CSV

# Extract
python3 glossary_extractor.py --pdf glossaire.pdf --output temp.csv

# Open in LibreOffice/Excel and fix manually
libreoffice temp.csv

# Then import
python3 swiss_french_dataset_builder.py --dialect vaud --import-csv temp.csv

πŸ’‘ Pro Tips

Tip 1: Always Test First

# Test with small sample
./test_pdf_extraction.sh glossaire.pdf vaud

# Review output before full extraction

Tip 2: Save Raw Text

# Always save raw text for review
python3 glossary_extractor.py \
  --pdf glossaire.pdf \
  --save-raw raw_vaud_text.txt \
  --dialect vaud

# You can reprocess without re-extracting PDF
python3 glossary_extractor.py \
  --raw-text raw_vaud_text.txt \
  --dialect vaud

Tip 3: Manual Review is OK

Don't expect 100% automatic accuracy:

  • 80-90% automatic extraction is great
  • 10-20% manual cleanup is normal
  • Quality > quantity

Tip 4: Iterate

  1. Extract first pass
  2. Review sample entries
  3. Adjust if needed
  4. Re-extract
  5. Manual cleanup
  6. Import

πŸ“ˆ Expected Results by PDF Quality

PDF Type Auto Extraction Manual Work Total Time
Modern, searchable 95% 5% 10 min
OCR'd (good quality) 85% 15% 30 min
OCR'd (poor quality) 70% 30% 1-2 hours
Image-only (no OCR) 0% β†’ OCR needed - +15 min OCR

Your Glossaire vaudois (1861): Likely "OCR'd (good quality)" category

  • Expected: 1,000-1,500 entries automatically
  • Manual cleanup: 100-300 entries
  • Total time: 30-60 minutes

🎯 Realistic Expectations

From One 1861 Glossary

Input: Glossaire vaudois (1861), ~250 pages

Automatic extraction:

  • 1,200 entries (80% success rate)
  • 2,400 training examples (bidirectional)

After manual cleanup (1-2 hours):

  • 1,500 entries (includes manual fixes)
  • 3,000 training examples

With additional processing:

  • Add example sentences: +1,500 examples
  • Add idiom identification: +500 examples
  • Total: ~5,000 examples from one glossary!

βœ… Success Checklist

After extraction, verify:

  • CSV file created with entries
  • Entry count reasonable (500+)
  • Sample entries look correct
  • Standard French column has values (>50%)
  • No major OCR errors (???, garbled text)

If all checked: Import to dataset!

python3 swiss_french_dataset_builder.py \
  --dialect vaud \
  --import-csv extracted_vaud_glossary.csv

python3 swiss_french_dataset_builder.py --stats

πŸš€ Next Steps

Immediate (Today)

  1. βœ… Test your PDF: ./test_pdf_extraction.sh glossaire_vaudois_1861.pdf vaud
  2. βœ… Run OCR if needed: ocrmypdf input.pdf output_ocr.pdf --language fra
  3. βœ… Extract: python3 glossary_extractor.py --pdf glossaire.pdf --dialect vaud
  4. βœ… Import: python3 swiss_french_dataset_builder.py --dialect vaud --import-csv extracted.csv

This Week

  1. Find more glossaries (Geneva, Fribourg, NeuchΓ’tel)
  2. Extract each one
  3. Target: 5,000 total examples

This Month

  1. Generate synthetic data (fill gaps)
  2. Human validation
  3. Target: 20,000 examples (production-ready)

πŸ“ž Need Help?

Documentation:

  • Full guide: PDF_GLOSSARY_EXTRACTION_GUIDE.md
  • This quickstart: GLOSSARY_EXTRACTION_QUICKSTART.md
  • Dataset guide: SWISS_FRENCH_DATASET_GUIDE.md

Test commands:

# Test PDF
./test_pdf_extraction.sh your_glossary.pdf vaud

# Get help
python3 glossary_extractor.py --help

Common commands:

# Basic extraction
python3 glossary_extractor.py --pdf glossary.pdf --dialect vaud

# With OCR
ocrmypdf glossary.pdf glossary_ocr.pdf --language fra
python3 glossary_extractor.py --pdf glossary_ocr.pdf --dialect vaud

# Save raw text for review
python3 glossary_extractor.py --pdf glossary.pdf --save-raw raw.txt

# Process raw text
python3 glossary_extractor.py --raw-text raw.txt --dialect vaud

# Import to dataset
python3 swiss_french_dataset_builder.py --dialect vaud --import-csv extracted.csv

🎊 Summary

What you have:

  • βœ… Glossaire vaudois (1861) PDF
  • βœ… Extraction tool (glossary_extractor.py)
  • βœ… Test script (test_pdf_extraction.sh)
  • βœ… Import pipeline (dataset builder)

What to do:

  1. Test PDF (1 minute)
  2. Run OCR if needed (5-15 minutes)
  3. Extract glossary (2-5 minutes)
  4. Import to dataset (1 minute)

Expected result:

  • 1,000-1,500 dictionary entries
  • 2,000-3,000 training examples
  • Major progress toward 5,000-example milestone!

Time investment: 30-60 minutes total


Your glossary is a goldmine - let's extract it! πŸ“šπŸ’Žβ†’πŸ“Š