CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
squad.cpython-310.pyc42 linesDownload Raw Back to __pycache__
1o

2.�Yi;$�@s�ddlZddlZddlmZmZddlmZddlmZm	Z	ddl3Z4ddlmZddl
mZddlmZdd	lmZdd5lmZmZddlmZmZmZmZe�e�Zee���Z e!d
d�e D��Z"eGdd�d��Z#Gdd�de�Z$Gdd�de�Z%dS)�N)�	dataclass�field)�Enum)�Optional�Union)�FileLock)�Dataset�)�$MODEL_FOR_QUESTION_ANSWERING_MAPPING)�PreTrainedTokenizer)�check_torch_load_is_safe�logging�)�
SquadFeatures�SquadV1Processor�SquadV2Processor�"squad_convert_examples_to_featuresccs�|]}|jVqdS�N)�6model_type)�.0Zconf�r��E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\transformers/data/datasets/squad.py�	<genexpr>"s�rc@s<eZdZUdZedddd�e�id�Zee	d<edddid�Z7ee	d	<ed8ddid�Zee	d<ed9dd
id�Z
ee	d<edddid�Zee	d<edddid�Zee	d<edddid�Zee	d<edddid�Zee	d<edddid�Zee	d<edddid�Zee	d<eddd id�Zee	d!<ed"dd#id�Zee	d$<dS)%�SquadDataTrainingArgumentszb10    Arguments pertaining to what data we are going to input our model for training and eval.11    N�helpz!Model type selected in the list: z, )�default�metadatarzFThe input data dir. Should contain the .json files for the SQuAD task.�data_dir�z�The maximum total input sequence length after tokenization. Sequences longer than this will be truncated, sequences shorter will be padded.�max_seq_lengthzVWhen splitting up a long document into chunks, how much stride to take between chunks.�12doc_stride�@zkThe maximum number of tokens for the question. Questions longer than this will be truncated to this length.�max_query_length�z�The maximum length of an answer that can be generated. This is needed because the start and end predictions are not conditioned on one another.�max_answer_lengthFz1Overwrite the cached training and evaluation sets�overwrite_cachezDIf true, the SQuAD examples contain some that do not have an answer.�version_2_with_negativegzIIf null_score - best_non_null is greater than the threshold predict null.�null_score_diff_threshold��n_best_sizerzjlanguage id of input for language-specific xlm models (see tokenization_xlm.PRETRAINED_INIT_CONFIGURATION)�lang_id�z3multiple threads for converting example to features�threads)�__name__�13__module__�__qualname__�__doc__r�join�MODEL_TYPESr�str�__annotations__rr�intr r"r$r%�boolr&r'�floatr)r*r,rrrrr%sb14����	���	��	������	rc@seZdZdZdZdS)�Split�train�devN)r-r.r/r9r:rrrrr8hsr8c@s�eZdZUdZeed<eeed<eed<e	ed<dej15dddfded	ed16ee
deeefde	deedefd
d�Zdd�Zdeeejffdd�ZdS)�SquadDatasetzH17    This will be superseded by a framework-agnostic approach soon.18    �args�features�mode�is_language_sensitiveNF�pt�	tokenizer�limit_length�	cache_dir�dataset_formatcCs&||_||_|jrt�nt�|_t|t�r'zt|}Wnt	y&t	d��w||_19|jr/dnd}tj�
|dur:|n|jd|j�d|jj�d|j�d|���}	|	d}20t|21���tj�|	�r�|js�t��}t�tj|	dd�|_|jd	|_|j�d22d�|_|j�dd�|_t� d|	�d
�t��|�|jdus�|jdur�t�!d|	�d��nX|tj"kr�|j�#|j�|_n|j�$|j�|_t%|j||j|j&|j'|tj(k|j)|d�\|_|_t��}t�*|j|j|jd�|	�t� d|	�dt��|d�d��Wd�dSWd�dS1�swYdS)Nzmode is not a valid split nameZv2Zv1Zcached_�_z.lockT)Zweights_onlyr=�dataset�examplesz"Loading features from cached file z [took %.3f s]zDeleting cached file z; will allow dataset and examples to be cached in future run)rGrArr r"Zis_trainingr,Zreturn_dataset)r=rFrGz!Saving features into cached file z [took z.3fz s])+r<r?r&rr�	processor�23isinstancer3r8�KeyErrorr>�os�pathr1r�value�	__class__r-rr�existsr%�timer�torch�loadZold_featuresr=�getrFrG�logger�info�warningr:Zget_dev_examplesZget_train_examplesrr r"r9r,�save)�selfr<rArBr>r?rCrDZversion_tagZcached_features_fileZ	lock_path�startrrr�__init__wsp2425�"�26�27��28�����$zSquadDataset.__init__cCs29t|j�Sr)�lenr=)rXrrr�__len__�s30zSquadDataset.__len__�returncCs4|j|}tj|jtjd�}tj|jtjd�}tj|jtjd�}tj|jtjd�}tj|jtj	d�}tj|j31tj	d�}|||d�}	|jjdvrJ|	d=|jjdvrx|	�
||d��|jjrc|	�
d|i�|jrx|	�
dtj|jtjd�|jji�|jtjkr�tj|jtjd�}32tj|jtjd�}|	�
|33|d	��|	S)34N)Zdtype)�	input_ids�attention_mask�token_type_ids)�xlmZrobertaZ35distilbertZ	camembertr`)Zxlnetra)�	cls_index�p_mask�
is_impossibleZlangs)�start_positions�
end_positions)r=rQZtensorr^�longr_r`rbrcr7rdr<r�updater&r?Zones�shapeZint64r*r>r8r9Zstart_positionZend_position)rX�i�featurer^r_r`rbrcrdZinputsrerfrrr�__getitem__�s036�$zSquadDataset.__getitem__)r-r.r/r0rr4�listrr8r6r9rrr5rr3rZr\�dictrQZTensorrlrrrrr;ms837����38���39�Lr;)&rKrP�dataclassesrr�enumr�typingrrrQ�filelockrZtorch.utils.datarZmodels.auto.modeling_autor40Ztokenization_utilsr�utilsrr
Zprocessors.squadrrrrZ41get_loggerr-rTrm�keysZMODEL_CONFIG_CLASSES�tupler2rr8r;rrrr�<module>s&42B
Aluode/PerceptionLabPortable · CoolFace