How ferdesmello/sci-fi-novels-evolution works
1. Project purpose
- This repository is a data pipeline for studying how sci-fi novel plots change over time.
- The output is a set of CSV datasets and final figures, not an application or service.
2. Main pipeline stages
- The workflow is: collect book metadata → clean and reduce it → enrich it with Wikipedia plot text → query an LLM for structured plot attributes → aggregate results into figures.
- Each stage writes intermediate files that become the input to the next stage.
3. Data ingestion layer
- scripts/1_Goodreads_scraper_SHELF.py and scripts/2_Goodreads_scraper_LISTS.py gather book metadata from Goodreads shelf/list pages.
- The repo expects scraped or downloaded HTML inputs for at least part of this step, so the data source boundary is partly offline and manually prepared.
4. Raw and intermediate data boundary
- data/ is the central working area, with subfolders for raw-ish inputs, filtered datasets, model answers, and variability experiments.
- The repository keeps most processing artifacts as CSV files, making the pipeline file-driven rather than database-driven.
5. Cleaning and reduction subsystem
- scripts/3_Data_reducer_FILTERED.py merges the collected sources and removes duplicates, bad records, and non-target books.
- scripts/4_Data_reducer_TOP.py builds the analysis sample by selecting the top 200 novels per decade, plus a smaller test set.
- scripts/5_Data_fixer.py exists to reconcile downstream files when the filtered/top sample changes.
6. Wikipedia enrichment boundary
- scripts/6_Wikipedia_plot_scraper.py adds plot sections from Wikipedia for books in the top/test sets.
- This step shifts the dataset from Goodreads-derived metadata to richer narrative text, which is preferred for the later AI analysis.
7. LLM annotation subsystem
- scripts/7_AI_asker_AI_ANSWERS.py sends each novel’s data to OpenAI’s API and stores structured answers in data/answers/.
- scripts/8_AI_asker_AI_ANSWERS_GENDER.py is a separate annotation pass that infers author gender per unique author.
- These scripts are the main external-service dependency points; they require an API key and budget.
8. Model variability experiment
- data/variability_in_answers/ contains repeated answer runs for the test set.
- This supports measuring how stable the model’s responses are across runs, and it feeds the test/variance figures rather than the main results.
9. Analysis and visualization layer
- scripts/9_Figure_maker_novels.py, scripts/9_Figure_maker_questions.py, and scripts/9_Figure_maker_tests.py turn the CSV outputs into plots.
- The figure scripts read from the AI answer files, gender file, and variability files, then write final images into figures/.
10. Repository structure for reproducibility
- paths.py likely centralizes filesystem locations so the scripts can share the same directory conventions.
- This matters because the workflow depends heavily on consistent relative paths between raw data, filtered data, answers, and figures.
11. Archived/previous-model branch
- old/ contains prior versions of the same pipeline and outputs for GPT-4o and Gemini 2.0 Flash.
- Architecturally, this is an experiment archive rather than part of the active production path.
12. End-to-end data flow to diagram
- A useful architecture diagram should show three major boundaries: external data sources (Goodreads, Wikipedia, OpenAI), local CSV-based processing stages, and final visualization outputs.
- The key artifacts moving between stages are: scraped book metadata, filtered/top samples, Wikipedia-enriched text, LLM answer CSVs, and figures.
Main entry points: paths.py Paths · sci-fi_novels_FILTERED.csv Filtered data · figures Figures · sci-fi_novels_TEST_Wiki.csv Test Wiki
Components 20
External sources
Offline and API-backed inputs used by the pipeline.
- Shelf scraper · Collects Goodreads shelf-based metadata.
scripts/1_Goodreads_scraper_SHELF.py - List scraper · Collects Goodreads list-based metadata.
scripts/2_Goodreads_scraper_LISTS.py - Wikipedia plot · Scrapes plot sections for the selected books.
scripts/6_Wikipedia_plot_scraper.py - LLM answers · Sends novels to OpenAI and stores structured plot answers.
scripts/7_AI_asker_AI_ANSWERS.py - Gender pass · Infers author gender per unique author via OpenAI.
scripts/8_AI_asker_AI_ANSWERS_GENDER.py
CSV pipeline
Main file-driven processing stages and intermediate datasets.
- Paths · Centralizes repository file locations for shared scripts.
paths.py - Filtered data · Merged and cleaned metadata after duplicate and target filtering.
data/filtered/sci-fi_novels_FILTERED.csv - Top sample · Main analysis sample with top novels per decade.
data/filtered/sci-fi_novels_TOP.csv - Test sample · Smaller test subset used for downstream checks and variability runs.
data/filtered/sci-fi_novels_TEST.csv - Top Wiki · Top sample enriched with Wikipedia plot text.
data/filtered/sci-fi_novels_TOP_Wiki.csv - Test Wiki · Test sample enriched with Wikipedia plot text.
data/filtered/sci-fi_novels_TEST_Wiki.csv - AI answers · Main structured annotation output from the LLM.
data/answers/sci-fi_novels_AI_ANSWERS.csv - Gender data · Author-gender annotation output used by figure scripts.
data/answers/sci-fi_novels_AI_ANSWERS_GENDER.csv - Variability runs · Repeated test-set answer files used to measure response stability.
data/variability_in_answers/sci-fi_novels_AI_ANSWERS_TEST_01.csv
Analysis and figures
Scripts and outputs that turn annotated data into plots.
- Novel figures · Builds plots about novel-level trends from annotated data.
scripts/9_Figure_maker_novels.py - Question figures · Builds plots summarizing question-level AI outputs.
scripts/9_Figure_maker_questions.py - Test figures · Builds plots for test-set and variability analysis.
scripts/9_Figure_maker_tests.py - Figures · Final visualization outputs produced by the analysis layer.
figures
Archived experiments
Previous model runs and legacy pipeline outputs kept for reference.
- GPT-4o archive · Archived prior-model pipeline outputs and scripts.
old/gpt-4o - Gemini archive · Archived Gemini 2.0 Flash pipeline outputs and scripts.
old/gemini_2.0_flash
Connections 25
- Paths → Shelf scraper: shared paths · Uses shared filesystem conventions.
- Paths → List scraper: shared paths · Uses shared filesystem conventions.
- Paths → Wikipedia plot: shared paths · Uses shared filesystem conventions.
- Paths → LLM answers: shared paths · Uses shared filesystem conventions.
- Paths → Gender pass: shared paths · Uses shared filesystem conventions.
- Shelf scraper → Filtered data: metadata · Produces scraped Goodreads shelf metadata that feeds cleaning.
- List scraper → Filtered data: metadata · Produces scraped Goodreads list metadata that feeds cleaning.
- Filtered data → Top sample: sample · Reduced dataset is used to build the main analysis sample.
- Filtered data → Test sample: sample · Reduced dataset is also used to build the test subset.
- Top sample → Top Wiki: enrich · Top sample is augmented with Wikipedia plot text.
- Test sample → Test Wiki: enrich · Test sample is augmented with Wikipedia plot text.
- Top Wiki → LLM answers: annotate · Enriched top sample is sent for structured LLM annotation.
- Test Wiki → LLM answers: annotate · Enriched test sample is also sent for structured LLM annotation.
- Filtered data → Gender pass: authors · Filtered author list supports gender annotation.
- Test Wiki → Variability runs: repeat runs · Test set is repeatedly annotated to measure response stability.
- AI answers → Novel figures: input · Main AI answer CSV feeds novel-level charts.
- AI answers → Question figures: input · Main AI answer CSV feeds question-level charts.
- Gender data → Novel figures: input · Gender annotations support several novel-level plots.
- Gender data → Question figures: input · Gender annotations support question-level analysis.
- Variability runs → Test figures: input · Repeated runs feed stability and variance figures.
- Novel figures → Figures: write · Outputs final novel-level plots.
- Question figures → Figures: write · Outputs final question-level plots.
- Test figures → Figures: write · Outputs final test and variability plots.
- GPT-4o archive → Figures: archived outputs · Reference outputs from earlier GPT-4o runs.
- Gemini archive → Figures: archived outputs · Reference outputs from earlier Gemini runs.