Views
No views yet
pip install torch transformers safetensors1from transformers import AutoModelForTokenClassification, AutoConfig, BertTokenizerFast
2from safetensors.torch import load_file
3
4# Load the config
5config = AutoConfig.from_pretrained("folder_to_model")
6
7# Initialize the model with the config
8model = AutoModelForTokenClassification.from_config(config)
9
10# Load the safetensors weights
11state_dict = load_file("folder_to_tensors")
12
13# Load the state dict into the model
14model.load_state_dict(state_dict)
15
16# Load the tokenizer
17tokenizer = BertTokenizerFast.from_pretrained("google-bert/bert-base-multilingual-cased")
18
19# Load the label mapper if needed
20with open("pii_model/label_mapper.json", 'r') as f:
21 label_mapper_data = json.load(f)
22
23label_mapper = LabelMapper()
24label_mapper.label_to_id = label_mapper_data['label_to_id']
25label_mapper.id_to_label = {int(k): v for k, v in label_mapper_data['id_to_label'].items()}
26label_mapper.num_labels = label_mapper_data['num_labels']
27
28# Process outputs for analysis...