
    i                     .   d dl Z d dlmZ d dlmZmZmZmZmZm	Z	m
Z
mZmZ d dlZd dlZd dlmZ ddlmZ ddlmZ erddlmZ d	d
de	e   de	e   dedee	e   e	e   e	e   f   fdZ	 	 	 ddedede
eeef      fdZ	 	 	 dde
e   dede
eeef      fdZy)    N)Path)	IOTYPE_CHECKINGAnyCallableDictListOptionalTupleUnion)Printer   )util)Errors)Language   )	max_widthcolswidthsr   returnc                    g }g }t        | |      D ]a  \  }}t        |      |kD  r|d |dz
   dz   }|j                  |j                                |j                  t	        t        |      |             c |||D cg c]  }d c}fS c c}w )N   z...r)ziplenappenduppermax)r   r   r   
final_colsfinal_widthscolwidth_s           g/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/spacy/training/loggers.pysetup_tabler%      s     JL$' 2
Us8io	A&.C#))+&CC%01	2
 |<%@ac%@@@%@s   ;	Bprogress_barconsole_outputoutput_filec                 *    t        | du rdnd||      S )a  The ConsoleLogger.v2 prints out training logs in the console and/or saves them to a jsonl file.
    progress_bar (bool): Whether the logger should print a progress bar tracking the steps till the next evaluation pass.
    console_output (bool): Whether the logger should print the logs on the console.
    output_file (Optional[Union[str, Path]]): The file to save the training logs to.
    FNevalr&   r'   r(   )console_logger_v3r+   s      r$   console_loggerr-      s#     )U2T%     c                     drct        j                        j                         rdj                  d   j                         sj                  d   j	                  d       t
        j                  t
        j                  fdddt        dt        d	t        t        t        t        t        t        f      gd
f   t        g d
f   f   f fd}|S )ax  The ConsoleLogger.v3 prints out training logs in the console and/or saves them to a jsonl file.
    progress_bar (Optional[str]): Type of progress bar to show in the console. Allowed values:
        train - Tracks the number of steps from the beginning of training until the full training run is complete (training.max_steps is reached).
        eval - Tracks the number of steps between the previous and next evaluation (training.eval_frequency is reached).
    console_output (bool): Whether the logger should print the logs on the console.
    output_file (Optional[Union[str, Path]]): The file to save the training logs to.
    FTr   )parentsnlpr   stdoutstderrr   Nc                 V   fdt        d      d r j                  d d             d n*r( j                  d              t        dd	      | j                  D cg c]  \  }}t        |d
      r|j                  r|! c}}| j                  d   d   | j                  d   d   | j                  d   d   }|j                         D cg c]
  \  }}|	| c}}D cg c]  }d| 	 }	}rdt        ddg|	z   z   dgz   ddg|	D 
cg c]  }
d c}
z   D 
cg c]  }
d c}
z   dgz         \  } j                  |              j                  D cg c]  }d|z  	 c}             d d}.|vr*t        t        j                  j                  |            dt        t         t"        t$        f      dd ffd}d!fd }||fS c c}}w c c}}w c c}w c c}
w c c}
w c c}w )"Nc                      t        | d      S )NT)fileflush)print)textr2   s    r$   <lambda>z:console_logger_v3.<locals>.setup_printer.<locals>.<lambda>G   s    U4fDA r.   T)no_printz Saving logs is disabled because z already exists.zSaving results to wzutf-8)encodingis_trainabletraining	max_stepseval_frequencyscore_weightszLoss r   E#Scorer         )r   r   )r   spacing-)rH   )trainr*   )
unexpectedexpectedinfor   c           	         | j                  d       y g }i }D ]E  }|j                  dj                  t        | d   |                      t        | d   |         ||<   G g }i }D ][  }| d   j	                  |d      }	 t        |      }|dk7  r|dz  }|j                  dj                  |             ||t        |      <   ] | d	   | d
   g|z   |z   dj                  t        | d               gz   }	rA| d	   | d
   ||t        | d         d}
j                  t        j                  |
      dz          j                          rn j                  |	             rPdk(  r}d| d	    }| d
   }n}d| d	   dz    }d}t!        j                   |d d|      j#                  |       y y y # t
        $ r7 t        j                  j                  |t        |            }t        |      d w xY w)N   z{0:.2f}lossesother_scoresg        )name
score_typespeedd   epochstepscore)rV   rW   rP   scoresrX   
)r   alignsrH   rJ   zLast Eval Epoch: zEpoch r   F)totaldisableleaver6   initial)updater   formatfloatget	TypeErrorr   E916type
ValueErrorstrwritesrsly
json_dumpscloserowtqdmset_description)rM   rP   
log_losses	pipe_namerY   
log_scoresr!   rX   errdatalog_datar\   descr_   r'   rA   logged_pipesr@   msgoutput_streamprogressr&   
score_colsrH   r3   table_alignstable_widthsri   s                 r$   log_stepz:console_logger_v3.<locals>.setup_printer.<locals>.log_stept   sv    |'OOA&FJ) I	i..uT(^I5N/OPQ(-d8nY.G(H
9%I FJ! 
-^,00c:4!%LE '>SLEi..u56',
3s8$
- gV- ##E$w-$89:;   "'] L(("4=1 ##E$4$4X$>$EF# GG\,PW  
  #w. )!24=/B"&v, .!'W(9':;"##yy# $## ' H ,,T2#   9 ! 4 ++,,#$u+,NC$S/t34s   F??A G?c                  ,     r j                          y y )N)rl   )ry   s   r$   finalizez:console_logger_v3.<locals>.setup_printer.<locals>.finalize   s    ##% r.   )r   N)r   warnrM   openpipelinehasattrr>   configitemsr%   rm   rg   r   E1048ra   r
   r   rh   r   )r1   r2   r3   rR   procrB   r!   valuepipe	loss_colsr#   table_headerr"   expected_progress_typesr~   r   rA   rw   r@   rx   ry   rz   r{   rH   r|   r}   ri   
_log_existr'   r(   r&   s    ``             @@@@@@@@@@@r$   setup_printerz(console_logger_v3.<locals>.setup_printerD   s]    Bt$ 6{mCST
 K#((/}=>? cGDM
 "ll
dt^,1B1B 

 JJz*;7	J/0@A

:.?,9,?,?,AWjc5UEVcW
0<=uTF^=	=G7B3Z)+j8G9D1vI 6q 66Z9P!9PPTUSVV84L, #'',|W'MN#''LA53;A7'ST"3#<S(S##+6M $  H	38DcN3 H	3 H	3 H	3 H	3T	& !!U
 X= !79P Bs*   ;$H,
H7HH.	H?	H!H&)r   ensure_pathexistsr0   mkdirsysr2   r3   r   r   r   r
   r   rh   r   )r&   r'   r(   r   r   s   ``` @r$   r,   r,   0   s     J&&{3J""1%,,."(((6 '*jjszz~"~"!#~":<~"	x$sCx.12D898BH;MM	N~" ~"@ r.   )FTN)NTN)r   pathlibr   typingr   r   r   r   r   r	   r
   r   r   rj   rn   wasabir    r   errorsr   languager   rh   intr%   boolr-   r,    r.   r$   <module>r      s    
  W W W     # =?
A#Y
A $S	
A69
A
49d3ic*+
A  .2 %T	*+$ #'.2T3-TT %T	*+Tr.   