o
    ci#                     @   sb   d Z ddlZddlmZmZ ddlZddlmZm	Z	m
Z
 dedeegef fddZdd
dZdS )z!Utilities to load and cache data.    N)CallableDict)EvalPredictionglue_compute_metricsglue_output_modes	task_namereturnc                    s    t   dtf fdd}|S )zCFunction from transformers/examples/text-classification/run_glue.pypc                    s@    dkrt j| jdd}n
 dkrt | j}t|| j}|S )Nclassification   )axis
regression)npargmaxpredictionssqueezer   	label_ids)r	   predsmetricsoutput_moder    \/home/ubuntu/.local/lib/python3.10/site-packages/ray/tune/examples/pbt_transformers/utils.pycompute_metrics_fn   s   z4build_compute_metrics_fn.<locals>.compute_metrics_fn)r   r   )r   r   r   r   r   build_compute_metrics_fn
   s   r   ./datac                 C   s   t d dd l}dd l}| dkrd}ntd| tj|d| }tj|sU|j	
|| ||}|| W d    n1 sFw   Y  t d| | d S t d| | d S )	NzDownloading dataset.r   rtez0https://dl.fbaipublicfiles.com/glue/data/RTE.zipzUnknown task: {}z{}.zipz!Downloaded data for task {} to {}z>Data already exists. Using downloaded data for task {} from {})printurllibzipfile
ValueErrorformatospathjoinexistsrequesturlretrieveZipFile
extractall)r   data_dirr   r   url	data_filezip_refr   r   r   download_data   s$   r.   )r   )__doc__r"   typingr   r   numpyr   transformersr   r   r   strr   r.   r   r   r   r   <module>   s    