
    9i                     B   S SK J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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/r%\RL                  " \!RN                  \RN                  S9 " S S\5      5       r(g)    N)Enum)AnyDictListOptionalUnion)	Pipelines)Model)InputFormat)
OutputKeys)
InputModelPipeline)	PIPELINES)Preprocessor)Config)	ModelFileTasks)
get_loggerTranslationEvaluationPipeline)module_namec            	       :  ^  \ rS rSrS\R
                  S4S\S\\   S\S\	4U 4S jjjr
S	 r\R
                  4S\4S
 jjrS\\	\\	\\	   4   4   4U 4S jjrS\\	\R$                  4   S\\	\R$                  4   4S jrS\R$                  S\\	\4   4S jrSrU =r$ )r      Ngpumodelpreprocessorinput_formatdevicec           	        > [         TU ]  UUUR                  SS5      UR                  S0 5      S9  X0l        U R	                  5         [        U R                  [        5      (       d   S[        R                   35       eU R                  R                  [        R                  " U R                  R                  [        R                  5      U R                  SS9  U R                  R!                  5         g)a  Build a translation evaluation pipeline with a model dir or a model id in the model hub.

Args:
    model: A Model instance.
    preprocessor: The preprocessor for this pipeline.
    input_format: Input format, choosing one from `"InputFormat.SRC_REF"`,
        `"InputFormat.SRC"`, `"InputFormat.REF"`. Aside from hypothesis, the
        source/reference/source+reference can be presented during evaluation.
    device: Used device for this pipeline.
compileFcompile_options)r   r   r   r    z,please check whether model config exists in )r   plm_onlyN)super__init__popr   checking_input_format
isinstancer   r
   r   CONFIGURATIONload_checkpointospjoin	model_dirTORCH_MODEL_BIN_FILEr   eval)selfr   r   r   r   kwargs	__class__s         x/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/pipelines/nlp/translation_evaluation_pipeline.pyr#   &TranslationEvaluationPipeline.__init__   s      	%JJy%0"JJ'8"=	 	 	? )""$$**e,, 	U:9;R;R:ST	U, 	

""HHTZZ))9+I+IJ;; 	# 	 	

    c                 P   U R                   [        R                  :X  a  [        R	                  S5        g U R                   [        R
                  :X  a  [        R	                  S5        g U R                   [        R                  :X  a  [        R	                  S5        g [        S5      e)NzEvaluation mode: source-onlyzEvaluation mode: reference-onlyz*Evaluation mode: source-reference-combinedziEvaluation mode should be one choice among'InputFormat.SRC', 'InputFormat.REF', and'InputFormat.SRC_REF'.)r   r   SRCloggerinfoREFSRC_REF
ValueError)r.   s    r1   r%   3TranslationEvaluationPipeline.checking_input_formatA   ss    /KK67+//1KK9:+"5"55KKDE 8 9 9r3   c                     [         R                  S5        Xl        U R                  5         U R                  R                  U5        g )NzChanging the evaluation mode.)r6   r7   r   r%   r   change_input_format)r.   r   s     r1   r=   1TranslationEvaluationPipeline.change_input_formatM   s8    34(""$--l;r3   
input_dictc                 (   > [         TU ]  " SSU0UD6$ )u(  Implementation of __call__ function.

Args:
    input: The formatted dict containing the inputted sentences.
    An example of the formatted dict:
        ```
        input = {
            'hyp': [
                'This is a sentence.',
                'This is another sentence.',
            ],
            'src': [
                '这是个句子。',
                '这是另一个句子。',
            ],
            'ref': [
                'It is a sentence.',
                'It is another sentence.',
            ]
        }
        ```
input )r"   __call__)r.   r?   r/   r0   s      r1   rC   &TranslationEvaluationPipeline.__call__U   s    . w;j;F;;r3   returnc                 &    U R                   " S0 UD6$ )NrB   )r   )r.   r?   s     r1   forward%TranslationEvaluationPipeline.forwardn   s     zz'J''r3   outputc                     U$ )NrB   )r.   rI   s     r1   postprocess)TranslationEvaluationPipeline.postprocesss   s    r3   )r   )__name__
__module____qualname____firstlineno__r   r9   r   r   r   strr#   r%   r=   r   r   r   rC   torchTensorrG   r   rK   __static_attributes____classcell__)r0   s   @r1   r   r      s     9=-8-@-@$	!"!'5!  +! 	! !F
9 9D8K8K*5<4U3S	>-B(B#C <2("3#(<<$0 1(59#u||:K5L(
%,, 4S>  r3   ))os.pathpathr)   enumr   typingr   r   r   r   r   numpynprR   modelscope.metainfor	   modelscope.models.baser
   )modelscope.models.nlp.unite.configurationr   modelscope.outputsr   modelscope.pipelines.baser   r   modelscope.pipelines.builderr   modelscope.preprocessorsr   modelscope.utils.configr   modelscope.utils.constantr   r   modelscope.utils.loggerr   r6   __all__register_moduletranslation_evaluationr   rB   r3   r1   <module>ri      s      3 3   ) ( A ) : 2 1 * 6 .	*
+ 	  i.N.NPXH XPXr3   