ó
    †ñ:i¸_  ã                   ó¨   • S SK r S SKrS SKrS SKrS SKrSSKJ	r	J
r
JrJr  SSKJr  SSKJrJrJr  SSKJrJr  SSKJr  SSKJr   " S	 S
\5      rS rg)é    Né   )Ú
explainersÚlinksÚmaskersÚmodels)ÚExplanation)ÚDeserializerÚSerializableÚ
Serializer)Úsafe_isinstanceÚshow_progress)ÚInvalidAlgorithmError)Úis_transformers_lmc                   ó¤   ^ • \ rS rSrSrS\R                  SSSSS4S jrSSSSSSS.S	 jrS
 r	\
S 5       rSU 4S jjr\SU 4S jj5       rSrU =r$ )Ú	Explaineré   a(  Uses Shapley values to explain any machine learning model or python function.

This is the primary explainer interface for the SHAP library. It takes any combination
of a model and masker and returns a callable subclass object that implements
the particular estimation algorithm that was chosen.
NÚautoTc	           	      ó²  • Xl         XPl        X`l        [        U[        R
                  5      (       d\  [        U[        R                  5      (       d$  [        R                  R                  U5      (       aY  [        UR                  5      S:X  a@  US:X  a  [        R                  " U5      U l        GOX[        R                   " U5      U l        GO;[#        USS/5      (       aR  [%        U R                   5      (       a  [        R&                  " USSS9U l        Oò[        R&                  " U5      U l        OÖU[(        L d	  U[*        L a%  US   [,        La  [        R.                  " U6 U l        OŸU[0        L a"  S	U;   a  [        R                   " U5      U l        OtUck  [        U R                   [2        R4                  5      (       aB  U R6                  " U R                   U R                   R8                  R:                  4UUUUUS.U	D6$ X l        [#        U R                   S5      (       aÁ  [%        U R                   R                   5      (       a[  U R6                  " U R                   R                   U R                  c  U R                   R:                  OU R                  4UUUUUS.U	D6$ U R6                  " [2        R4                  " U R                   5      U R                  4UUUUUS.U	D6$ [%        U R                   5      (       au  [2        R<                  " U R                   U R                  R:                  5      U l         [        R>                  " U R                  U R                   R@                  5      U l        OÎ[#        U R                   S5      (       aX  [#        U R                  SS/5      (       a;  [        R>                  " U R                  U R                   R@                  5      U l        O[[#        U R                   S5      (       a@  [#        U R                  S5      (       a%  [        RB                  " U R                  5      U l        [E        U5      (       a  X0l#        O[I        S5      eXpl%        U RL                  [N        L GaÚ  US:X  GaË  [P        RR                  RU                  XR                  5      (       a  SnGO™[P        RV                  RU                  XR                  5      (       a  SnGOg[P        RX                  RU                  XR                  5      (       a  SnGO5[E        U R                   5      (       Ga  [[        []        U R                  5      [        R                   5      (       a#  U R                  R                  S   S::  a  SnOÈSnOÅ[[        []        U R                  5      [        R                  5      (       a#  U R                  R                  S   S::  a  SnOsSnOp[_        U R                  SS5      (       d  [_        U R                  SS5      (       a  [a        U R                  S5      (       a  SnOSnO[I        S[-        U5      -   5      eUS:X  ae  [P        Rb                  U l&        [P        Rb                  R6                  " U U R                   U R                  4U RF                  U R                  US .U	D6  g
US:X  af  [P        Rd                  U l&        [P        Rd                  R6                  " U U R                   U R                  4U RF                  U R                  UUS!.U	D6  g
US:X  ap  [P        Rf                  U l&        [P        Rf                  R6                  " U U R                   U R                  4U RF                  U R                  UU R                  S".U	D6  g
US:X  ae  [P        RV                  U l&        [P        RV                  R6                  " U U R                   U R                  4U RF                  U R                  US .U	D6  g
US:X  ae  [P        RX                  U l&        [P        RX                  R6                  " U U R                   U R                  4U RF                  U R                  US .U	D6  g
US:X  ae  [P        RR                  U l&        [P        RR                  R6                  " U U R                   U R                  4U RF                  U R                  US .U	D6  g
US#:X  ae  [P        Rh                  U l&        [P        Rh                  R6                  " U U R                   U R                  4U RF                  U R                  US .U	D6  g
[k        S$U S%35      eg
)&a¼  Build a new explainer for the passed model.

Parameters
----------
model : object or function
    User supplied function or model object that takes a dataset of samples and
    computes the output of the model for those samples.

masker : function, numpy.array, pandas.DataFrame, tokenizer, None, or a list of these for each model input
    The function used to "mask" out hidden features of the form `masked_args = masker(*model_args, mask=mask)`.
    It takes input in the same form as the model, but for just a single sample with a binary
    mask, then returns an iterable of masked samples. These
    masked samples will then be evaluated using the model function and the outputs averaged.
    As a shortcut for the standard masking using by SHAP you can pass a background data matrix
    instead of a function and that matrix will be used for masking. Domain specific masking
    functions are available in shap such as shap.ImageMasker for images and shap.TokenMasker
    for text. In addition to determining how to replace hidden features, the masker can also
    constrain the rules of the cooperative game used to explain the model. For example
    shap.TabularMasker(data, hclustering="correlation") will enforce a hierarchical clustering
    of coalitions for the game (in this special case the attributions are known as the Owen values).

link : function
    The link function used to map between the output units of the model and the SHAP value units. By
    default it is shap.links.identity, but shap.links.logit can be useful so that expectations are
    computed in probability units while explanations remain in the (more naturally additive) log-odds
    units. For more details on how link functions work see any overview of link functions for generalized
    linear models.

algorithm : "auto", "permutation", "partition", "tree", or "linear"
    The algorithm used to estimate the Shapley values. There are many different algorithms that
    can be used to estimate the Shapley values (and the related value for constrained games), each
    of these algorithms have various tradeoffs and are preferable in different situations. By
    default the "auto" options attempts to make the best choice given the passed model and masker,
    but this choice can always be overridden by passing the name of a specific algorithm. The type of
    algorithm used will determine what type of subclass object is returned by this constructor, and
    you can also build those subclasses directly if you prefer or need more fine grained control over
    their options.

output_names : None or list of strings
    The names of the model outputs. For example if the model is an image classifier, then output_names would
    be the names of all the output classes. This parameter is optional. When output_names is None then
    the Explanation objects produced by this explainer will not have any output_names, which could effect
    downstream plots.

seed: None or int
    seed for reproducibility

r   Ú	partitionz transformers.PreTrainedTokenizerz<transformers.tokenization_utils_base.PreTrainedTokenizerBasez...T)Ú
mask_tokenÚcollapse_mask_tokenr   ÚmeanN)ÚlinkÚ	algorithmÚoutput_namesÚfeature_namesÚlinearize_linkztransformers.pipelines.Pipelinezshap.models.TeacherForcingzshap.maskers.Textzshap.maskers.Imagezshap.models.TopKLMz.The passed link function needs to be callable!r   ÚlinearÚtreeÚadditiveé   é
   ÚexactÚpermutationé    Ú	text_dataFÚ
image_dataÚ
clusteringz_The passed model is not callable and cannot be analyzed directly with the given masker! Model: )r   r   r   )r   r   r   Úseed)r   r   r   r   ÚdeepzUnknown algorithm type passed: Ú!)6Úmodelr   r   Ú
isinstanceÚpdÚ	DataFrameÚnpÚndarrayÚscipyÚsparseÚissparseÚlenÚshaper   Ú	PartitionÚmaskerÚIndependentr   r   ÚTextÚlistÚtupleÚstrÚ	CompositeÚdictr   ÚTransformersPipelineÚ__init__Úinner_modelÚ	tokenizerÚTeacherForcingÚOutputCompositeÚtext_generateÚFixedCompositeÚcallabler   Ú	TypeErrorr   Ú	__class__r   r   ÚLinearExplainerÚsupports_model_with_maskerÚTreeExplainerÚAdditiveExplainerÚ
issubclassÚtypeÚgetattrÚhasattrÚExactExplainerÚPermutationExplainerÚPartitionExplainerÚDeepExplainerr   )
Úselfr,   r8   r   r   r   r   r   r)   Úkwargss
             Ú]/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/shap/explainers/_explainer.pyrA   ÚExplainer.__init__   s£  € ðx Œ
Ø(ÔØ*Ôô �fœbŸl™l×+Ñ+Ü˜¤§
¡
×+Ñ+¬u¯|©|×/DÑ/DÀV×/LÑ/LÔRUÐV\×VbÑVbÓRcÐghÓRhà˜KÓ'Ü%×/Ò/°Ó7�–ä%×1Ò1°&Ó9�–ÜØÐ7Ð9wÐx÷
ñ 
ô " $§*¡*×-Ñ-ä%Ÿlšl¨6¸eÐY]Ñ^�•ä%Ÿlšl¨6Ó2�•ØœŠn ¬%¢°V¸A±YÄcÒ5IÜ!×+Ò+¨VÐ4ˆD�KØœŠn 6¨VÓ#3Ü!×-Ò-¨fÓ5ˆD�KØ‰^¤
¨4¯:©:´v×7RÑ7R× SÑ SØ—=’=Ø—
‘
Ø—
‘
×&Ñ&×0Ñ0ð	ð Ø#Ø)Ø+Ø-ñ	ð ñ	ð 	ð !ŒKô ˜4Ÿ:™:Ð'H×IÑIÜ! $§*¡*×"2Ñ"2×3Ñ3Ø—}’}Ø—J‘J×$Ñ$Ø,0¯K©KÑ,?�D—J‘J×(Ò(ÀTÇ[Á[ð	ð Ø'Ø!-Ø"/Ø#1ñ	ð ñ	ð 	ð —}’}Ü×/Ò/°·
±
Ó;Ø—K‘Kð	ð Ø'Ø!-Ø"/Ø#1ñ	ð ñ	ð 	ô ˜dŸj™j×)Ñ)Ü×.Ò.¨t¯z©z¸4¿;¹;×;PÑ;PÓQˆDŒJÜ!×1Ò1°$·+±+¸t¿z¹z×?WÑ?WÓXˆD�KÜ˜TŸZ™ZÐ)E×FÑFÌ?Ø�K‰KÐ-Ð/CÐD÷L
ñ L
ô "×1Ò1°$·+±+¸t¿z¹z×?WÑ?WÓXˆD�KÜ˜TŸZ™ZÐ)=×>Ñ>Ä?ÐSW×S^ÑS^Ð`s×CtÑCtÜ!×0Ò0°·±Ó=ˆDŒKô
 �D�>‰>Ø�IäÐLÓMÐMØ,Ôð �>‰>œYÓ&ð ˜FÔ"ä×-Ñ-×HÑHÈ×P[ÑP[×\Ñ\Ø (’IÜ×-Ñ-×HÑHØŸ;™;÷ñ ð !'’IÜ×1Ñ1×LÑLÈU×T_ÑT_×`Ñ`Ø *’Iô ˜dŸj™j×)Ò)Ü!¤$ t§{¡{Ó"3´W×5HÑ5H×IÑIØŸ;™;×,Ñ,¨QÑ/°2Ó5Ø(/™Ià(5™IÜ#¤D¨¯©Ó$5´w×7HÑ7H×IÑIØŸ;™;×,Ñ,¨QÑ/°2Ó5Ø(/™Ià(5™Iä §¡¨[¸%×@Ñ@ÄGÈDÏKÉKÐYeÐgl×DmÑDmÜ! $§+¡+¨|×<Ñ<Ø$/™	à$1™	ô $ØyÜ˜e›*ñ%óð ð ˜GÓ#Ü!+×!:Ñ!:�”Ü×)Ñ)×2Ò2ØØ—J‘JØ—K‘Kðð Ÿ™Ø"&×"4Ñ"4Ø#1ñð óð ˜mÓ+Ü!+×!@Ñ!@�”Ü×/Ñ/×8Ò8ØØ—J‘JØ—K‘Kð	ð Ÿ™Ø"&×"4Ñ"4Ø#1Øñ	ð ó	ð ˜kÓ)Ü!+×!>Ñ!>�”Ü×-Ñ-×6Ò6ØØ—J‘JØ—K‘Kð	ð Ÿ™Ø"&×"4Ñ"4Ø#1Ø!%×!2Ñ!2ñ	ð ó	ð ˜fÓ$Ü!+×!9Ñ!9�”Ü×(Ñ(×1Ò1ØØ—J‘JØ—K‘Kðð Ÿ™Ø"&×"4Ñ"4Ø#1ñð óð ˜jÓ(Ü!+×!=Ñ!=�”Ü×,Ñ,×5Ò5ØØ—J‘JØ—K‘Kðð Ÿ™Ø"&×"4Ñ"4Ø#1ñð óð ˜hÓ&Ü!+×!;Ñ!;�”Ü×*Ñ*×3Ò3ØØ—J‘JØ—K‘Kðð Ÿ™Ø"&×"4Ñ"4Ø#1ñð óð ˜fÓ$Ü!+×!9Ñ!9�”Ü×(Ñ(×1Ò1ØØ—J‘JØ—K‘Kðð Ÿ™Ø"&×"4Ñ"4Ø#1ñð óô ,Ð.MÈiÈ[ÐXYÐ,ZÓ[Ð[ðs 'ó    F©Ú	max_evalsÚmain_effectsÚerror_boundsÚ
batch_sizeÚoutputsÚsilentc                óv  ^&• [         R                   " 5       n	[        [        U R                  5      [        R
                  5      (       a:  [        U5      S:X  a+  [        R                  " US   S9U R                  l	        USS nSn
[        U5      nU R                  c%  [        [        U5      5       Vs/ s H  nSPM     nnOs[        [        U R                  S   5      [        [        45      (       a!  [        R                  " U R                  5      nO![        R                  " U R                  5      /n[        [        U5      5       Hµ  nU
c   [        X}   5      n
[#        X}   [$        R&                  5      (       a-  [        X}   R(                  5      XÍ'   X}   R+                  5       X}'   [-        X}   S5      (       a  X}   S   X}'   M€  [        [        X}   5      [.        5      (       d  M¢  SX}   ;   d  M¬  X}   S   X}'   M·     US:X  a4  [1        U R                  S	5      (       a  U R                  R2                  nOS
n/ n/ m&/ n/ n/ n/ n/ n/ n/ n[5        [7        U R                  SS5      5      (       a$  [        [        U5      5       Vs/ s H  n/ PM     nn[9        [;        U6 X R<                  R>                  S-   U5       GHÂ  nU R@                  " UUUUUUUS.UD6nURC                  URE                  SS5      5        T&RC                  URE                  SS5      5        URC                  URE                  SS5      5        URC                  US   5        URC                  URE                  SS5      5        URC                  URE                  SS5      5        URC                  URE                  SS5      5        URE                  SS5      nURC                  [5        U5      (       a  U" U6 OU5        URC                  URE                  SS5      5        [5        [7        U R                  SS5      5      (       d  GMx  U R                  R                  " U6 n[        [        U5      5       H  nXÍ   RC                  UU   5        M     GMÅ     U Vs/ s H  n/ PM     nn[        [        U5      5       H]  nSn[        [        U5      5       H@  n[F        RH                  " UU   U   5      nUU   RC                  Xí   UUU-    5        UU-  nMB     M_     [K        U5      n[K        U5      n[K        T&5      m&[K        U5      n[K        U5      n[K        U5      n[K        U5      nSnT&b  [M        U&4S jT& 5       5      (       + nU RN                  cb  SU;  aY  U(       d  [F        RP                  " U5      nOš[S        T&5       VV s/ s H"  u  nn [F        RP                  " UU   5      U    PM$     nnn O_SnO\T&c   S5       e[F        RP                  " U RN                  5      n!T& V s/ s H  n U!U    PM
     nn U(       d  [F        RP                  " U5      n[#        U[F        RT                  5      (       aC  [        URV                  5      S:X  a*  [F        RL                  " USSS24   U:H  5      (       a  US   n[1        U R                  S5      (       ad  / n"[;        U6  HE  nU"RC                  U R                  RX                  " U6  V#s/ s H  n#[K        U#5      PM     sn#5        MG     [        [;        U"6 5      n/ n$[S        U5       GH7  u  nn%/ n[S        UU   5       H“  u  nn#[F        RH                  " UU   U   5      [F        RH                  " U#RV                  5      :w  a+  URC                  U#RZ                  " / UU   U   QSP76 5        Mo  URC                  U#RZ                  " UU   U   6 5        M•     [K        U5      UU'   UU   c8  [        U%RV                  S   5       Vs/ s H  nS[]        U5      -   PM     snUU'   U$RC                  [_        UU   UU%UU   UUUUU[         R                   " 5       U	-
  S9
5        GM:     [        U$5      S:X  a  U$S   $ U$$ s  snf ! [          a     GN;f = fs  snf s  snf s  sn nf s  sn f s  sn#f s  snf )a9  Explains the output of model(*args), where args is a list of parallel iterable datasets.

Note this default version could be an abstract method that is implemented by each algorithm-specific
subclass of Explainer. Descriptions of each subclasses' __call__ arguments
are available in their respective doc-strings.
r   r!   )Útarget_sentencesNr   znlp.arrow_dataset.DatasetÚtextr   Údefault_batch_sizer"   r   z
 explainerr\   ÚvaluesÚoutput_indicesÚexpected_valuesÚmask_shapesr^   r(   Úhierarchical_valuesr   Ú	error_stdFc              3   óX   >#   • U  H  n[        U5      [        TS    5      :H  v •  M!     g7f)r   N)r5   )Ú.0Úxrh   s     €rY   Ú	<genexpr>Ú%Explainer.__call__.<locals>.<genexpr>š  s$   øé € Ð$^Ê~È!¤S¨£V¬s°>À!Ñ3DÓ/EÖ%EÊ~ùs   ƒ'*zYYou have passed a list for output_names but the model seems to not have multiple outputs!Údata_transforméÿÿÿÿzFeature )r   r^   r(   rk   r   rl   Úcompute_time)0ÚtimerO   rP   r8   r   rE   r5   r   ÚTextGenerationr,   r;   r   Úranger<   ÚcopyÚdeepcopyÚ	Exceptionr-   r.   r/   ÚcolumnsÚto_numpyr   r?   rR   rf   rH   rQ   r   ÚziprJ   Ú__name__Úexplain_rowÚappendÚgetr0   ÚprodÚpack_valuesÚallr   ÚarrayÚ	enumerater1   r6   rr   Úreshaper=   r   )'rW   r]   r^   r_   r`   ra   rb   ÚargsrX   Ú
start_timeÚnum_rowsÚ_r   Úirg   ri   rj   rk   r(   r   rl   Úrow_argsÚ
row_resultÚtmpÚrow_feature_namesÚaÚ
arg_valuesÚposÚjÚmask_lengthÚragged_outputsÚsliced_labelsÚ
index_listÚlabelsÚnew_argsÚvÚoutÚdatarh   s'                                         @rY   Ú__call__ÚExplainer.__call__$  s®  ø€ ô( —Y’Y“[ˆ
ä”d˜4Ÿ;™;Ó'¬×)@Ñ)@×AÑAÄcÈ$ÃiÐSTÃnÜ &× 5Ò 5ÀtÈAÁwÑ OˆD�K‰KÔØ˜˜�8ˆDàˆÜ�D‹zˆØ×ÑÑ%Ü+0´°T³Ô+;Ó<Ò+; a›TÑ+;ˆMÐ<ˆMÜœ˜T×/Ñ/°Ñ2Ó3´d¼E°]×CÑCÜ ŸMšM¨$×*<Ñ*<Ó=‰Mä!Ÿ]š]¨4×+=Ñ+=Ó>Ð?ˆMÜ”s˜4“yÖ!ˆAàÑðÜ" 4¡7›|�Hô
 ˜$™'¤2§<¡<×0Ñ0Ü#'¨©¯©Ó#8�Ñ Ø™'×*Ñ*Ó,�‘ô ˜t™wÐ(C×DÑDØ™' &™/�“ÜœD ¡›M¬4×0Ó0°V¸t¹wÕ5FØ™' &™/�“ñ# "ð& ˜ÓÜ�t—{‘{Ð$8×9Ñ9Ø!Ÿ[™[×;Ñ;‘
à�
ð ˆØˆØˆØˆØˆØ ÐØˆ
ØˆØˆ	Ü”G˜DŸK™K¨¸$Ó?×@Ñ@Ü).¬s°4«yÔ)9Ó:Ò)9 A›RÑ)9ˆMÐ:Ü%¤c¨4 j°(¿N¹N×<SÑ<SÐVbÑ<bÐdj×kˆHØ×)Ò)ØØ#Ø)Ø)Ø%ØØñ	ð ñ	ˆJð �M‰M˜*Ÿ.™.¨°4Ó8Ô9Ø×!Ñ! *§.¡.Ð1AÀ4Ó"HÔIØ×"Ñ" :§>¡>Ð2CÀTÓ#JÔKØ×Ñ˜z¨-Ñ8Ô9Ø×Ñ 
§¡¨~¸tÓ DÔEØ×Ñ˜jŸn™n¨\¸4Ó@ÔAØ×&Ñ& z§~¡~Ð6KÈTÓ'RÔSØ—.‘. °Ó6ˆCØ×Ñ´(¸3·-±-¡ X¡ÀSÔIØ×Ñ˜ZŸ^™^¨K¸Ó>Ô?Üœ §¡¨_¸dÓC×DÔDØ$(§K¡K×$=Ò$=¸xÐ$HÐ!Üœs 8›}Ö-�AØ!Ñ$×+Ñ+Ð,=¸aÑ,@ÖAô .ñ/ lñ6 #'Ó'¢$˜Q“b¡$ˆ
Ð'Ü”s˜6“{Ö#ˆAØˆCÜœ3˜t›9Ö%�Ü Ÿgšg k°!¡n°QÑ&7Ó8�Ø˜1‘×$Ñ$ V¡Y¨s°S¸;Ñ5FÐ%GÔHØ�{Ñ"’ó &ñ $ô & oÓ6ˆÜ" <Ó0ˆÜ$ ^Ó4ˆÜ" <Ó0ˆÜ)Ð*=Ó>ÐÜ 	Ó*ˆ	Ü  Ó,ˆ
ð ˆØÑ%Ü!$Ô$^É~Ó$^Ó!^Ô^ˆNØ×ÑÑ$Ø˜<Ó'Þ%Ü$&§H¢H¨\Ó$:‘Mô T]Ð]kÔSlô%ÚSlÁ-À!ÀZœŸš ¨a¡Ó1°*Ô=ÑSlð "ñ %�Mð !%‘à!Ñ-ð ØkóÐ-ô —X’X˜d×/Ñ/Ó0ˆFÙBPÓQÂ.°J˜V JÔ/Á.ˆMÐQÞ!Ü "§¢¨Ó 7�ä�m¤R§Z¡Z×0Ñ0´S¸×9LÑ9LÓ5MÐQRÓ5RÜ�vŠv�m A¢q DÑ)¨]Ñ:×;Ñ;Ø -¨aÑ 0�ô �4—;‘;Ð 0×1Ñ1ØˆHÜ ›J�Ø—‘¸¿¹×9SÒ9SÐU]Ñ9^Ó _Ò9^°A¤¨Q¦Ñ9^Ñ _Ö`ñ 'äœ˜X˜Ó'ˆDð ˆÜ  —‰GˆAˆtàˆCÜ! *¨Q¡-Ö0‘��1Ü—7’7˜; q™>¨!Ñ,Ó-´·²¸¿¹Ó1AÓAØ—J‘J˜qŸyšyÐ@¨+°a©.¸Ñ*;Ð@¸RÒ@ÖAà—J‘J˜qŸyšy¨+°a©.¸Ñ*;Ð<Ö=ñ	 1ô
 (¨Ó,ˆJ�q‰Mà˜QÑÑ'ÜAFÀtÇzÁzÐRSÁ}ÔAUÓ#VÒAU¸A J´°Q³Ô$7ÑAUÑ#V�˜aÑ ð �J‰JÜØ˜q‘MØ#ØØ"/°Ñ"2Ø!-Ø)Ø(;Ø!.Ø'Ü!%§¢£¨zÑ!9ñ÷ñ 'ô< ˜S› Q›ˆs�1‰vÐ/¨CÐ/ùòs =øô !ó Úðüò> ;ùò8 (ùó4%ùò Rùò !`ùò  $Ws<   Â3bÅbÊ	bÒb!Ö:)b&Øb,Û6b1
àb6â
bâbc                ó   • 0 $ )a©  Explains a single row and returns the tuple (row_values, row_expected_values, row_mask_shapes, main_effects).

This is an abstract method meant to be implemented by each subclass.

Returns
-------
tuple
    A tuple of (row_values, row_expected_values, row_mask_shapes), where row_values is an array of the
    attribution values for each sample, row_expected_values is an array (or single value) representing
    the expected value of the model for each sample (which is the same for all samples unless there
    are fixed inputs present, like labels when explaining the loss), and row_mask_shapes is a list
    of all the input shapes (since the row_values is always flattened),

© )rW   r]   r^   r_   ra   rb   r�   rX   s           rY   r   ÚExplainer.explain_rowÜ  s	   € ð ˆ	r[   c                 ó   • g)z†Determines if this explainer can handle the given model.

This is an abstract static method meant to be implemented by each subclass.
Fr¡   )r,   r8   s     rY   rL   Ú$Explainer.supports_model_with_maskerí  s   € ð r[   c                 ó–  >• [         TU ]  U5        [        USSS9 nUR                  SU R                  U5        [	        U S5      (       a  UR                  SU R
                  U5        [	        U S5      (       a  UR                  SU R                  5        UR                  SU R                  5        SSS5        g! , (       d  f       g= f)	z-Write the explainer to the given file stream.úshap.Explainerr   )Úversionr,   r8   r�   r   N)ÚsuperÚsaver   r,   rR   r8   r�   r   )rW   Úout_fileÚmodel_saverÚmasker_saverÚsrJ   s        €rY   r©   ÚExplainer.saveõ  s�   ø€ ä‰‰�XÔÜ˜Ð"2¸AÒ>À!Ø�F‰F�7˜DŸJ™J¨Ô4Ü�t˜X×&Ñ&Ø—‘�x §¡¨lÔ;Ü�t˜V×$Ñ$Ø—‘�v˜tŸy™yÔ)Ø�F‰F�6˜4Ÿ9™9Ô%÷ ?×>Ö>ús   œBB:Â:
Cc                 óf  >• U(       a  U R                  XUS9$ [        TU ]	  USS9n[        USSSS9 nUR                  SU5      US'   U R                  S:X  a  UR                  S	5      US	'   OUR                  S
U5      US
'   UR                  S5      US'   SSS5        U$ ! , (       d  f       U$ = f)zvLoad an Explainer from the given file stream.

Parameters
----------
in_file : The file stream to load objects from.

)Úmodel_loaderÚmasker_loaderF)Úinstantiater¦   r   )Úmin_versionÚmax_versionr,   ÚKernelExplainerr�   r8   r   N)Ú_instantiated_loadr¨   Úloadr	   r~   )ÚclsÚin_filer°   r±   r²   rX   r­   rJ   s          €rY   r·   ÚExplainer.load   sº   ø€ ö Ø×)Ñ)¨'Ð\iÐ)ÐjÐjä‘‘˜g°5�Ð9ˆÜ˜'Ð#3ÀÐPQÒRÐVWØŸf™f W¨lÓ;ˆF�7‰OØ�|‰|Ð0Ó0Ø!"§¡¨£��v’à#$§6¡6¨(°MÓ#B��xÑ ØŸV™V F›^ˆF�6‰N÷ Sð ˆ÷ SÔRð ˆús   ³A$B!Â!
B0)rJ   r   r   r   r8   r,   r   )ú.saver»   )NNT)r~   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚidentityrA   rž   r   ÚstaticmethodrL   r©   Úclassmethodr·   Ú__static_attributes__Ú__classcell__)rJ   s   @rY   r   r      sx   ø† ñð Ø�^‰^ØØØØØôJ\ð^ ØØØØØõv0òpð" ñó ð÷	&ð öó ör[   r   c           
      óŠ  • [        U S5      (       d  U $ U b  U S   c  g[        R                  " [        U S   5      [        R                  5      (       d=  [        [        R                  " U  Vs/ s H  n[        U5      PM     sn5      5      S:X  a  [        R                  " U 5      $ [        R                  " U [        S9$ s  snf )zHUsed the clean up arrays before putting them into an Explanation object.Ú__len__Nr   r!   )Údtype)	rR   r0   Ú
issubdtyperP   Únumberr5   Úuniquer…   Úobject)rg   r›   s     rY   rƒ   rƒ     sš   € ä�6˜9×%Ñ%Øˆð �~˜ ™Ñ*Øô 
�Š”t˜F 1™I“¬¯	©	×	2Ñ	2´c¼"¿)º)ÑU[ÓD\ÒU[ÐPQÄSÈÆVÑU[ÑD\Ó:]Ó6^ÐbcÓ6cÜ�xŠx˜ÓÐä�xŠx˜¤fÑ-Ð-ùò E]s   Á-C )rx   ru   Únumpyr0   Úpandasr.   Úscipy.sparser2   Ú r   r   r   r   Ú_explanationr   Ú_serializabler	   r
   r   Úutilsr   r   Úutils._exceptionsr   Úutils.transformersr   r   rƒ   r¡   r[   rY   Ú<module>rÕ      s@   ðÛ Û ã Û Û ç 1Ó 1Ý &ß BÑ Bß 2Ý 5Ý 3ôD�ô DóN.r[   