o
    Si                     @   sB   d Z ddlZddlZddlZddlmZ ddlmZ dddZdS )zJ
The function lex_net(args) define the lexical analysis network structure
    N)NormalInitializerTc              	      sN   ddddd}dd fddd fd	d
	}|| S )a#  
    define the lexical analysis network structure
    word: stores the input of the model
    for_infer: a boolean value, indicating if the model to be created is for training or predicting.

    return:
        for infer: return the prediction
        otherwise: return the prediction
          g      ?g?Tc              	      s   t jj|  d t jt jj dt jjdddd}t jj| t jt jj dt jjdddd}t jj|  d t jt jj dt jjdddd}t jj| dt jt jj dt jjdddd}t jj	||gd	d
}|S )z4
        define the bidirectional gru layer
           lowhigh-C6?regularization_coeffinitializerregularizer)inputsize
param_attrT)r   r   
is_reverser      )r   axis)
fluidlayersfc	ParamAttrr   Uniformr   L2DecayRegularizerdynamic_gruconcat)input_featurepre_grugru	pre_gru_rgru_rbi_merge)grnn_hidden_dim
init_bound H/home/ubuntu/.local/lib/python3.10/site-packages/jieba/lac_small/nets.py_bigru_layer,   sf   	
zlex_net.<locals>._bigru_layerNc           	         s   t j| gd t jdt jj ddd}|}tD ]}|}|}qt jj|t jt jj dt jj	dddd	}|j
d
 }t jj|d |g|jdd t jj|t jddd}|S )z'
        Configure the network
        float32word_embr   )learning_ratenamer   )r   r   dtype	is_sparser   r	   r
   r   )r   r   r   r   r   crfw)shaper,   r+   )r+   )r   r   )r   	embeddingr   r   r   ranger   r   r   r   r/   create_parameterr,   crf_decoding)	wordtargetword_embeddingr   ibigru_outputemissionr   
crf_decode)	IS_SPARSEr'   	bigru_numemb_lrr$   
num_labels
vocab_sizeword_emb_dimr%   r&   	_net_confV   sJ   
	zlex_net.<locals>._net_conf)Nr%   )r4   r?   r>   	for_inferr5   crf_lrrA   r%   )	r;   r'   r<   r=   r#   r$   r>   r?   r@   r&   lex_net   s   *$rD   )TN)	__doc__sysosmathpaddle.fluidr   paddle.fluid.initializerr   rD   r%   r%   r%   r&   <module>   s   