NiklasAbraham commited on
Commit
90c9c63
·
verified ·
1 Parent(s): fa81228

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -57,3 +57,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
57
  # Video files - compressed
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
 
57
  # Video files - compressed
58
  *.mp4 filter=lfs diff=lfs merge=lfs -text
59
  *.webm filter=lfs diff=lfs merge=lfs -text
60
+ final_dataset.csv filter=lfs diff=lfs merge=lfs -text
61
+ knn_faiss_novelty.csv filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,386 @@
1
- ---
2
- license: cc-by-nc-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Movie Plot Embeddings Dataset
2
+
3
+ **Project Title**: Plot Twists Over Time: How Movie Stories Have Changed Over 95 Years
4
+
5
+ ## Dataset Summary
6
+
7
+ This dataset contains movie metadata, plot summaries, and semantic embeddings for feature-length films released between 1930 and 2024. The dataset was created for analyzing temporal semantic drift in movie plots using embedding-based techniques, as part of the research project "Plot Twists Over Time: How Movie Stories Have Changed Over 95 Years". It includes comprehensive movie metadata from Wikidata, TMDb, and Wikipedia, along with dense and sparse embeddings generated using the BAAI/bge-m3 model.
8
+
9
+ **Dataset Size**: ~92,000 movies with plot summaries and embeddings
10
+
11
+ **Year Range**: 1930-2024
12
+
13
+ **Primary Use Case**: Temporal semantic analysis, genre classification, concept extraction, and embedding-based movie similarity analysis
14
+
15
+ ## Dataset Structure
16
+
17
+ The dataset consists of the following files:
18
+
19
+ ### Core Data Files
20
+
21
+ - **`final_dataset.csv`**: Consolidated movie metadata CSV file containing all movie information
22
+ - Contains 39 columns with movie metadata (title, year, genre, plot, etc.)
23
+ - Includes movies from 1930-2024
24
+ - All movies have corresponding embeddings in the embedding files
25
+
26
+ - **`final_dense_embeddings.npy`**: NumPy array of dense embeddings
27
+ - Shape: `(N, 1024)` where N is the number of movies
28
+ - Generated using BAAI/bge-m3 model with CLS token aggregation
29
+ - Each embedding corresponds to a movie plot summary
30
+
31
+ - **`final_dense_movie_ids.npy`**: NumPy array of movie IDs (Wikidata QIDs)
32
+ - Shape: `(N,)`
33
+ - Contains Wikidata QIDs (e.g., "Q1931001") corresponding to each embedding
34
+ - Index alignment: `final_dense_embeddings[i]` corresponds to `final_dense_movie_ids[i]`
35
+
36
+ - **`final_sparse_embeddings.npz`**: Sparse lexical weights (optional)
37
+ - Contains token-level lexical weights from BGE-M3 model
38
+ - Format: NPZ file with keys:
39
+ - `token_indices`: List of arrays, one per movie, containing token IDs with non-zero weights
40
+ - `weights`: List of arrays, one per movie, containing corresponding lexical weights
41
+ - `movie_ids`: Array of movie IDs corresponding to the lexical weights
42
+ - Used for concept extraction and fine-grained semantic analysis
43
+
44
+ ### Additional Files
45
+
46
+ - **`knn_faiss_novelty.csv`**: K-nearest neighbors analysis results using FAISS
47
+ - Contains novelty scores and neighbor information for movies
48
+
49
+ - **`umap_cluster_trajectories.png`**: Visualization of movie embeddings in UMAP space
50
+ - Shows temporal trajectories and genre clusters
51
+
52
+ - **`concept_space/`**: Directory containing concept vocabulary and embeddings
53
+ - `concept_words_*.npy`: WordNet-based concept vocabulary (nouns)
54
+ - `concept_vecs_*.npy`: Pre-computed embeddings for concept words
55
+ - Used for concept extraction and semantic mapping
56
+
57
+ ## Data Collection Pipeline
58
+
59
+ The dataset was created through a four-step pipeline:
60
+
61
+ ### Step 1: Wikidata Collection
62
+ - Queries Wikidata SPARQL endpoint to fetch movie metadata
63
+ - Filters for feature-length films (excludes TV series, short films, etc.)
64
+ - Collects: titles, release years, genres, directors, actors, countries, Wikidata IDs
65
+ - Year range: 1930-2024
66
+ - Target: ~8,000 movies per year
67
+
68
+ ### Step 2: TMDb Enrichment
69
+ - Enriches Wikidata entries with TMDb metadata via API lookup
70
+ - Retrieves: popularity scores, vote counts, average ratings, TMDb IDs
71
+ - Links movies using Wikidata IDs
72
+
73
+ ### Step 3: Wikipedia Plot Retrieval
74
+ - Fetches full plot summaries from Wikipedia using Wikidata sitelinks
75
+ - Handles redirects and extracts main plot sections
76
+ - Filters out plots that are too short or contain insufficient narrative content
77
+ - Stores plot text and section title
78
+
79
+ ### Step 4: Embedding Generation
80
+ - Generates dense embeddings using BAAI/bge-m3 model
81
+ - Uses CLS token aggregation method (default)
82
+ - Supports multiple chunking strategies (CLS token, mean pooling, chunk-first, late chunking)
83
+ - Generates sparse lexical weights for concept extraction
84
+ - Processes embeddings in batches with parallel GPU support
85
+
86
+ ## Data Fields
87
+
88
+ The `final_dataset.csv` file contains the following columns:
89
+
90
+ ### Core Identifiers
91
+ - **`movie_id`**: Wikidata QID (e.g., "Q1931001") - primary identifier
92
+ - **`title`**: Movie title
93
+ - **`year`**: Release year (1930-2024)
94
+ - **`imdb_id`**: IMDb identifier
95
+ - **`tmdb_id`**: TMDb identifier
96
+
97
+ ### Metadata
98
+ - **`release_date`**: Full release date
99
+ - **`country`**: Production country
100
+ - **`duration`**: Runtime in minutes
101
+ - **`duration_all`**: All duration information
102
+ - **`wikidata_class`**: Wikidata entity class
103
+ - **`wikipedia_link`**: Link to Wikipedia article
104
+
105
+ ### Creative Team
106
+ - **`directors`**: Director names (pipe-separated if multiple)
107
+ - **`directors_id`**: Director Wikidata IDs (pipe-separated)
108
+ - **`actors`**: Actor names (pipe-separated if multiple)
109
+ - **`actors_id`**: Actor Wikidata IDs (pipe-separated)
110
+
111
+ ### Genre Information
112
+ - **`genre`**: Raw genre strings (comma-separated)
113
+ - **`genre_id`**: Genre Wikidata IDs (comma-separated)
114
+ - **`genre_cluster_ids`**: Clustered genre IDs (after processing)
115
+ - **`genre_cluster_names`**: Clustered genre names (after processing)
116
+
117
+ ### Plot Data
118
+ - **`plot`**: Full plot summary text from Wikipedia
119
+ - **`plot_section`**: Section title from which plot was extracted
120
+ - **`plot_length_chars`**: Character count of plot
121
+ - **`plot_length_tokens`**: Token count of plot
122
+ - **`num_different_tokens`**: Number of unique tokens
123
+ - **`token_shannon_entropy`**: Shannon entropy of token distribution
124
+
125
+ ### TMDb Metrics
126
+ - **`popularity`**: TMDb popularity score
127
+ - **`vote_average`**: Average user rating
128
+ - **`vote_count`**: Number of votes
129
+
130
+ ### Financial Data (if available)
131
+ - **`budget`**: Production budget
132
+ - **`budget_currency`**: Budget currency
133
+ - **`box_office`**: Box office revenue
134
+ - **`box_office_currency`**: Box office currency
135
+ - **`box_office_worldwide`**: Worldwide box office
136
+ - **`box_office_worldwide_currency`**: Worldwide currency
137
+
138
+ ### Additional Metadata
139
+ - **`set_in_period`**: Time period in which movie is set
140
+ - **`awards`**: Awards information
141
+ - **`summary`**: Additional summary (usually empty)
142
+
143
+ ## Loading the Dataset
144
+
145
+ ### Python Example
146
+
147
+ ```python
148
+ import numpy as np
149
+ import pandas as pd
150
+
151
+ # Load movie metadata
152
+ df = pd.read_csv('final_dataset.csv', low_memory=False)
153
+ print(f"Loaded {len(df)} movies")
154
+ print(f"Year range: {df['year'].min()} to {df['year'].max()}")
155
+
156
+ # Load dense embeddings
157
+ embeddings = np.load('final_dense_embeddings.npy')
158
+ movie_ids = np.load('final_dense_movie_ids.npy', allow_pickle=True)
159
+
160
+ print(f"Embeddings shape: {embeddings.shape}")
161
+ print(f"Number of movie IDs: {len(movie_ids)}")
162
+
163
+ # Verify alignment: embeddings[i] corresponds to movie_ids[i]
164
+ assert len(embeddings) == len(movie_ids)
165
+
166
+ # Merge embeddings with metadata
167
+ embeddings_df = pd.DataFrame({
168
+ 'movie_id': movie_ids,
169
+ 'embedding': list(embeddings)
170
+ })
171
+ combined_df = pd.merge(df, embeddings_df, on='movie_id', how='inner')
172
+ print(f"Combined dataset: {len(combined_df)} movies with embeddings")
173
+ ```
174
+
175
+ ### Using the Provided Utilities
176
+
177
+ The dataset is designed to work with the utilities in `src/data_utils.py`:
178
+
179
+ ```python
180
+ from src.data_utils import (
181
+ load_final_dataset,
182
+ load_final_dense_embeddings,
183
+ load_final_sparse_embeddings,
184
+ load_final_data_with_embeddings
185
+ )
186
+
187
+ # Load dataset with embeddings merged
188
+ data_dir = "data/data_final"
189
+ df = load_final_data_with_embeddings(
190
+ csv_path=f"{data_dir}/final_dataset.csv",
191
+ data_dir=data_dir,
192
+ verbose=True
193
+ )
194
+
195
+ # Access embeddings
196
+ embeddings = np.array(df['embedding'].tolist())
197
+ movie_ids = df['movie_id'].values
198
+ ```
199
+
200
+ ### Loading Sparse Embeddings (Lexical Weights)
201
+
202
+ ```python
203
+ from src.data_utils import load_final_sparse_embeddings
204
+
205
+ # Load sparse embeddings
206
+ token_indices_list, weights_list, movie_ids = load_final_sparse_embeddings(
207
+ data_dir="data/data_final",
208
+ verbose=True
209
+ )
210
+
211
+ # Access lexical weights for a specific movie
212
+ movie_idx = 0
213
+ token_indices = token_indices_list[movie_idx] # Token IDs with non-zero weights
214
+ weights = weights_list[movie_idx] # Corresponding lexical weights
215
+ movie_id = movie_ids[movie_idx] # Wikidata QID
216
+ ```
217
+
218
+ ## Embedding Details
219
+
220
+ ### Model
221
+ - **Model**: BAAI/bge-m3
222
+ - **Embedding Dimension**: 1024
223
+ - **Aggregation Method**: CLS token (default)
224
+ - **Normalization**: L2-normalized embeddings
225
+
226
+ ### Alternative Chunking Methods
227
+ The pipeline supports multiple chunking strategies (stored with suffixes):
228
+ - `_cls_token`: CLS token aggregation (default)
229
+ - `_mean_pooling`: Global mean pooling
230
+ - `_chunk_first_{chunk_size}_{stride}`: Early chunking with specified parameters
231
+ - `_late_chunking_{window_size}_{stride}`: Late chunking with specified parameters
232
+
233
+ ### Embedding Alignment
234
+ - Embeddings are indexed by `movie_id` (Wikidata QID)
235
+ - `final_dense_embeddings[i]` corresponds to `final_dense_movie_ids[i]`
236
+ - To find embedding for a specific movie:
237
+ ```python
238
+ movie_id = "Q1931001"
239
+ idx = np.where(movie_ids == movie_id)[0][0]
240
+ embedding = embeddings[idx]
241
+ ```
242
+
243
+ ## Concept Space
244
+
245
+ The `concept_space/` directory contains pre-computed concept vocabularies and embeddings:
246
+
247
+ - **Source**: WordNet noun synsets
248
+ - **Filtering**: Zipf frequency ≥ 4.0 (common words)
249
+ - **Size**: Top 20,000 most frequent nouns
250
+ - **Embedding Model**: BGE-small-en-v1.5 (L2-normalized)
251
+ - **Usage**: Concept extraction from movie plots using lexical weights
252
+
253
+ Files are parameterized by:
254
+ - Zipf threshold
255
+ - Vocabulary size
256
+ - Model name
257
+
258
+ Example: `concept_words_zipf2.5_vocab10000_BAAI_bge-m3.npy`
259
+
260
+ ## Data Quality
261
+
262
+ ### Completeness
263
+ - All movies have: `movie_id`, `title`, `year`, `wikipedia_link`
264
+ - ~92,000 movies have plot summaries
265
+ - ~91,000 movies have TMDb metadata (popularity, votes)
266
+ - ~75,000 movies have director information
267
+ - ~81,000 movies have genre information
268
+
269
+ ### Filtering
270
+ - Only feature-length films (excludes TV series, short films, video games)
271
+ - Plots filtered for minimum length and narrative content
272
+ - Non-movie entries removed based on Wikidata class
273
+
274
+ ### Data Cleaning
275
+ - Plot text cleaned (removed line breaks, normalized whitespace)
276
+ - Genre strings normalized and clustered
277
+ - Duplicate entries removed based on movie_id
278
+
279
+ ## Use Cases
280
+
281
+ ### 1. Temporal Semantic Drift Analysis
282
+ Analyze how movie plot semantics evolve over time:
283
+ ```python
284
+ # Group by decade and compute centroid shifts
285
+ decades = (df['year'] // 10) * 10
286
+ decade_embeddings = df.groupby(decades)['embedding'].apply(
287
+ lambda x: np.mean(np.array(x.tolist()), axis=0)
288
+ )
289
+ ```
290
+
291
+ ### 2. Genre Classification
292
+ Use embeddings for genre prediction or clustering:
293
+ ```python
294
+ from sklearn.cluster import KMeans
295
+
296
+ embeddings_array = np.array(df['embedding'].tolist())
297
+ kmeans = KMeans(n_clusters=10)
298
+ clusters = kmeans.fit_predict(embeddings_array)
299
+ ```
300
+
301
+ ### 3. Movie Similarity Search
302
+ Find similar movies using cosine similarity:
303
+ ```python
304
+ from sklearn.metrics.pairwise import cosine_similarity
305
+
306
+ target_embedding = embeddings[0].reshape(1, -1)
307
+ similarities = cosine_similarity(target_embedding, embeddings)
308
+ similar_movies = np.argsort(similarities[0])[-10:][::-1]
309
+ ```
310
+
311
+ ### 4. Concept Extraction
312
+ Extract semantic concepts from plots using lexical weights:
313
+ ```python
314
+ # Use sparse embeddings to map plot nouns to concept space
315
+ # See src/analysis/concept_extraction.py for implementation
316
+ ```
317
+
318
+ ## Citation
319
+
320
+ If you use this dataset, please cite:
321
+
322
+ ```bibtex
323
+ @dataset{movie_plot_embeddings_2026,
324
+ title={Plot Twists Over Time: How Movie Stories Have Changed Over 95 Years},
325
+ author={Cheung, Ansel and Villa, Alessio and Markovinović, Bartol and López de Ipiña, Martín and Abraham, Niklas},
326
+ year={2026},
327
+ note={Dataset collected from Wikidata, TMDb, and Wikipedia for temporal semantic analysis of movie plots}
328
+ }
329
+ ```
330
+
331
+ ## License
332
+
333
+ This dataset is derived from multiple open data sources with different licenses. Users must comply with all applicable source licenses:
334
+
335
+ - **Wikidata**: Released under [CC0 1.0 Universal (Public Domain)](https://creativecommons.org/publicdomain/zero/1.0/). No restrictions on use.
336
+ - **Wikipedia**: Content is licensed under [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/). Requires attribution and share-alike terms.
337
+ - **TMDb**: Data is licensed under [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/) for non-commercial use. Commercial use requires separate licensing from TMDb.
338
+
339
+ **Dataset License**: This aggregated dataset inherits the most restrictive license from its sources. For non-commercial research purposes, this dataset may be used under CC BY-NC 4.0 with proper attribution to all sources. For commercial use, users must obtain appropriate licenses from TMDb and comply with Wikipedia's CC BY-SA 4.0 terms.
340
+
341
+ **Code/Software**: The code used to create this dataset is licensed under MIT License (see main repository LICENSE file).
342
+
343
+ **Attribution**: When using this dataset, please cite:
344
+ - Wikidata contributors
345
+ - Wikipedia contributors
346
+ - TMDb (The Movie Database)
347
+ - This dataset (see Citation section)
348
+
349
+ ## Acknowledgments
350
+
351
+ - **Wikidata**: Movie metadata and identifiers
352
+ - **TMDb**: Popularity scores, ratings, and additional metadata
353
+ - **Wikipedia**: Plot summaries and descriptions
354
+ - **BAAI**: BGE-M3 embedding model
355
+ - **WordNet**: Concept vocabulary for semantic analysis
356
+
357
+ ## Contact
358
+
359
+ For questions or issues, please refer to the main repository: [GroupDataLiteracy](https://github.com/your-repo/GroupDataLiteracy)
360
+
361
+ ## Dataset Statistics
362
+
363
+ - **Total Movies**: ~92,000
364
+ - **Year Range**: 1930-2024
365
+ - **Movies with Plots**: ~92,000
366
+ - **Movies with TMDb Data**: ~91,000
367
+ - **Movies with Genres**: ~81,000
368
+ - **Embedding Dimension**: 1024
369
+ - **Average Plot Length**: ~1,500 characters
370
+ - **Unique Genres**: ~50 (after clustering)
371
+
372
+ ## File Sizes (Approximate)
373
+
374
+ - `final_dataset.csv`: ~200 MB
375
+ - `final_dense_embeddings.npy`: ~380 MB (for 92K movies × 1024 dims)
376
+ - `final_dense_movie_ids.npy`: ~7 MB
377
+ - `final_sparse_embeddings.npz`: ~500 MB (variable, depends on sparsity)
378
+
379
+ ## Notes
380
+
381
+ - All embeddings are L2-normalized
382
+ - Movie IDs are Wikidata QIDs (strings starting with "Q")
383
+ - Plot text is cleaned and normalized
384
+ - Genre information may contain multiple genres per movie (pipe-separated)
385
+ - Some fields may be NaN for older movies or less popular films
386
+ - The dataset is designed for research in temporal semantic analysis and embedding-based movie analysis
concept_space/concept_vecs_zipf2.5_vocab10000_BAAI_bge-m3.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da0a9eaf7b141e96617f4d2ea08275bd7aaf090dd5a4effde36af3777cfe9690
3
+ size 40960128
concept_space/concept_words_zipf2.5_vocab10000_BAAI_bge-m3.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72e4f3d2aff99b1995882e788baa70284a09b042a7ccab509d8475fb5c38f0f7
3
+ size 102236
final_dataset.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:507f8e6336363f199a9fdbdf04f6c6b48e1b774c9154875f28ca9ec9fd096d32
3
+ size 206689833
final_dense_embeddings.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ab5eab102198e673741f41b66ac44179c9233216ca9d801fcd4418590666494f
3
+ size 189182080
final_dense_movie_ids.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44b744987091aa3a1030b1d91a7712127706ecdd19ad6ddf974bc8e2ed2b9ca0
3
+ size 3695088
final_sparse_embeddings.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dc78ed7779c63a0c58e1981e2c65e314d2ed34db56de8f9b3e35d04a06e401a3
3
+ size 223608040
knn_faiss_novelty.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cbde8053e55098daaacc24a38fb965e5f8c42848b971ab2e4cdcaa2b4f19ff09
3
+ size 31360950
upload_hf.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ from huggingface_hub import login, upload_folder
4
+
5
+ # Login with your Hugging Face credentials
6
+ login()
7
+
8
+ # Get current directory (absolute path of this script)
9
+ current_dir = os.path.abspath(os.path.dirname(__file__))
10
+ print(f"Current directory: {current_dir}")
11
+
12
+ # Upload the current folder (contents of the directory this script is in)
13
+ upload_folder(
14
+ folder_path=current_dir,
15
+ repo_id="NiklasAbraham/MoviePlotEmbeddingsDataset",
16
+ repo_type="dataset",
17
+ )