Main Module¶
This page documents the main entry point for the AniSearch Model application.
Overview¶
The src.main
module serves as the primary entry point for the AniSearch Model CLI. It handles command-line parsing, model initialization, and execution of search and training operations.
API Reference¶
Anime/Manga Description Search Model using Cross-Encoders
This script implements a cross-encoder model to match user-provided descriptions with anime/manga entries in the merged dataset. It enables semantic search capabilities by computing relevance scores between queries and entries in the dataset.
The application has two main modes:
- Search Mode: For finding anime/manga that match a description
- Training Mode: For fine-tuning cross-encoder models on anime/manga data
Usage
# Search mode:
python src/main.py search --type anime --query "A story about pirates searching for treasure"
python src/main.py search --type manga --query "A story about a boy who becomes a hero"
python src/main.py search --type anime --interactive # For interactive mode
python src/main.py search --type manga --query "Fantasy adventure" --include-light-novels
# Training mode:
python src/main.py train --type anime --model "cross-encoder/ms-marco-MiniLM-L-6-v2" --epochs 3
python src/main.py train --type manga --model "cross-encoder/ms-marco-MiniLM-L-6-v2" --epochs 3
python src/main.py train --type anime --create-labeled-data "data/labeled_anime.csv"
The script will return the top matching anime/manga titles based on the query.
ATTRIBUTE | DESCRIPTION |
---|---|
logger | Logger instance for the main module
|
get_search_model ¶
get_search_model(dataset_type: str, model_name: str, device: Optional[str] = None, include_light_novels: bool = False) -> Any
Create and return the appropriate search model based on dataset type.
This factory function initializes either an AnimeSearchModel or MangaSearchModel based on the specified dataset type. For manga models, it optionally includes light novels in the dataset.
PARAMETER | DESCRIPTION |
---|---|
dataset_type | The type of dataset to search. Must be either 'anime' or 'manga'. TYPE: |
model_name | The name of the model to use, either a pre-trained model name or path to a fine-tuned model. TYPE: |
device | Device to run the model on ('cpu', 'cuda', 'cuda:0', etc.). If None, automatically selects the best available device. TYPE: |
include_light_novels | Whether to include light novels in manga search results. Only applicable when dataset_type is 'manga'. Defaults to False. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Any | An instance of either AnimeSearchModel or MangaSearchModel. |
RAISES | DESCRIPTION |
---|---|
ValueError | If dataset_type is not 'anime' or 'manga'. |
Example
Source code in src/main.py
handle_model_listing ¶
Handle listing models without loading any ML frameworks.
This is a lightweight function that doesn't import TensorFlow or PyTorch. It displays available pre-trained models for search, and optionally fine-tuned models if requested.
PARAMETER | DESCRIPTION |
---|---|
args | Command-line arguments namespace containing at least the following:
TYPE: |
Notes
This function calls sys.exit(0) after displaying the models to prevent loading heavy ML frameworks unnecessarily.
Example
Source code in src/main.py
handle_search_command ¶
Handle the search command functionality.
This function processes the search command, initializing the appropriate search model and executing either interactive search or one-time query search based on arguments.
The function supports:
- Interactive mode for continuous querying
- One-time query with formatted results
- Customizable number of results and batch size
PARAMETER | DESCRIPTION |
---|---|
args | Parsed command-line arguments for search, containing at least:
TYPE: |
RAISES | DESCRIPTION |
---|---|
Various exceptions might be raised but are handled by the decorator |
|
Example
Source code in src/main.py
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 |
|
handle_train_command ¶
Handle the train command functionality.
This function processes the training command, initializing the appropriate model trainer and executing either model training or labeled data creation based on arguments.
The function supports:
- Training anime or manga models with customizable parameters
- Creating labeled data without training
- Using custom labeled data for training
- Including light novels in manga training
PARAMETER | DESCRIPTION |
---|---|
args | Parsed command-line arguments for training, containing at least:
TYPE: |
RAISES | DESCRIPTION |
---|---|
Various exceptions might be raised but are handled by the decorator |
|
Example
# Handle training an anime model with specified parameters
args = ArgNamespace(type='anime', model='cross-encoder/ms-marco-MiniLM-L-6-v2',
epochs=3, batch_size=16, eval_steps=250, max_samples=10000,
learning_rate=2e-5, seed=42, include_light_novels=False,
create_labeled_data=None, labeled_data=None, loss='mse',
scheduler='linear')
handle_train_command(args)
Source code in src/main.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
|
main ¶
Main function to run the search model or trainer.
This is the entry point for the application. It:
- Sets up logging
- Parses command-line arguments
- Dispatches to the appropriate handler based on command
The function handles three primary commands:
search
: For finding anime/manga matching a descriptiontrain
: For training custom models on anime/manga data- Implicit model listing via --list-models or --list-fine-tuned flags
RETURNS | DESCRIPTION |
---|---|
None | None |
RAISES | DESCRIPTION |
---|---|
SystemExit | With code 1 if an unknown command is provided |