medcat.components.addons.relation_extraction.rel_cat
Classes:
-
BalancedBatchSampler– -
RelCAT–The RelCAT class used for training 'Relation-Annotation' models, i.e.,
-
RelCATAddon–
Attributes:
-
logger–
BalancedBatchSampler
BalancedBatchSampler(dataset, classes, batch_size, max_samples, max_minority)
Bases: Sampler
Attributes:
-
batch_size– -
classes– -
dataset– -
indices– -
max_minority– -
max_samples_per_class– -
num_classes–
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
126 127 128 129 130 131 132 133 134 135 136 | |
batch_size
instance-attribute
batch_size = batch_size
classes
instance-attribute
classes = classes
dataset
instance-attribute
dataset = dataset
max_minority
instance-attribute
max_minority = max_minority
max_samples_per_class
instance-attribute
max_samples_per_class = max_samples
RelCAT
RelCAT(base_tokenizer: BaseTokenizer, cdb: CDB, config: ConfigRelCAT = ConfigRelCAT(), task: str = 'train', init_model: bool = False)
The RelCAT class used for training 'Relation-Annotation' models, i.e., annotation of relations between clinical concepts.
Parameters:
-
(cdbCDB) –cdb, this is used when creating relation datasets.
-
(tokenizerTokenizerWrapperBERT) –The Huggingface tokenizer instance. This can be a pre-trained tokenzier instance from a BERT-style model. For now, only BERT models are supported.
-
(configConfigRelCAT, default:ConfigRelCAT()) –the configuration for RelCAT. Param descriptions available in ConfigRelCAT class docs.
-
(taskstr, default:'train') –What task is this model supposed to handle. Defaults to "train"
-
(init_modelbool, default:False) –loads default model. Defaults to False.
Methods:
-
evaluate_– -
evaluate_results– -
load– -
pipe– -
predict_text_with_anns–Creates spacy doc from text and annotation input.
-
save– -
train–
Attributes:
-
addon_type– -
base_tokenizer– -
cdb– -
checkpoint_path(str) – -
component– -
device– -
is_cuda_available– -
output_key– -
task(str) –
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
addon_type
class-attribute
instance-attribute
addon_type = 'rel_cat'
base_tokenizer
instance-attribute
base_tokenizer = base_tokenizer
device
instance-attribute
device = device('cuda' if is_cuda_available and device != 'cpu' else 'cpu')
is_cuda_available
instance-attribute
is_cuda_available = is_available()
output_key
class-attribute
instance-attribute
output_key = 'rel_'
evaluate_
evaluate_(output_logits, labels, ignore_idx)
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
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 | |
evaluate_results
evaluate_results(data_loader, pad_id)
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
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 | |
load
classmethod
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
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 | |
pipe
pipe(stream: Iterable[MutableDocument], *args, **kwargs) -> Iterator[MutableDocument]
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
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 | |
predict_text_with_anns
predict_text_with_anns(text: str, annotations: list[dict]) -> MutableDocument
Creates spacy doc from text and annotation input. Predicts using self.call
Parameters:
-
(textstr) –text
-
(annotationsdict) –dict containing the entities from NER (of your choosing), the format must be the following format: [ { "cui": "202099003", -this is optional "value": "discoid lateral meniscus", "start": 294, "end": 318 }, { "cui": "202099003", "value": "Discoid lateral meniscus", "start": 1905, "end": 1929, } ]
Returns:
-
Doc(MutableDocument) –spacy doc with the relations.
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
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 | |
save
save(save_path: str = './') -> None
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
219 220 | |
train
train(export_data_path: str = '', train_csv_path: str = '', test_csv_path: str = '', checkpoint_path: str = './')
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
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 | |
RelCATAddon
RelCATAddon(config: ConfigRelCAT, rel_cat: RelCAT)
Bases: AddonComponent
Methods:
-
create_new–Factory method to create a new MetaCATAddon instance.
-
create_new_component– -
deserialise_from– -
get_init_attrs– -
get_strategy– -
ignore_attrs– -
include_properties– -
load_existing–Factory method to load an existing RelCAT addon from disk.
-
serialise_to–
Attributes:
-
addon_type– -
config(ConfigRelCAT) – -
name(str) – -
output_key–
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
46 47 48 49 | |
addon_type
class-attribute
instance-attribute
addon_type = 'rel_cat'
output_key
class-attribute
instance-attribute
output_key = 'relations'
create_new
classmethod
create_new(config: ConfigRelCAT, base_tokenizer: BaseTokenizer, cdb: CDB) -> RelCATAddon
Factory method to create a new MetaCATAddon instance.
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
51 52 53 54 55 56 | |
create_new_component
classmethod
create_new_component(cnf: ComponentConfig, tokenizer: BaseTokenizer, cdb: CDB, vocab: Vocab, model_load_path: Optional[str]) -> RelCATAddon
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
58 59 60 61 62 63 64 65 66 67 68 69 70 | |
deserialise_from
classmethod
deserialise_from(folder_path: str, **init_kwargs) -> RelCATAddon
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
94 95 96 97 98 99 100 101 102 103 | |
get_init_attrs
classmethod
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
108 109 110 | |
get_strategy
get_strategy() -> SerialisingStrategy
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
105 106 | |
ignore_attrs
classmethod
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
112 113 114 | |
include_properties
classmethod
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
116 117 118 | |
load_existing
classmethod
load_existing(cnf: ConfigRelCAT, base_tokenizer: BaseTokenizer, cdb: CDB, load_path: str) -> RelCATAddon
Factory method to load an existing RelCAT addon from disk.
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
72 73 74 75 76 77 78 79 80 81 82 | |
serialise_to
serialise_to(folder_path: str) -> None
Source code in medcat-v2/medcat/components/addons/relation_extraction/rel_cat.py
84 85 86 | |