
    9i&                         S SK r S SKJr  S SKJrJrJrJrJr  S SK	r	S SK
rS SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJrJr  S S
KJr  \" 5       rSS/r   SS jrSS jrg)    N)Mapping)AnyDictListTupleUnion)AutoTokenizer)Models)
OutputKeys)Preprocessor)ModeKeys)get_model_typeparse_label_mapping)
get_loggerparse_text_and_labellabels_to_idc                 (   Su  pVn[        U [        5      (       a  U nO[        U [        5      (       d  [        U [        5      (       aB  [	        U 5      S:X  a  U u  pVnO[	        U 5      S:X  a  U[
        R                  :X  a  U u  pVOU u  pWO[        U [        5      (       al  U R                  U5      nU R                  U5      nUb  [        U[        5      (       a  U R                  U5      nO U Vs/ s H  oR                  U5      PM     nnXVU4$ s  snf )a   Parse the input and return the sentences and labels.

When input type is tuple or list and its size is 2:
If the pair param is False, data will be parsed as the first_sentence and the label,
else it will be parsed as the first_sentence and the second_sentence.

Args:
    data: The input data.
    mode: The mode of the preprocessor
    first_sequence: The key of the first sequence
    second_sequence: The key of the second sequence
    label: The key of the label
Returns:
    The sentences and labels tuple.
NNN      )	
isinstancestrtuplelistlenr   	INFERENCEr   get)	datamodefirst_sequencesecond_sequencelabeltext_atext_blabelslbs	            b/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/preprocessors/nlp/utils.pyr   r      s    ( .FF$	D%	 	 JtT$:$:t9>%)"FFY!^x)))!%!%	D'	"	".)/*=Juc22XXe_F-23UrhhrlUF36!! 4s   /Dc                    S n [        U [        [        45      (       ac  [        U  Vs/ s H
  oC" U5      PM     sn5      (       a=  Ub:  U  Vs/ s H  nXB;   a  X$   OU[	        U5         PM     snU[
        R                  '   gU" U 5      (       a-  Ub*  X;   a  UU    OU[	        U 5         U[
        R                  '   gU b  X[
        R                  '   ggs  snf s  snf ! [         a#  n[        R                  SU  SU S35        UeSnAff = f)a  Turn the labels to id with the type int or float.

If the original label's type is str or int, the label2id mapping will try to convert it to the final label.
If the original label's type is float, or the label2id mapping does not exist,
the original label will be returned.

Args:
    label2id: An extra label2id mapping. If not provided, the label will not be translated to ids.
    labels: The input labels.
    output: The label id.

Returns:
    The final labels.
c                 P    [        U [        5      =(       d    [        U [        5      $ N)r   r   int)r"   s    r'   label_can_be_mapped)labels_to_id.<locals>.label_can_be_mappedP   s    %%?E3)??    NzLabel z& cannot be found in the label mapping zt,which comes from the user input or the configuration files. Please consider matching your labels with this mapping.)
r   r   r   allr   r   LABELSKeyErrorloggererror)r%   outputlabel2idr,   r"   es         r'   r   r   @   s,    @fudm,,^d5e^dUZ6I%6P^d5e1f1f( $)#E $)#4(3u::NN#)F:$$% !((X-A!- )1)3;CK3H :$$%(.:$$%   6f)  VHB8* MF G	H s?   $C CC !C.C 9C =C 
C 
D(DDr   r*   )oscollections.abcr   typingr   r   r   r   r   jsonnumpynptransformersr	   modelscope.metainfor
   modelscope.outputsr   modelscope.preprocessors.baser   modelscope.utils.constantr   modelscope.utils.hubr   r   modelscope.utils.loggerr   r2   __all__r   r    r.   r'   <module>rF      sU    
 # 0 0   & & ) 6 . D .	!>
2
 )-)-#	&"R$r.   