erikhenriksson commited on
Commit
b37a02d
·
verified ·
1 Parent(s): 2911649

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. example.py +15 -0
  2. modeling_sm_subgroup_classifier.py +8 -1
example.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from transformers import AutoModel
3
+
4
+ # Load sm_subgroup_classifier
5
+ sm_classifier = AutoModel.from_pretrained(
6
+ "erikhenriksson/sm-subgroup-classifier", trust_remote_code=True
7
+ )
8
+
9
+ # create a random 1024 dimensional embedding
10
+
11
+ embedding = np.random.rand(1024).astype(np.float32)
12
+
13
+ # Use - model automatically discovers what's available
14
+ result = sm_classifier("en", "OP-ob", embedding)
15
+ print(f"Prediction: {result['predictions']['predicted_class']}")
modeling_sm_subgroup_classifier.py CHANGED
@@ -120,6 +120,13 @@ class SmSubgroupClassifier(PreTrainedModel):
120
 
121
  @classmethod
122
  def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
123
- model = super().from_pretrained(pretrained_model_name_or_path, **kwargs)
 
 
 
 
 
 
124
  model.model_dir = pretrained_model_name_or_path
 
125
  return model
 
120
 
121
  @classmethod
122
  def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
123
+ # Load config
124
+ config = SmSubgroupClassifierConfig.from_pretrained(
125
+ pretrained_model_name_or_path, **kwargs
126
+ )
127
+
128
+ # Create model instance (skip the pytorch weight loading)
129
+ model = cls(config)
130
  model.model_dir = pretrained_model_name_or_path
131
+
132
  return model