DataUtils
Utility module for data handling and management in the anime/manga recommendation system.
This module provides utility functions for:
-
Data persistence: Saving and loading training pairs
-
Genre and theme management: Maintaining predefined sets of genres and themes for both anime and manga datasets
The module supports two main data types:
-
Anime: Contains specific genres and themes for anime content
-
Manga: Contains specific genres and themes for manga content
FUNCTION | DESCRIPTION |
---|---|
save_pairs_to_csv |
Save training pairs (text pairs and their similarity labels) to CSV |
get_genres_and_themes |
Retrieve predefined sets of genres and themes based on data type |
The genre and theme sets are carefully curated for each data type and are used for calculating semantic similarities between different entries in the dataset. These sets are essential for the training process and maintaining consistency in the recommendation system.
Note
The genres and themes are maintained as static sets within the module. Updates to these sets should be done with careful consideration of the impact on the overall recommendation system.
get_genres_and_themes
¶
get_genres_and_themes(data_type: DataType) -> Tuple[Set[str], Set[str]]
Get predefined sets of genres and themes for anime or manga data.
This function returns two sets containing valid genres and themes based on the specified data type. The sets are curated specifically for each content type to ensure accurate semantic similarity calculations.
PARAMETER | DESCRIPTION |
---|---|
data_type
|
Type of data to get genres/themes for ("anime" or "manga")
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[Set[str], Set[str]]
|
Tuple[Set[str], Set[str]]: A tuple containing: - First element: Set of all valid genres for the data type - Second element: Set of all valid themes for the data type |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If data_type is not "anime" or "manga" |
Source code in src/training/common/data_utils.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
save_pairs_to_csv
¶
Save pairs of texts and their similarity labels to a CSV file.
This function takes a list of InputExample objects containing text pairs and their similarity labels and saves them to a CSV file. It creates the output directory if it doesn't exist.
PARAMETER | DESCRIPTION |
---|---|
pairs
|
List of text pairs and their similarity labels
TYPE:
|
filename
|
Path to save the CSV file
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If filename parameter is None |
OSError
|
If directory creation fails or file cannot be written |