Spaces:
Build error
Build error
danseith
commited on
Commit
·
2bf7c7e
1
Parent(s):
b5b3297
Added uniform output sampling.
Browse files
app.py
CHANGED
@@ -6,6 +6,18 @@ unmasker = pipeline("fill-mask", model="anferico/bert-for-patents")
|
|
6 |
|
7 |
example = 'A crustless sandwich made from two slices of baked bread'
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
def unmask(text):
|
10 |
text = add_mask(text)
|
11 |
res = unmasker(text)
|
|
|
6 |
|
7 |
example = 'A crustless sandwich made from two slices of baked bread'
|
8 |
|
9 |
+
|
10 |
+
class TempScalePipe(pipeline):
|
11 |
+
def _forward(self, model_inputs):
|
12 |
+
outputs = self.model(**model_inputs)
|
13 |
+
return outputs
|
14 |
+
|
15 |
+
def postprocess(self, model_outputs, temp=1e3):
|
16 |
+
out = model_outputs["logits"] / temp
|
17 |
+
idx = np.random.randint(-3, 0)
|
18 |
+
best_class = out.softmax(idx)
|
19 |
+
return best_class
|
20 |
+
|
21 |
def unmask(text):
|
22 |
text = add_mask(text)
|
23 |
res = unmasker(text)
|