UMCU commited on
Commit
2198535
·
verified ·
1 Parent(s): 316ee77

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +29 -0
README.md CHANGED
@@ -71,6 +71,35 @@ with torch.no_grad():
71
 
72
  ```
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
 
76
  The macro f1 score is 0.73. We suggest to use it primarily for feature extraction or for use as an *explainable* embedder.
 
71
 
72
  ```
73
 
74
+ An approach could be
75
+
76
+ ```python
77
+
78
+ def get_feature_vector(text):
79
+ inputs = tokenizer(
80
+ text,
81
+ return_tensors="pt",
82
+ truncation=True,
83
+ )
84
+
85
+ with torch.no_grad():
86
+ features = model(**inputs).logits
87
+
88
+ return features.flatten()
89
+
90
+ def reform(features, how='softmax'):
91
+ if how == 'softmax':
92
+ return torch.nn.functional.softmax(features)
93
+ elif how = 'gumbel':
94
+ return torch.nn.functional.gumbel_softmax(features)
95
+ elif how = 'normalize':
96
+ return torch.nn.functional.normalize(features.reshape(1,-1))
97
+
98
+ feature_vector = reform(get_feature_vector(text))
99
+
100
+
101
+ ```
102
+
103
 
104
 
105
  The macro f1 score is 0.73. We suggest to use it primarily for feature extraction or for use as an *explainable* embedder.