Here is my full code of creating the labels for training, I did manually check my generated labels and these were correct.
def tokenize_and_align_labels(examples, tokenizer):
    tokenized_inputs = tokenizer(examples["token"], truncation=True, is_split_into_words=True)
    label_to_id = dict(map(reversed, enumerate(label_list)))
    labels = []
           
    for i, label in tqdm(enumerate(examples["labels"]),total=len(examples["labels"])):
        steps=[]
        batch=0
        for index,value in enumerate(examples['token'][i]):
            len_to_compare=len(tokenizer.tokenize(value))
            if len_to_compare>1:
                steps+=(list(range(index+batch+1,index+batch+len_to_compare)))
                batch+=(len_to_compare-1)
        word_ids = list(range(-1,len(label)+len(steps)+1))
        word_ids[0]=None
        word_ids[-1]=None
        #https://huggingface.co/transformers/custom_datasets.html#token-classification-with-w-nut-emerging-entities
        for idx in steps:
            word_ids[idx+1]=None
        ##set_sub_tokesn as None
        previous_word_idx = None
        label_ids = []
        index_to_look_up_label=0
        for word_idx in word_ids:
            # Special tokens have a word id that is None. We set the label to -100 so they are automatically
            # ignored in the loss function.
            if word_idx is None:
                label_ids.append(-100)
            else:
                label_ids.append(label_to_id[label[index_to_look_up_label]])
                index_to_look_up_label+=1
                                
        labels.append(label_ids)
    tokenized_inputs["labels"] = labels
    return tokenized_inputs


Input sentence: “… thị_trấn an_phú huyện an phútỉnh an_giang”
Value after tokenizer:
{‘attention_mask’: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
‘input_ids’: [0,135,64051,2677,64049,64008,64020,30519,64998,2677,64046,2],
‘labels’: [-100, 2, 0, 1, -100, 1, 1, 1, -100, 1, -100, -100],
‘token_type_ids’: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}
Because tokenize of “an_phú” is [‘an_@@’, ‘phú’]; of “tân_bình” is [‘phú@@’, ‘tỉnh’]; of “an_giang” is [‘an_@@’, ‘giang’’]


label_list = [“B-LOC”,“I-LOC”,“O”]