hyacinthum commited on
Commit
054eca3
1 Parent(s): 48a5c49

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +20 -12
README.md CHANGED
@@ -47,24 +47,32 @@ pip install torch transformers safetensors
47
  Load and run the model using PyTorch and transformers:
48
 
49
  ```python
50
- import torch
51
- from transformers import AutoTokenizer, AutoModel
52
  from safetensors.torch import load_file
53
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  # Load the tokenizer
55
  tokenizer = BertTokenizerFast.from_pretrained("google-bert/bert-base-multilingual-cased")
56
 
57
- # Load the model
58
- model = AutoModel.from_pretrained('model-path/miniagent.pt', device_map='auto')
59
- # Alternatively, for the precision-focused model
60
- # model = AutoModel.from_pretrained('model-path/miniagent_precision', device_map='auto')
61
-
62
- # Example input
63
- text = "Your sensitive information string"
64
 
65
- # Tokenize and run the model
66
- inputs = tokenizer(text, return_tensors="pt")
67
- outputs = model(**inputs)
 
68
 
69
  # Process outputs for analysis...
70
  ```
 
47
  Load and run the model using PyTorch and transformers:
48
 
49
  ```python
50
+ from transformers import AutoModelForTokenClassification, AutoConfig, BertTokenizerFast
 
51
  from safetensors.torch import load_file
52
 
53
+ # Load the config
54
+ config = AutoConfig.from_pretrained("folder_to_model")
55
+
56
+ # Initialize the model with the config
57
+ model = AutoModelForTokenClassification.from_config(config)
58
+
59
+ # Load the safetensors weights
60
+ state_dict = load_file("folder_to_tensors")
61
+
62
+ # Load the state dict into the model
63
+ model.load_state_dict(state_dict)
64
+
65
  # Load the tokenizer
66
  tokenizer = BertTokenizerFast.from_pretrained("google-bert/bert-base-multilingual-cased")
67
 
68
+ # Load the label mapper if needed
69
+ with open("pii_model/label_mapper.json", 'r') as f:
70
+ label_mapper_data = json.load(f)
 
 
 
 
71
 
72
+ label_mapper = LabelMapper()
73
+ label_mapper.label_to_id = label_mapper_data['label_to_id']
74
+ label_mapper.id_to_label = {int(k): v for k, v in label_mapper_data['id_to_label'].items()}
75
+ label_mapper.num_labels = label_mapper_data['num_labels']
76
 
77
  # Process outputs for analysis...
78
  ```