a
    –¥»a  ã                   @   sl   d dl mZmZ d dlmZ d dlmZ d dlmZ d dl	m
Z d dlmZmZ d dlZG dd„ deƒZdS )	é    )Ú	workspaceÚcrf)ÚCNNModelHelper)Úcrf_update_predictions)ÚTestCaseN)ÚgivenÚsettingsc                   @   s:   e Zd Zee dd¡e dd¡d�edd�dd„ ƒƒZd	S )
ÚTestCrfDecodeé   é   é   )Únum_tagsÚ	num_wordsiÐ  )Údeadlinec                 C   sê   t dd�}tj ||¡ tj¡}tjjdd|d |d fd� tj¡}|j dd¡\}}t	 
t|ƒ|¡ t	 
t|ƒ|¡ t |||¡}t|||ƒ}	| |¡}
t	 |j¡ t	 |j¡ t	 t|	ƒ¡}	t	 t|
ƒ¡}
tjj|	|
d	d	d
d� d S )NZexternal)Únameéÿÿÿÿé   r
   )ÚlowÚhighÚsizeÚpredictionsZcrf_transitionsg-Cëâ6?zMismatch in CRF predictions)ZatolZrtolÚerr_msg)r   ÚnpÚrandomZrandnZastypeÚfloat32ÚuniformÚnetZAddExternalInputsr   ZFeedBlobÚstrr   ZCRFWithLossr   Zupdate_predictionsZ
RunNetOnceZparam_init_netZ	FetchBlobZtestingZassert_allclose)Úselfr   r   Úmodelr   ZtransitionsZpredictions_blobZtransitions_blobZ	crf_layerZupdated_predictionsZref_predictions© r    úX/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/caffe2/python/crf_viterbi_test.pyÚtest_crf_viterbi   s2    
ÿþÿÿ
ýzTestCrfDecode.test_crf_viterbiN)Ú__name__Ú
__module__Ú__qualname__r   ÚstZintegersr   r"   r    r    r    r!   r	      s   r	   )Zcaffe2.pythonr   r   Zcaffe2.python.cnnr   Zcaffe2.python.crf_predictr   Zcaffe2.python.test_utilr   Zhypothesis.strategiesZ
strategiesr&   Z
hypothesisr   r   Únumpyr   r	   r    r    r    r!   Ú<module>   s   