CoolFace
Apppublic

obversarystudios/failure-geometry-demo

sourceHugging Facemitupdated 5mo agoView on Hugging Face
0likes
embed.cpython-312.pyc37 linesDownload Raw Back to __pycache__
1�

2�`�i���j�dZddlmZddlZddlmZddlmZddl	m3Z4dZdd�Zef					dd	�Z
d
d5�Zy)a�6TF-IDF + Truncated SVD embedding for failure records.7 8No network downloads; no GPU required. Runs entirely with scikit-learn.9 10Feature construction combines:11- TF-IDF on a failure-context string (input text, expected label, prediction, reasoning type)12- TruncatedSVD to produce a dense, low-dimensional representation13 14Adapted from failure-induced-benchmarks/src/failure_geometry/embedding.py15(engineered sparse features) but extended to dense SVD projections for16KMeans and scatter visualisation.17�)�annotationsN)�TruncatedSVD)�TfidfVectorizer)�	normalize� c�B�d|d�d|d�d|d�d|d�d	|d18��19S)Nzinput: �xz expected: �yz
 prediction: �20predictionz type: �reasoning_typez model: �model_id�)�failures �d/mnt/ai_lab_os/AI_LAB/infra/09_practice/github_ready/huggingface/failure-geometry-demo/core/embed.py�
_failure_textrsV��21�'�#�,�� ��S�\�N�#��|�,�-�.��)�*�+�,��*�%�&�		(��c	��|stjd|f�S|D�cgc]
}t|���}}t|�}t	ddd��}|j|�}t
||jddz22|dz23�}|dkr.|j�}t|dd�dt|d��f�St|d�	�}	|	j|�}24t|25�Scc}w)26Nri )��T)�max_features�ngram_range�sublinear_tfrr�*)�n_components�random_state)�np�emptyr�lenr�
fit_transform�min�shape�toarrayr�maxr)�failuresr�f�texts�n�27vectorizer�tfidf�effective_dims�arr�svd�denses           r�embed_failuresr.$s�����x�x��L�)�*�*�'/�0�!�]�1�
�0�E�0��E�28�A� �����J�29
�$�$�U�+�E���u�{�{�1�~��'9�1�q�5�A�N�����m�m�o����Q� 8�#�n�a�"8� 8�8�9�:�:�30�N��31D�C����e�$�E��U����#
1s�Cc�x�t|�dkr tjt|�df�St|d��S)z8Return exactly 2 components for PCA-style scatter plots.�r)r)rr�zerosr.)r$s r�embed_for_scatterr2?s3��32�8�}�q���x�x��X���*�+�+��(��3�3r)r�dict�return�str)r$�33list[dict]r�intr4�34np.ndarray)r$r6r4r8)�__doc__�35__future__r�numpyr�sklearn.decompositionr�sklearn.feature_extraction.textr�sklearn.preprocessingr�36EMBED_DIMSrr.r2rrr�<module>r@sP���#��.�;�+��37��#��������64r