(tvars)
return tvars_result_list
get trainable variables only to train from layer 9 to last layer
    :param tvars: a list
    :return: a new tvars, which is list
get trainable variables only to train from layer 9 to last layer
    :param tvars: a list
    :return: a new tvars, which is list
get trainable variables only to train from layer 9 to last layer : param tvars : a list : return : a new tvars which is list
def find_train_variables(tvars):
    """
    get trainable variables only to train from layer 9 to last layer
    :param tvars: a list
    :return: a new tvars, which is list
    """
    # bert/encoder/layer_21, bert/encoder/layer_9, bert/encoder/layer_20/attention/output/dense/bias:0, bert/encoder/layer_20/attention/output/dense/kernel:
    tvars_result_list=[]

    for var in tvars:
        if 'cls/predictions' in var.name or 'bert/pooler/dense' in  var.name: # 最后几层
            tvars_result_list.append(var)
        else: # 后半个网络的参数
            layer_number_list=re.findall("layer_(.+?)/", var.name)
            if len(layer_number_list)>0 and isinstance(layer_number_list[0],int): # 匹配到了一个数字
                layer_number=int(layer_number_list[0])
                if layer_number>=9:
                    tvars_result_list.append(var)

    # print train variables
    for i,var_ in enumerate(tvars_result_list):
        print("####find_train_variables.i:",i, "variable name:",var_.name)

    print("####find_train_variables:length of tvars_result_list:",tvars_result_list)
    return tvars_result_list
def find_train_variables ( tvars ) : # bert/encoder/layer_21, bert/encoder/layer_9, bert/encoder/layer_20/attention/output/dense/bias:0, bert/encoder/layer_20/attention/output/dense/kernel: tvars_result_list = [ ] for var in tvars : if 'cls/predictions' in var . name or 'bert/pooler/dense' in var . name : # 最后几层 tvars_result_list . append ( var ) else : # 后半个网络的参数 layer_number_list = re . findall ( "layer_(.+?)/" , var . name ) if len ( layer_number_list ) > 0 and isinstance ( layer_number_list [ 0 ] , int ) : # 匹配到了一个数字 layer_number = int ( layer_number_list [ 0 ] ) if layer_number >= 9 : tvars_result_list . append ( var ) # print train variables for i , var_ in enumerate ( tvars_result_list ) : print ( "####find_train_variables.i:" , i , "variable name:" , var_ . name ) print ( "####find_train_variables:length of tvars_result_list:" , tvars_result_list ) return tvars_result_list