Dataset Merging¶
This page documents the dataset merging functionality of AniSearch Model.
Overview¶
The merge_datasets.py
module handles the process of downloading, cleaning, and merging multiple anime and manga datasets into unified datasets that can be used by the search models.
API Reference¶
Anime and Manga Dataset Merger¶
Utility for merging, cleaning and consolidating multiple anime or manga datasets into comprehensive training datasets.
This module provides a robust processing pipeline for combining and standardizing anime and manga datasets from various sources. It handles data loading, cleaning, deduplication, and consolidation to create high-quality datasets suitable for training ML models.
Features¶
- Loads datasets from multiple sources (CSV files, JSON, Parquet, Hugging Face datasets)
- Applies advanced text preprocessing to titles and synopses
- Performs deduplication using multiple matching strategies
- Filters out inappropriate or unwanted content (adult, kids' content, music videos)
- Consolidates information across datasets while preserving provenance
- Handles multilingual titles and cross-referencing between sources
- Saves the final merged dataset with progress tracking
Processing Pipeline¶
The module implements separate processing pipelines for anime and manga datasets:
- Data Loading: Imports data from local files and Hugging Face
- Preprocessing: Cleans text fields and standardizes formats
- Content Filtering: Removes unwanted content categories
- Deduplication: Removes duplicate entries within and across datasets
- Merging: Combines datasets using ID and title-based matching
- Consolidation: Creates comprehensive entries from multiple sources
- Export: Saves the final dataset with progress tracking
Usage¶
The script can be run from the command line with a required --type
argument specifying either 'anime' or 'manga':
Output¶
The merged datasets will be saved to:
model/merged_anime_dataset.csv
(for anime)model/merged_manga_dataset.csv
(for manga)
These datasets contain standardized fields including: - title: Consolidated primary title - synopsis: Cleaned and merged synopsis text - genres: List of genres in consistent format - score: Average rating score - type: Media type (TV, Movie, Manga, etc.) - status: Current status (Airing, Completed, etc.)
Dataset Sources¶
Anime Datasets¶
The following datasets are processed for anime:
- MyAnimeList Dataset (
anime.csv
) - Primary source with core metadata - Anime Dataset 2023 (
anime-dataset-2023.csv
) - Recent releases and updates - Animes Dataset (
animes.csv
) - Additional descriptive content - Anime 4500 (
anime4500.csv
) - Curated collection of popular titles - Anime 2022 (
Anime-2022.csv
) - Recent releases from 2022 - Anime Data (
Anime_data.csv
) - Additional metadata - Anime2 (
Anime2.csv
) - Supplementary data - MAL Anime (
mal_anime.csv
) - Additional MyAnimeList data - Hugging Face Datasets:
johnidouglas/anime_270
- Curated anime collectionwykonos/anime
- Additional anime metadata
Manga Datasets¶
The following datasets are processed for manga:
- MyAnimeList Manga Dataset (
manga.csv
) - Primary source with core metadata - Jikan API Data (
jikan.csv
) - Data from the Jikan API (MyAnimeList) - Manga, Manhwa and Manhua Dataset (
data.csv
) - Diverse manga types
Notes¶
- Processing large datasets can be memory-intensive
- Runtime varies based on dataset sizes and available resources
- Consider available disk space for the output files
file_formatter module-attribute
¶
file_handler module-attribute
¶
file_handler = RotatingFileHandler('./logs/merge_datasets.log', maxBytes=10 * 1024 * 1024, backupCount=10, encoding='utf-8')
stream_formatter module-attribute
¶
add_additional_info ¶
add_additional_info(merged: DataFrame, additional_df: DataFrame, description_col: str, name_columns: list[str], new_synopsis_col: str) -> DataFrame
Add additional synopsis information from supplementary dataset.
PARAMETER | DESCRIPTION |
---|---|
merged | Main DataFrame to update with additional info TYPE: |
additional_df | DataFrame containing additional descriptions TYPE: |
description_col | Name of column containing descriptions TYPE: |
name_columns | List of columns to use for matching titles TYPE: |
new_synopsis_col | Name for new column to store additional synopses TYPE: |
RETURNS | DESCRIPTION |
---|---|
DataFrame | pd.DataFrame: Updated DataFrame with additional synopsis information |
Matches entries between datasets and adds non-duplicate synopsis information. Uses tqdm for progress tracking during updates.
Source code in src/merge_datasets.py
clean_synopsis ¶
Clean synopsis text by removing entries containing unwanted phrases.
This function identifies and removes invalid synopsis entries that contain specific unwanted phrases (like "No synopsis" or "Music video"). This helps ensure the dataset contains only meaningful synopsis content.
PARAMETER | DESCRIPTION |
---|---|
df | DataFrame containing the synopsis column to clean TYPE: |
synopsis_col | Name of the column containing synopsis text TYPE: |
unwanted_phrases | List of phrases that indicate invalid synopsis content (e.g., ["No synopsis", "Music video", "Short film"]) TYPE: |
Notes
- The function modifies the DataFrame in-place
- Empty synopses are represented as empty strings
- The function logs the column being cleaned
Example
Source code in src/merge_datasets.py
consolidate_titles ¶
Consolidate multiple title columns into a single title column.
When working with multiple datasets, titles for the same content may be stored in different columns. This function creates a single consolidated title column by taking the first available non-null title from the specified columns.
PARAMETER | DESCRIPTION |
---|---|
df | DataFrame containing multiple title columns TYPE: |
title_columns | List of column names containing titles to consolidate (e.g., ["title_english", "title_japanese", "original_title"]) TYPE: |
RETURNS | DESCRIPTION |
---|---|
Series | pd.Series: Consolidated titles, using first non-null value found across columns |
Notes
- Prioritizes existing 'title' column if present in the DataFrame
- Fills missing values from other title columns in the order they're provided
- Empty strings and 'unknown title' are treated as null values
- Logs warnings for entries with missing titles after consolidation
Example
Source code in src/merge_datasets.py
find_additional_info ¶
find_additional_info(row: Series, additional_df: DataFrame, description_col: str, name_columns: list) -> Optional[str]
Find matching description information from additional dataset.
PARAMETER | DESCRIPTION |
---|---|
row | Series containing title information to match TYPE: |
additional_df | DataFrame containing additional descriptions TYPE: |
description_col | Name of column containing descriptions TYPE: |
name_columns | List of column names to use for matching titles TYPE: |
RETURNS | DESCRIPTION |
---|---|
Optional[str] | str | None: Matching description if found, None otherwise |
Attempts to match titles across multiple name columns and returns first matching description.
Source code in src/merge_datasets.py
main ¶
Main entry point for the dataset merging script.
This function serves as the entry point for running the dataset merging process. It parses command-line arguments to determine whether to merge anime or manga datasets, executes the appropriate merging function, and handles any exceptions that may occur during the process.
Command-line arguments:
--type: Specifies the type of dataset to merge ('anime' or 'manga')
The function will:
- Parse command-line arguments
- Call the appropriate merging function based on the specified type
- Handle exceptions and log errors if they occur
- Display a success message upon completion
Example usage
Notes
- The merging process can be memory-intensive and might take some time
- Progress is logged to the console during execution
- Requires the appropriate datasets to be available in the expected paths
Source code in src/merge_datasets.py
merge_anime_datasets ¶
Merge multiple anime datasets into a single comprehensive dataset.
This function orchestrates the entire process of merging anime datasets from multiple sources into a single cohesive dataset. It handles loading, preprocessing, merging, and saving the final dataset.
Processing steps:
- Loading datasets from CSV files and Hugging Face datasets
- Preprocessing datasets (cleaning, standardizing, removing duplicates)
- Removing inappropriate content (adult, kids' content)
- Merging datasets based on IDs and titles
- Consolidating information (synopsis, ratings, genres)
- Removing duplicates from the merged dataset
- Saving the final dataset to disk with progress tracking
RETURNS | DESCRIPTION |
---|---|
DataFrame | pd.DataFrame: Merged and cleaned anime dataset containing: - title: Standardized title - synopsis: Consolidated synopsis text - genres: List of genres - score: Average rating score - type: Anime type (TV, Movie, OVA, etc.) - status: Airing status - episodes: Number of episodes - And other relevant columns |
RAISES | DESCRIPTION |
---|---|
Exception | If any error occurs during the merging process |
Notes
- The process can be memory-intensive for large datasets
- Progress is logged at each major step
- The final dataset is saved to 'data/anime/merged_anime_dataset.csv'
Source code in src/merge_datasets.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 |
|
merge_manga_datasets ¶
Merge multiple manga datasets into a single comprehensive dataset.
This function orchestrates the process of merging manga datasets from multiple sources into a unified dataset. Similar to the anime merging process, it handles loading, preprocessing, merging, and saving the final manga dataset.
Processing steps:
- Loading manga datasets from CSV files
- Preprocessing datasets (cleaning, standardizing)
- Removing inappropriate or low-quality content
- Merging datasets based on IDs and titles
- Consolidating information from multiple sources
- Removing duplicates from the merged dataset
- Saving the final dataset to disk
RETURNS | DESCRIPTION |
---|---|
DataFrame | pd.DataFrame: Merged and cleaned manga dataset containing: - title: Standardized manga title - synopsis: Consolidated synopsis text - genres: List of genres - score: Average rating score - type: Manga type (Manga, Manhwa, One-shot, etc.) - status: Publication status - chapters: Number of chapters - volumes: Number of volumes - And other relevant columns |
RAISES | DESCRIPTION |
---|---|
Exception | If any error occurs during the merging process |
Notes
- Progress is logged at each major step
- The final dataset is saved to 'data/manga/merged_manga_dataset.csv'
- The manga merging process handles fewer sources compared to anime
Source code in src/merge_datasets.py
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 |
|
parse_args ¶
Parse command line arguments for dataset type selection.
This function sets up an argument parser to accept a single required argument --type
, which specifies whether to merge anime or manga datasets. The validation of the argument is handled by the choices parameter to ensure only valid dataset types are accepted.
RETURNS | DESCRIPTION |
---|---|
Namespace | argparse.Namespace: Parsed command-line arguments containing: - type (str): Either 'anime' or 'manga' to specify dataset type to merge |
Source code in src/merge_datasets.py
preprocess_name ¶
Preprocess a name string for consistent matching.
This function standardizes name strings to ensure consistent comparison and matching across different datasets. It handles various input types and normalizes names to lowercase with consistent whitespace.
PARAMETER | DESCRIPTION |
---|---|
name | Input name value of any type Can be string, number, or other types including None/NaN TYPE: |
RETURNS | DESCRIPTION |
---|---|
str | Preprocessed name in lowercase with whitespace stripped Returns empty string if input is null/NaN TYPE: |
Example
Source code in src/merge_datasets.py
preprocess_synopsis_columns ¶
Preprocess text in synopsis columns for consistency.
PARAMETER | DESCRIPTION |
---|---|
df | DataFrame containing synopsis columns TYPE: |
synopsis_cols | List of column names containing synopsis text TYPE: |
Applies common text preprocessing to each synopsis column in-place. Uses preprocess_text() for standardization. Logs warning if specified column not found.
Source code in src/merge_datasets.py
preprocess_text ¶
Preprocess text data by applying various cleaning and normalization steps.
This function implements a comprehensive text preprocessing pipeline that normalizes and cleans textual data, making it more suitable for analysis and matching operations.
Preprocessing steps:
- Converting to lowercase
- Expanding contractions (e.g., "don't" → "do not")
- Removing accents and special characters
- Removing extra whitespace
- Removing URLs and web references
- Removing source citations and attributions
- Removing stopwords (common words like "the", "and", etc.)
- Lemmatizing words (converting to base forms)
PARAMETER | DESCRIPTION |
---|---|
text | Input text to preprocess. Can be string or other type. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Any | Preprocessed text if input was string, otherwise returns input unchanged. Returns empty string for None inputs. TYPE: |
Example
Source code in src/merge_datasets.py
remove_duplicate_infos ¶
Remove duplicate synopsis/description entries across columns.
PARAMETER | DESCRIPTION |
---|---|
df | DataFrame containing synopsis columns TYPE: |
info_cols | List of column names containing synopsis information TYPE: |
RETURNS | DESCRIPTION |
---|---|
DataFrame | pd.DataFrame: DataFrame with duplicate synopses removed |
Keeps first occurrence of each unique synopsis and sets duplicates to NA. Processes row-by-row to maintain data integrity.
Source code in src/merge_datasets.py
remove_numbered_list_synopsis ¶
Remove synopsis entries that are formatted as numbered lists.
Some synopsis entries consist only of numbered lists (e.g., "1. Character introduction 2. Plot outline...") which typically don't provide a cohesive description. This function identifies such entries using regex pattern matching and removes them.
PARAMETER | DESCRIPTION |
---|---|
df | DataFrame containing the synopsis columns to clean TYPE: |
synopsis_cols | List of column names containing synopsis text to process TYPE: |
Notes
- The function modifies the DataFrame in-place
- Numbered list synopses are replaced with empty strings
- The regex pattern identifies entries that predominantly consist of numbered points (e.g., "1.", "2.", etc.)
- The function logs which columns are being processed