pelinker.analysis¶
compute_adjusted_rand_index(y_true, y_pred)
¶
Compute clustering quality via adjusted Rand index (ARI).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ndarray
|
True labels (e.g., property names) |
required |
y_pred
|
ndarray
|
Predicted cluster labels |
required |
Returns:
| Type | Description |
|---|---|
float
|
ARI score. |
Source code in pelinker/analysis.py
compute_clustering_fit_metrics(clusterer, manifold_df, *, min_cluster_size, cluster_labels)
¶
DBCV, ARI vs entity, and cluster counts for a fitted HDBSCAN model.
Source code in pelinker/analysis.py
compute_kb_generality_scores(embeddings, labels, k_neighbors=10, metric='cosine', word_frequencies=None, density_weight=0.5)
¶
Compute generality scores for entities based on KB statistics.
Combines embedding-space density with label simplicity to identify generic vs specific terms. Generic terms tend to have: - Many similar neighbors (high density) - High average similarity to neighbors - Shorter, simpler labels (fewer words, common words) - Central position in semantic space
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings
|
ndarray
|
Array of shape (n_points, n_features) containing embeddings |
required |
labels
|
list[str]
|
List of labels corresponding to embeddings |
required |
k_neighbors
|
int
|
Number of nearest neighbors to consider |
10
|
metric
|
str
|
Distance metric ('cosine' or 'euclidean') |
'cosine'
|
word_frequencies
|
Mapping[str, float] | None
|
Optional word frequency mapping for simplicity scoring |
None
|
density_weight
|
float
|
Weight for embedding density vs label simplicity (0.0 = pure simplicity, 1.0 = pure density) |
0.5
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of generality scores (higher = more generic), shape (n_points,) |
Source code in pelinker/analysis.py
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 918 919 920 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 | |
drop_entities_with_few_mentions(frame, min_mentions_per_entity, *, negative_label=None)
¶
Drop entities with fewer than min_mentions_per_entity rows (same rule as
:func:~pelinker.selection.load_selection_frame / mention-level selection eval).
When negative_label is set, that label is never dropped for low mention count
(so thin negative tails remain for screener training).
Source code in pelinker/analysis.py
embeddings_dict_to_dataframe(embeddings_dict)
¶
Convert embeddings dictionary to DataFrame format expected by transform artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings_dict
|
dict[str, tuple[str, Tensor | ndarray]]
|
Dictionary mapping id -> (label, embedding) |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns: id, label, embed |
Source code in pelinker/analysis.py
evaluate_all_screeners_cv(X_embed, X_manifold, y, entity, orig_idx, screener_cfg, oov_cfg)
¶
Shared-stratified-fold CV for LDA/SVM negative screener, manifold OOV model, and stacked score.
screener_best scores use the ROC winner (LDA vs SVM) on pooled OOS predictions.
When oov_cfg.enabled is False or X_manifold is None, OOV branch is skipped:
combined metrics match screener_best and oov_winner_kind is "disabled".
Source code in pelinker/analysis.py
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 | |
fit_ambient_screener_with_metrics(dfr, config)
¶
Fit the persisted screener on dfr and report in-sample PR/F1 for detecting
negative_label when both classes are present.
Source code in pelinker/analysis.py
get_word_frequencies_from_library(language='en', wordlist='best')
¶
Get word frequency lookup object from wordfreq library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
language
|
str
|
Language code (default: "en" for English) |
'en'
|
wordlist
|
str
|
Wordlist size - "best", "large", or "small" (default: "best") |
'best'
|
Returns:
| Type | Description |
|---|---|
object | None
|
WordFrequencyLookup object with .get() method, or None if library not available |
Source code in pelinker/analysis.py
pooled_grid_solve_from_metrics_dfs(metrics_dfs, optimization_config=None)
¶
After all bootstrap samples have run a min_cluster_size grid, aggregate their metrics
once and return full smoothed-grid diagnostics (including y_objective curve).
Source code in pelinker/analysis.py
pooled_min_cluster_size_from_metrics_dfs(metrics_dfs, optimization_config=None)
¶
After all bootstrap samples have run a min_cluster_size grid, aggregate their metrics
once and return the smoothed (chosen_min_cluster_size, raw objective mean at that grid point).
The objective is set by ClusteringOptimizationConfig.grid_objective (default: pooled
min–max normalized DBCV and ARI).
Source code in pelinker/analysis.py
split_by_negative_label(dfr, negative_label)
¶
Split a mention frame into a boolean mask of synthetic-negative rows and the manifold frame (KB / non-negative rows only).