inference/predictor API¶
DNA Language Model Inference Module.
This module implements core model inference functionality, including:
- DNAPredictor class
- Model loading and initialization
- Batch sequence prediction
- Result post-processing
- Device management
-
Half-precision inference support
-
Core features:
- Model state management
- Batch prediction
- Result merging
- Prediction result saving
-
Memory optimization
-
Inference optimization:
- Batch parallelization
- GPU acceleration
- Half-precision computation
- Memory efficiency optimization
Example
predictor = DNAPredictor(
model=model,
tokenizer=tokenizer,
config=config
)
results = predictor.predict(sequences)
DNAPredictor
¶
DNA sequence predictor using fine-tuned models.
This class provides comprehensive functionality for making predictions using DNA language models. It handles model loading, inference, result processing, and various output formats including hidden states and attention weights for model interpretability.
Attributes:
Name | Type | Description |
---|---|---|
model |
Fine-tuned model instance for inference |
|
tokenizer |
Tokenizer for encoding DNA sequences |
|
task_config |
Configuration object containing task settings |
|
pred_config |
Configuration object containing inference parameters |
|
device |
Device (CPU/GPU/MPS) for model inference |
|
sequences |
List of input sequences |
|
labels |
List of true labels (if available) |
|
embeddings |
Dictionary containing hidden states and attention weights |
Source code in dnallm/inference/predictor.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 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 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 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 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 |
|
__init__(model, tokenizer, config)
¶
Initialize the predictor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Any
|
Fine-tuned model instance for inference |
required |
tokenizer
|
Any
|
Tokenizer for encoding DNA sequences |
required |
config
|
dict
|
Configuration dictionary containing task settings and inference parameters |
required |
Source code in dnallm/inference/predictor.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
batch_predict(dataloader, do_pred=True, output_hidden_states=False, output_attentions=False)
¶
Perform batch prediction on sequences.
This method runs inference on batches of sequences and optionally extracts hidden states and attention weights for model interpretability.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataloader
|
DataLoader
|
DataLoader object containing sequences for inference |
required |
do_pred
|
bool
|
Whether to convert logits to predictions |
True
|
output_hidden_states
|
bool
|
Whether to output hidden states from all layers |
False
|
output_attentions
|
bool
|
Whether to output attention weights from all layers |
False
|
Returns:
Type | Description |
---|---|
Tuple[Tensor, Optional[Dict], Dict]
|
Tuple containing: - torch.Tensor: All logits from the model - Optional[Dict]: Predictions dictionary if do_pred=True, otherwise None - Dict: Embeddings dictionary containing hidden states and/or attention weights |
Note
Setting output_hidden_states or output_attentions to True will consume significant memory, especially for long sequences or large models.
Source code in dnallm/inference/predictor.py
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 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
calculate_metrics(logits, labels, plot=False)
¶
Calculate evaluation metrics for model predictions.
This method computes task-specific evaluation metrics using the configured metrics computation module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logits
|
Union[List, Tensor]
|
Model predictions (logits or probabilities) |
required |
labels
|
Union[List, Tensor]
|
True labels for evaluation |
required |
plot
|
bool
|
Whether to generate metric plots |
False
|
Returns:
Type | Description |
---|---|
Dict
|
Dictionary containing evaluation metrics for the task |
Source code in dnallm/inference/predictor.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 |
|
format_output(predictions)
¶
Format output predictions into a structured dictionary.
This method converts raw predictions into a user-friendly format with sequences, labels, and confidence scores.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
predictions
|
Tuple[Tensor, List]
|
Tuple containing (probabilities, labels) |
required |
Returns:
Type | Description |
---|---|
Dict
|
Dictionary containing formatted predictions with structure: |
Dict
|
{index: {'sequence': str, 'label': str/list, 'scores': dict/list}} |
Source code in dnallm/inference/predictor.py
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 |
|
generate_dataset(seq_or_path, batch_size=1, seq_col='sequence', label_col='labels', sep=None, fasta_sep='|', multi_label_sep=None, uppercase=False, lowercase=False, keep_seqs=True, do_encode=True)
¶
Generate dataset from sequences or file path.
This method creates a DNADataset and DataLoader from either a list of sequences or a file path, supporting various file formats and preprocessing options.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seq_or_path
|
Union[str, List[str]]
|
Single sequence, list of sequences, or path to a file containing sequences |
required |
batch_size
|
int
|
Batch size for DataLoader |
1
|
seq_col
|
str
|
Column name for sequences in the file |
'sequence'
|
label_col
|
str
|
Column name for labels in the file |
'labels'
|
sep
|
str
|
Delimiter for CSV, TSV, or TXT files |
None
|
fasta_sep
|
str
|
Delimiter for FASTA files |
'|'
|
multi_label_sep
|
Union[str, None]
|
Delimiter for multi-label sequences |
None
|
uppercase
|
bool
|
Whether to convert sequences to uppercase |
False
|
lowercase
|
bool
|
Whether to convert sequences to lowercase |
False
|
keep_seqs
|
bool
|
Whether to keep sequences in the dataset for later use |
True
|
do_encode
|
bool
|
Whether to encode sequences for the model |
True
|
Returns:
Type | Description |
---|---|
Tuple[DNADataset, DataLoader]
|
Tuple containing: - DNADataset: Dataset object with sequences and labels - DataLoader: DataLoader object for batch processing |
Raises:
Type | Description |
---|---|
ValueError
|
If input is neither a file path nor a list of sequences |
Source code in dnallm/inference/predictor.py
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 |
|
logits_to_preds(logits)
¶
Convert model logits to predictions and human-readable labels.
This method processes raw model outputs based on the task type to generate appropriate predictions and convert them to human-readable labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logits
|
Tensor
|
Model output logits tensor |
required |
Returns:
Type | Description |
---|---|
Tuple[Tensor, List]
|
Tuple containing: - torch.Tensor: Model predictions (probabilities or raw values) - List: Human-readable labels corresponding to predictions |
Raises:
Type | Description |
---|---|
ValueError
|
If task type is not supported |
Source code in dnallm/inference/predictor.py
223 224 225 226 227 228 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 |
|
plot_attentions(seq_idx=0, layer=-1, head=-1, width=800, height=800, save_path=None)
¶
Plot attention map visualization.
This method creates a heatmap visualization of attention weights between tokens in a sequence, showing how the model attends to different parts of the input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seq_idx
|
int
|
Index of the sequence to plot, default 0 |
0
|
layer
|
int
|
Layer index to visualize, default -1 (last layer) |
-1
|
head
|
int
|
Attention head index to visualize, default -1 (last head) |
-1
|
width
|
int
|
Width of the plot |
800
|
height
|
int
|
Height of the plot |
800
|
save_path
|
Optional[str]
|
Path to save the plot. If None, plot will be shown interactively |
None
|
Returns:
Type | Description |
---|---|
Optional[Any]
|
Attention map visualization if available, otherwise None |
Note
This method requires that attention weights were collected during inference by setting output_attentions=True in prediction methods
Source code in dnallm/inference/predictor.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 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 |
|
plot_hidden_states(reducer='t-SNE', ncols=4, width=300, height=300, save_path=None)
¶
Visualize embeddings using dimensionality reduction.
This method creates 2D visualizations of high-dimensional embeddings from different model layers using PCA, t-SNE, or UMAP dimensionality reduction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reducer
|
str
|
Dimensionality reduction method to use ('PCA', 't-SNE', 'UMAP') |
't-SNE'
|
ncols
|
int
|
Number of columns in the plot grid |
4
|
width
|
int
|
Width of each plot |
300
|
height
|
int
|
Height of each plot |
300
|
save_path
|
Optional[str]
|
Path to save the plot. If None, plot will be shown interactively |
None
|
Returns:
Type | Description |
---|---|
Optional[Any]
|
Embedding visualization if available, otherwise None |
Note
This method requires that hidden states were collected during inference by setting output_hidden_states=True in prediction methods
Source code in dnallm/inference/predictor.py
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 |
|
predict_file(file_path, evaluate=False, output_hidden_states=False, output_attentions=False, seq_col='sequence', label_col='labels', sep=None, fasta_sep='|', multi_label_sep=None, uppercase=False, lowercase=False, save_to_file=False, plot_metrics=False)
¶
Predict from a file containing sequences.
This method loads sequences from a file and performs prediction, with optional evaluation, visualization, and saving capabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Path to the file containing sequences |
required |
evaluate
|
bool
|
Whether to evaluate predictions against true labels |
False
|
output_hidden_states
|
bool
|
Whether to output hidden states for visualization |
False
|
output_attentions
|
bool
|
Whether to output attention weights for visualization |
False
|
seq_col
|
str
|
Column name for sequences in the file |
'sequence'
|
label_col
|
str
|
Column name for labels in the file |
'labels'
|
sep
|
str
|
Delimiter for CSV, TSV, or TXT files |
None
|
fasta_sep
|
str
|
Delimiter for FASTA files |
'|'
|
multi_label_sep
|
Union[str, None]
|
Delimiter for multi-label sequences |
None
|
uppercase
|
bool
|
Whether to convert sequences to uppercase |
False
|
lowercase
|
bool
|
Whether to convert sequences to lowercase |
False
|
save_to_file
|
bool
|
Whether to save predictions and metrics to output directory |
False
|
plot_metrics
|
bool
|
Whether to generate metric plots |
False
|
Returns:
Name | Type | Description |
---|---|---|
Either |
Union[Dict, Tuple[Dict, Dict]]
|
|
Note
Setting output_attentions=True may consume significant memory
Source code in dnallm/inference/predictor.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
|
predict_seqs(sequences, evaluate=False, output_hidden_states=False, output_attentions=False, save_to_file=False)
¶
Predict for a list of sequences.
This method provides a convenient interface for predicting on sequences, with optional evaluation and saving capabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sequences
|
Union[str, List[str]]
|
Single sequence or list of sequences for prediction |
required |
evaluate
|
bool
|
Whether to evaluate predictions against true labels |
False
|
output_hidden_states
|
bool
|
Whether to output hidden states for visualization |
False
|
output_attentions
|
bool
|
Whether to output attention weights for visualization |
False
|
save_to_file
|
bool
|
Whether to save predictions to output directory |
False
|
Returns:
Name | Type | Description |
---|---|---|
Either |
Union[Dict, Tuple[Dict, Dict]]
|
|
Note
Evaluation requires that labels are available in the dataset
Source code in dnallm/inference/predictor.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
generate(self, dataloader, n_tokens=400, temperature=1.0, top_k=4)
¶
Generate DNA sequences using the model.
This function performs sequence generation tasks using the loaded model, currently supporting EVO2 models for DNA sequence generation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataloader
|
DataLoader
|
DataLoader containing prompt sequences |
required |
n_tokens
|
int
|
Number of tokens to generate, default 400 |
400
|
temperature
|
float
|
Sampling temperature for generation, default 1.0 |
1.0
|
top_k
|
int
|
Top-k sampling parameter, default 4 |
4
|
Returns:
Type | Description |
---|---|
Dict
|
Dictionary containing generated sequences |
Note
Currently only supports EVO2 models for sequence generation
Source code in dnallm/inference/predictor.py
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 |
|
plot_attention_map(attentions, sequences, tokenizer, seq_idx=0, layer=-1, head=-1, width=800, height=800, save_path=None)
¶
Plot attention map visualization for transformer models.
This function creates a heatmap visualization of attention weights between tokens in a sequence, showing how the model attends to different parts of the input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attentions
|
Union[tuple, list]
|
Tuple or list containing attention weights from model layers |
required |
sequences
|
list
|
List of input sequences |
required |
tokenizer
|
Tokenizer object for converting tokens to readable text |
required | |
seq_idx
|
int
|
Index of the sequence to plot, default 0 |
0
|
layer
|
int
|
Layer index to visualize, default -1 (last layer) |
-1
|
head
|
int
|
Attention head index to visualize, default -1 (last head) |
-1
|
width
|
int
|
Width of the plot |
800
|
height
|
int
|
Height of the plot |
800
|
save_path
|
str
|
Path to save the plot. If None, plot will be shown interactively |
None
|
Returns:
Type | Description |
---|---|
Chart
|
Altair chart object showing the attention heatmap |
Source code in dnallm/inference/plot.py
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 |
|
plot_bars(data, show_score=True, ncols=3, width=200, height=50, bar_width=30, domain=(0.0, 1.0), save_path=None, separate=False)
¶
Plot bar charts for model metrics comparison.
This function creates bar charts to compare different metrics across multiple models. It supports automatic layout with multiple columns and optional score labels on bars.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict
|
Dictionary containing metrics data with 'models' as the first key |
required |
show_score
|
bool
|
Whether to show the score values on the bars |
True
|
ncols
|
int
|
Number of columns to arrange the plots |
3
|
width
|
int
|
Width of each individual plot |
200
|
height
|
int
|
Height of each individual plot |
50
|
bar_width
|
int
|
Width of the bars in the plot |
30
|
domain
|
Union[tuple, list]
|
Y-axis domain range for the plots, default (0.0, 1.0) |
(0.0, 1.0)
|
save_path
|
str
|
Path to save the plot. If None, plot will be shown interactively |
None
|
separate
|
bool
|
Whether to return separate plots for each metric |
False
|
Returns:
Type | Description |
---|---|
Chart
|
Altair chart object (combined or separate plots based on separate parameter) |
Source code in dnallm/inference/plot.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 |
|
plot_curve(data, show_score=True, width=400, height=400, save_path=None, separate=False)
¶
Plot ROC and PR curves for classification tasks.
This function creates ROC (Receiver Operating Characteristic) and PR (Precision-Recall) curves to evaluate model performance on classification tasks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict
|
Dictionary containing ROC and PR curve data with 'ROC' and 'PR' keys |
required |
show_score
|
bool
|
Whether to show the score values on the plot (currently not implemented) |
True
|
width
|
int
|
Width of each plot |
400
|
height
|
int
|
Height of each plot |
400
|
save_path
|
str
|
Path to save the plot. If None, plot will be shown interactively |
None
|
separate
|
bool
|
Whether to return separate plots for ROC and PR curves |
False
|
Returns:
Type | Description |
---|---|
Chart
|
Altair chart object (combined or separate plots based on separate parameter) |
Source code in dnallm/inference/plot.py
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 |
|
plot_embeddings(hidden_states, attention_mask, reducer='t-SNE', labels=None, label_names=None, ncols=4, width=300, height=300, save_path=None, separate=False)
¶
Visualize embeddings using dimensionality reduction techniques.
This function creates 2D visualizations of high-dimensional embeddings from different model layers using PCA, t-SNE, or UMAP dimensionality reduction methods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hidden_states
|
Union[tuple, list]
|
Tuple or list containing hidden states from model layers |
required |
attention_mask
|
Union[tuple, list]
|
Tuple or list containing attention masks for sequence padding |
required |
reducer
|
str
|
Dimensionality reduction method. Options: 'PCA', 't-SNE', 'UMAP' |
't-SNE'
|
labels
|
Union[tuple, list]
|
List of labels for the data points |
None
|
label_names
|
Union[str, list]
|
List of label names for legend display |
None
|
ncols
|
int
|
Number of columns to arrange the plots |
4
|
width
|
int
|
Width of each plot |
300
|
height
|
int
|
Height of each plot |
300
|
save_path
|
str
|
Path to save the plot. If None, plot will be shown interactively |
None
|
separate
|
bool
|
Whether to return separate plots for each layer |
False
|
Returns:
Type | Description |
---|---|
Chart
|
Altair chart object (combined or separate plots based on separate parameter) |
Raises:
Type | Description |
---|---|
ValueError
|
If unsupported dimensionality reduction method is specified |
Source code in dnallm/inference/plot.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
plot_muts(data, show_score=False, width=None, height=100, save_path=None)
¶
Visualize mutation effects on model predictions.
This function creates comprehensive visualizations of how different mutations affect model predictions, including: - Heatmap showing mutation effects at each position - Line plot showing gain/loss of function - Bar chart showing maximum effect mutations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict
|
Dictionary containing mutation data with 'raw' and mutation keys |
required |
show_score
|
bool
|
Whether to show the score values on the plot (currently not implemented) |
False
|
width
|
int
|
Width of the plot. If None, automatically calculated based on sequence length |
None
|
height
|
int
|
Height of the plot |
100
|
save_path
|
str
|
Path to save the plot. If None, plot will be shown interactively |
None
|
Returns:
Type | Description |
---|---|
Chart
|
Altair chart object showing the combined mutation effects visualization |
Source code in dnallm/inference/plot.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
|
plot_scatter(data, show_score=True, ncols=3, width=400, height=400, save_path=None, separate=False)
¶
Plot scatter plots for regression task evaluation.
This function creates scatter plots to compare predicted vs. experimental values for regression tasks, with optional R² score display.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict
|
Dictionary containing scatter plot data for each model |
required |
show_score
|
bool
|
Whether to show the R² score on the plot |
True
|
ncols
|
int
|
Number of columns to arrange the plots |
3
|
width
|
int
|
Width of each plot |
400
|
height
|
int
|
Height of each plot |
400
|
save_path
|
str
|
Path to save the plot. If None, plot will be shown interactively |
None
|
separate
|
bool
|
Whether to return separate plots for each model |
False
|
Returns:
Type | Description |
---|---|
Chart
|
Altair chart object (combined or separate plots based on separate parameter) |
Source code in dnallm/inference/plot.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 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 |
|
prepare_data(metrics, task_type='binary')
¶
Prepare data for plotting various types of visualizations.
This function organizes model metrics data into formats suitable for different plot types: - Bar charts for classification and regression metrics - ROC and PR curves for classification tasks - Scatter plots for regression tasks
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metrics
|
dict
|
Dictionary containing model metrics for different models |
required |
task_type
|
str
|
Type of task ('binary', 'multiclass', 'multilabel', 'token', 'regression') |
'binary'
|
Returns:
Type | Description |
---|---|
tuple
|
Tuple containing: |
tuple
|
|
tuple
|
|
Raises:
Type | Description |
---|---|
ValueError
|
If task type is not supported for plotting |
Source code in dnallm/inference/plot.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
save_metrics(metrics, output_dir)
¶
Save evaluation metrics to JSON file.
This function saves computed evaluation metrics in JSON format to the specified output directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metrics
|
Dict
|
Dictionary containing metrics to save |
required |
output_dir
|
Path
|
Directory path where metrics will be saved |
required |
Source code in dnallm/inference/predictor.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
|
save_predictions(predictions, output_dir)
¶
Save predictions to JSON file.
This function saves model predictions in JSON format to the specified output directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
predictions
|
Dict
|
Dictionary containing predictions to save |
required |
output_dir
|
Path
|
Directory path where predictions will be saved |
required |
Source code in dnallm/inference/predictor.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 |
|